mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-20 22:48:33 +03:00
use seperate queries
This commit is contained in:
@@ -14,21 +14,6 @@ export class Sqlite implements IDatabase {
|
|||||||
|
|
||||||
// eslint-disable-next-line require-await
|
// eslint-disable-next-line require-await
|
||||||
async prepare(type: QueryType, query: string, params: any[] = []): Promise<any[]> {
|
async prepare(type: QueryType, query: string, params: any[] = []): Promise<any[]> {
|
||||||
if (query.includes(";")) {
|
|
||||||
const promises = [];
|
|
||||||
let paramsCount = 0;
|
|
||||||
for (const q of query.split(";")) {
|
|
||||||
if (q.trim() !== "") {
|
|
||||||
const currentParamCount = q.match(/\?/g)?.length ?? 0;
|
|
||||||
promises.push(this.prepare(type, q, params.slice(paramsCount, paramsCount + currentParamCount)));
|
|
||||||
|
|
||||||
paramsCount += currentParamCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (await Promise.all(promises)).flat();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Logger.debug(`prepare (sqlite): type: ${type}, query: ${query}, params: ${params}`);
|
// Logger.debug(`prepare (sqlite): type: ${type}, query: ${query}, params: ${params}`);
|
||||||
const preparedQuery = this.db.prepare(Sqlite.processQuery(query));
|
const preparedQuery = this.db.prepare(Sqlite.processQuery(query));
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ export async function postBranding(req: Request, res: Response) {
|
|||||||
|
|
||||||
if (!videoID || !userID || userID.length < 30 || !service
|
if (!videoID || !userID || userID.length < 30 || !service
|
||||||
|| ((!title || !title.title)
|
|| ((!title || !title.title)
|
||||||
&& (!thumbnail || thumbnail.original == null
|
&& (!thumbnail || thumbnail.original == null
|
||||||
|| (!thumbnail.original && !(thumbnail as TimeThumbnailSubmission).timestamp)))) {
|
|| (!thumbnail.original && !(thumbnail as TimeThumbnailSubmission).timestamp)))) {
|
||||||
res.status(400).send("Bad Request");
|
res.status(400).send("Bad Request");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -53,9 +53,11 @@ export async function postBranding(req: Request, res: Response) {
|
|||||||
if (existingUUID) {
|
if (existingUUID) {
|
||||||
await updateVoteTotals(BrandingType.Title, existingVote, UUID, isVip);
|
await updateVoteTotals(BrandingType.Title, existingVote, UUID, isVip);
|
||||||
} else {
|
} else {
|
||||||
await db.prepare("run", `INSERT INTO "titles" ("videoID", "title", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?, ?);
|
await db.prepare("run", `INSERT INTO "titles" ("videoID", "title", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||||
INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, 0, ?, 0);`,
|
[videoID, title.title, title.original ? 1 : 0, hashedUserID, service, hashedVideoID, now, UUID]);
|
||||||
[videoID, title.title, title.original ? 1 : 0, hashedUserID, service, hashedVideoID, now, UUID, UUID, isVip ? 1 : 0]);
|
|
||||||
|
await db.prepare("run", `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, 0, ?, 0);`,
|
||||||
|
[UUID, isVip ? 1 : 0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})(), (async () => {
|
})(), (async () => {
|
||||||
@@ -70,13 +72,17 @@ export async function postBranding(req: Request, res: Response) {
|
|||||||
if (existingUUID) {
|
if (existingUUID) {
|
||||||
await updateVoteTotals(BrandingType.Thumbnail, existingVote, UUID, isVip);
|
await updateVoteTotals(BrandingType.Thumbnail, existingVote, UUID, isVip);
|
||||||
} else {
|
} else {
|
||||||
await db.prepare("run", `INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?);
|
await db.prepare("run", `INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
||||||
INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, 0, ?, 0);
|
[videoID, thumbnail.original ? 1 : 0, hashedUserID, service, hashedVideoID, now, UUID]);
|
||||||
${thumbnail.original ? "" : `INSERT INTO "thumbnailTimestamps" ("UUID", "timestamp") VALUES (?, ?)`}`,
|
|
||||||
[videoID, thumbnail.original ? 1 : 0, hashedUserID, service, hashedVideoID, now, UUID, UUID,
|
|
||||||
isVip ? 1 : 0, thumbnail.original ? null : UUID, thumbnail.original ? null : (thumbnail as TimeThumbnailSubmission).timestamp]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
await db.prepare("run", `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, 0, ?, 0)`,
|
||||||
|
[UUID, isVip ? 1 : 0]);
|
||||||
|
|
||||||
|
if (!thumbnail.original) {
|
||||||
|
await db.prepare("run", `INSERT INTO "thumbnailTimestamps" ("UUID", "timestamp") VALUES (?, ?)`,
|
||||||
|
[UUID, (thumbnail as TimeThumbnailSubmission).timestamp]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})()]);
|
})()]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user