mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-13 23:17:02 +03:00
add last lastSegmentID
This commit is contained in:
@@ -5,6 +5,7 @@ import {Request, Response} from 'express';
|
||||
import {Logger} from '../utils/logger';
|
||||
import { HashedUserID, UserID } from '../types/user.model';
|
||||
import { getReputation } from '../utils/reputation';
|
||||
import { SegmentUUID } from "../types/segments.model";
|
||||
|
||||
async function dbGetSubmittedSegmentSummary(userID: HashedUserID): Promise<{ minutesSaved: number, segmentCount: number }> {
|
||||
try {
|
||||
@@ -27,7 +28,7 @@ async function dbGetSubmittedSegmentSummary(userID: HashedUserID): Promise<{ min
|
||||
}
|
||||
}
|
||||
|
||||
async function dbGetIgnoredSegmentCount(userID: HashedUserID): Promise<{ ignoredSegmentCount: number }> {
|
||||
async function dbGetIgnoredSegmentCount(userID: HashedUserID): Promise<number> {
|
||||
try {
|
||||
let row = await db.prepare("get", `SELECT COUNT(*) as "ignoredSegmentCount" FROM "sponsorTimes" WHERE "userID" = ? AND ( "votes" <= -2 OR "shadowHidden" = 1 )`, [userID]);
|
||||
return row?.ignoredSegmentCount ?? 0
|
||||
@@ -78,6 +79,15 @@ async function dbGetWarningsForUser(userID: HashedUserID): Promise<number> {
|
||||
}
|
||||
}
|
||||
|
||||
async function dbGetLastSegmentForUser(userID: HashedUserID): Promise<SegmentUUID> {
|
||||
try {
|
||||
let row = await db.prepare('get', `SELECT "timeSubmitted", "UUID" FROM "sponsorTimes" WHERE "userID" = ? ORDER BY "timeSubmitted" DESC LIMIT 1`, [userID]);
|
||||
return row?.UUID ?? null;
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getUserInfo(req: Request, res: Response) {
|
||||
const userID = req.query.userID as UserID;
|
||||
const hashedUserID: HashedUserID = userID ? getHash(userID) : req.query.publicUserID as HashedUserID;
|
||||
@@ -101,6 +111,7 @@ export async function getUserInfo(req: Request, res: Response) {
|
||||
warnings: await dbGetWarningsForUser(hashedUserID),
|
||||
reputation: await getReputation(hashedUserID),
|
||||
vip: await isUserVIP(hashedUserID),
|
||||
lastSegmentID: await dbGetLastSegmentForUser(hashedUserID),
|
||||
});
|
||||
} else {
|
||||
res.status(400).send();
|
||||
|
||||
Reference in New Issue
Block a user