mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 09:07:47 +01:00
add maxRewardTime
This commit is contained in:
parent
5ad7c6a3ba
commit
58551ba37f
2 changed files with 46 additions and 13 deletions
|
@ -6,21 +6,28 @@ import {Logger} from "../utils/logger";
|
||||||
import { HashedUserID, UserID } from "../types/user.model";
|
import { HashedUserID, UserID } from "../types/user.model";
|
||||||
import { getReputation } from "../utils/reputation";
|
import { getReputation } from "../utils/reputation";
|
||||||
import { SegmentUUID } from "../types/segments.model";
|
import { SegmentUUID } from "../types/segments.model";
|
||||||
|
import {config} from "../config";
|
||||||
|
const maxRewardTime = config.maxRewardTimePerSegmentInSeconds;
|
||||||
|
|
||||||
async function dbGetSubmittedSegmentSummary(userID: HashedUserID): Promise<{ minutesSaved: number, segmentCount: number }> {
|
async function dbGetSubmittedSegmentSummary(userID: HashedUserID): Promise<{ minutesSaved: number, segmentCount: number }> {
|
||||||
const row = await db.prepare("get", `SELECT SUM((("endTime" - "startTime") / 60) * "views") as "minutesSaved",
|
try {
|
||||||
count(*) as "segmentCount" FROM "sponsorTimes"
|
const row = await db.prepare("get",
|
||||||
WHERE "userID" = ? AND "votes" > -2 AND "shadowHidden" != 1`, [userID]);
|
`SELECT SUM(((CASE WHEN "endTime" - "startTime" > ? THEN ? ELSE "endTime" - "startTime" END) / 60) * "views") as "minutesSaved",
|
||||||
if (row.minutesSaved != null) {
|
count(*) as "segmentCount" FROM "sponsorTimes"
|
||||||
return {
|
WHERE "userID" = ? AND "votes" > -2 AND "shadowHidden" != 1`, [maxRewardTime, maxRewardTime, userID]);
|
||||||
minutesSaved: row.minutesSaved,
|
if (row.minutesSaved != null) {
|
||||||
segmentCount: row.segmentCount,
|
return {
|
||||||
};
|
minutesSaved: row.minutesSaved,
|
||||||
} else {
|
segmentCount: row.segmentCount,
|
||||||
return {
|
};
|
||||||
minutesSaved: 0,
|
} else {
|
||||||
segmentCount: 0,
|
return {
|
||||||
};
|
minutesSaved: 0,
|
||||||
|
segmentCount: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ describe("getUserInfo", () => {
|
||||||
await db.prepare("run", sponsorTimesQuery, ["zzzxxxyyy", 1, 11, 2, "uuid000006", getHash("getuserinfo_user_02"), 6, 10, "sponsor", 0]);
|
await db.prepare("run", sponsorTimesQuery, ["zzzxxxyyy", 1, 11, 2, "uuid000006", getHash("getuserinfo_user_02"), 6, 10, "sponsor", 0]);
|
||||||
await db.prepare("run", sponsorTimesQuery, ["xxxyyyzzz", 1, 11, 2, "uuid000007", getHash("getuserinfo_user_02"), 7, 10, "sponsor", 1]);
|
await db.prepare("run", sponsorTimesQuery, ["xxxyyyzzz", 1, 11, 2, "uuid000007", getHash("getuserinfo_user_02"), 7, 10, "sponsor", 1]);
|
||||||
await db.prepare("run", sponsorTimesQuery, ["xxxyyyzzz", 1, 11, 2, "uuid000008", getHash("getuserinfo_user_02"), 8, 10, "sponsor", 1]);
|
await db.prepare("run", sponsorTimesQuery, ["xxxyyyzzz", 1, 11, 2, "uuid000008", getHash("getuserinfo_user_02"), 8, 10, "sponsor", 1]);
|
||||||
|
await db.prepare("run", sponsorTimesQuery, ["xxxyyyzzz", 0, 36000, 2, "uuid000009", getHash("getuserinfo_user_03"), 8, 2, "sponsor", 0]);
|
||||||
|
|
||||||
const insertWarningQuery = 'INSERT INTO warnings ("userID", "issueTime", "issuerUserID", "enabled", "reason") VALUES (?, ?, ?, ?, ?)';
|
const insertWarningQuery = 'INSERT INTO warnings ("userID", "issueTime", "issuerUserID", "enabled", "reason") VALUES (?, ?, ?, ?, ?)';
|
||||||
await db.prepare("run", insertWarningQuery, [getHash("getuserinfo_warning_0"), 10, "getuserinfo_vip", 1, "warning0-0"]);
|
await db.prepare("run", insertWarningQuery, [getHash("getuserinfo_warning_0"), 10, "getuserinfo_vip", 1, "warning0-0"]);
|
||||||
|
@ -294,4 +295,29 @@ describe("getUserInfo", () => {
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Should only count long segments as 10 minutes", (done: Done) => {
|
||||||
|
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_user_03`)
|
||||||
|
.then(async res => {
|
||||||
|
assert.strictEqual(res.status, 200);
|
||||||
|
const expected = {
|
||||||
|
userName: "807e0a5d0a62c9c4365fae3d403e4618a3226f231314a898fa1555a0e55eab9e",
|
||||||
|
userID: "807e0a5d0a62c9c4365fae3d403e4618a3226f231314a898fa1555a0e55eab9e",
|
||||||
|
minutesSaved: 20,
|
||||||
|
viewCount: 2,
|
||||||
|
ignoredViewCount: 0,
|
||||||
|
segmentCount: 1,
|
||||||
|
ignoredSegmentCount: 0,
|
||||||
|
reputation: 0,
|
||||||
|
lastSegmentID: "uuid000009",
|
||||||
|
vip: false,
|
||||||
|
warnings: 0,
|
||||||
|
warningReason: ""
|
||||||
|
};
|
||||||
|
const data = await res.json();
|
||||||
|
assert.deepStrictEqual(data, expected);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue