mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-11 05:57:04 +03:00
adjust permissions and use parrallel processing
This commit is contained in:
@@ -4,7 +4,7 @@ import { Client, Pool, QueryResult, types } from "pg";
|
||||
|
||||
import fs from "fs";
|
||||
import { CustomPostgresConfig, CustomPostgresReadOnlyConfig } from "../types/config.model";
|
||||
import { timeoutPomise, PromiseWithState, savePromiseState, nextFulfilment } from "../utils/promiseTimeout";
|
||||
import { timeoutPomise, PromiseWithState, savePromiseState, nextFulfilment } from "../utils/promise";
|
||||
|
||||
// return numeric (pg_type oid=1700) as float
|
||||
types.setTypeParser(1700, function(val) {
|
||||
|
||||
@@ -11,7 +11,7 @@ import { Logger } from "../utils/logger";
|
||||
import { QueryCacher } from "../utils/queryCacher";
|
||||
import { getReputation } from "../utils/reputation";
|
||||
import { getService } from "../utils/getService";
|
||||
import { promiseOrTimeout } from "../utils/promiseTimeout";
|
||||
import { promiseOrTimeout } from "../utils/promise";
|
||||
|
||||
|
||||
async function prepareCategorySegments(req: Request, videoID: VideoID, service: Service, segments: DBSegment[], cache: SegmentCache = { shadowHiddenSegmentIPs: {} }, useCache: boolean): Promise<Segment[]> {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Category } from "../types/segments.model";
|
||||
import { Feature, HashedUserID } from "../types/user.model";
|
||||
import { hasFeature } from "./features";
|
||||
import { isUserVIP } from "./isUserVIP";
|
||||
import { oneOf } from "./promise";
|
||||
import { getReputation } from "./reputation";
|
||||
|
||||
interface CanSubmitResult {
|
||||
@@ -15,16 +16,18 @@ export async function canSubmit(userID: HashedUserID, category: Category): Promi
|
||||
switch (category) {
|
||||
case "chapter":
|
||||
return {
|
||||
canSubmit: (await isUserVIP(userID))
|
||||
|| (await getReputation(userID)) > config.minReputationToSubmitChapter
|
||||
|| (await hasFeature(userID, Feature.ChapterSubmitter))
|
||||
canSubmit: await oneOf([isUserVIP(userID),
|
||||
(async () => (await getReputation(userID)) > config.minReputationToSubmitChapter)(),
|
||||
hasFeature(userID, Feature.ChapterSubmitter)
|
||||
])
|
||||
};
|
||||
case "filler":
|
||||
return {
|
||||
canSubmit: (await isUserVIP(userID))
|
||||
|| (await getReputation(userID)) > config.minReputationToSubmitFiller
|
||||
|| (await hasFeature(userID, Feature.FillerSubmitter))
|
||||
|| (await db.prepare("get", `SELECT count(*) as "submissionCount" FROM "sponsorTimes" WHERE "userID" = ? AND category != 'filler' AND "timeSubmitted" < 1654010691000 LIMIT 4`, [userID], { useReplica: true }))?.submissionCount > 3,
|
||||
canSubmit: await oneOf([isUserVIP(userID),
|
||||
(async () => (await getReputation(userID)) > config.minReputationToSubmitFiller)(),
|
||||
hasFeature(userID, Feature.FillerSubmitter),
|
||||
(async () => (await db.prepare("get", `SELECT count(*) as "submissionCount" FROM "sponsorTimes" WHERE "userID" = ? AND category != 'filler' AND "timeSubmitted" < 1654010691000 LIMIT 4`, [userID], { useReplica: true }))?.submissionCount > 3)()
|
||||
]),
|
||||
reason: "Someone has submitted over 1.9 million spam filler submissions and refuses to stop even after talking with them, so we have to restrict it for now. You can request submission access on chat.sponsor.ajay.app/#filler, discord.gg/SponsorBlock or matrix.to/#/#sponsor:ajay.app"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { Logger } from "./logger";
|
||||
|
||||
export class PromiseTimeoutError<T> extends Error {
|
||||
promise?: Promise<T>;
|
||||
|
||||
@@ -48,3 +50,26 @@ export function savePromiseState<T>(promise: Promise<T>): PromiseWithState<T> {
|
||||
export function nextFulfilment<T>(promises: PromiseWithState<T>[]): Promise<T> {
|
||||
return Promise.race(promises.filter((p) => !p.isRejected));
|
||||
}
|
||||
|
||||
export function oneOf<T>(promises: Promise<T>[]): Promise<T> {
|
||||
return new Promise((resolve, reject) => {
|
||||
let fulfilments = 0;
|
||||
for (const promise of promises) {
|
||||
promise.then((result) => {
|
||||
fulfilments++;
|
||||
|
||||
if (result || fulfilments === promises.length) {
|
||||
resolve(result);
|
||||
}
|
||||
}).catch((err) => {
|
||||
fulfilments++;
|
||||
|
||||
if (fulfilments === promises.length) {
|
||||
reject(err);
|
||||
} else {
|
||||
Logger.error(`oneOf ignore error (promise): ${err}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user