mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-06 11:36:58 +03:00
Support private db with postgres
This commit is contained in:
@@ -29,7 +29,7 @@ CREATE TABLE IF NOT EXISTS "config" (
|
|||||||
"value" TEXT NOT NULL
|
"value" TEXT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS sponsorTimes_hashedIP on sponsorTimes(hashedIP);
|
CREATE INDEX IF NOT EXISTS "sponsorTimes_hashedIP" on "sponsorTimes"("hashedIP");
|
||||||
CREATE INDEX IF NOT EXISTS votes_userID on votes(UUID);
|
CREATE INDEX IF NOT EXISTS "votes_userID" on "votes"("UUID");
|
||||||
|
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|||||||
@@ -3,6 +3,6 @@ BEGIN TRANSACTION;
|
|||||||
/* for testing the db upgrade, don't remove because it looks empty */
|
/* for testing the db upgrade, don't remove because it looks empty */
|
||||||
|
|
||||||
/* Add version to config */
|
/* Add version to config */
|
||||||
INSERT INTO config (key, value) VALUES("version", 1);
|
INSERT INTO config (key, value) VALUES('version', 1);
|
||||||
|
|
||||||
COMMIT;
|
COMMIT;
|
||||||
@@ -17,18 +17,28 @@ if (config.mysql) {
|
|||||||
fileNamePrefix: 'sponsorTimes',
|
fileNamePrefix: 'sponsorTimes',
|
||||||
readOnly: config.readOnly,
|
readOnly: config.readOnly,
|
||||||
createDbIfNotExists: config.createDatabaseIfNotExist,
|
createDbIfNotExists: config.createDatabaseIfNotExist,
|
||||||
enableWalCheckpointNumber: !config.readOnly && config.mode === "production",
|
postgres: {
|
||||||
postgres: config.postgres
|
user: config.postgres?.user,
|
||||||
|
host: config.postgres?.host,
|
||||||
|
database: "sponsorTimes",
|
||||||
|
password: config.postgres?.password,
|
||||||
|
port: config.postgres?.port,
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
privateDB = new Sqlite({
|
privateDB = new Postgres({
|
||||||
dbPath: config.privateDB,
|
|
||||||
dbSchemaFileName: config.privateDBSchema,
|
dbSchemaFileName: config.privateDBSchema,
|
||||||
dbSchemaFolder: config.schemaFolder,
|
dbSchemaFolder: config.schemaFolder,
|
||||||
fileNamePrefix: 'private',
|
fileNamePrefix: 'private',
|
||||||
readOnly: config.readOnly,
|
readOnly: config.readOnly,
|
||||||
createDbIfNotExists: config.createDatabaseIfNotExist,
|
createDbIfNotExists: config.createDatabaseIfNotExist,
|
||||||
enableWalCheckpointNumber: false
|
postgres: {
|
||||||
|
user: config.postgres?.user,
|
||||||
|
host: config.postgres?.host,
|
||||||
|
database: "privateDB",
|
||||||
|
password: config.postgres?.password,
|
||||||
|
port: config.postgres?.port,
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
db = new Sqlite({
|
db = new Sqlite({
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ async function sendWebhooks(voteData: VoteData) {
|
|||||||
|
|
||||||
async function categoryVote(UUID: string, userID: string, isVIP: boolean, isOwnSubmission: boolean, category: string, hashedIP: string, res: Response) {
|
async function categoryVote(UUID: string, userID: string, isVIP: boolean, isOwnSubmission: boolean, category: string, hashedIP: string, res: Response) {
|
||||||
// Check if they've already made a vote
|
// Check if they've already made a vote
|
||||||
const usersLastVoteInfo = await privateDB.prepare('get', `select count(*) as votes, category from "categoryVotes" where "UUID" = ? and "userID" = ?`, [UUID, userID]);
|
const usersLastVoteInfo = await privateDB.prepare('get', `select count(*) as votes, category from "categoryVotes" where "UUID" = ? and "userID" = ? group by category`, [UUID, userID]);
|
||||||
|
|
||||||
if (usersLastVoteInfo?.category === category) {
|
if (usersLastVoteInfo?.category === category) {
|
||||||
// Double vote, ignore
|
// Double vote, ignore
|
||||||
@@ -250,7 +250,6 @@ export async function voteOnSponsorTime(req: Request, res: Response) {
|
|||||||
//check if user voting on own submission
|
//check if user voting on own submission
|
||||||
const isOwnSubmission = (await db.prepare("get", `SELECT "UUID" as "submissionCount" FROM "sponsorTimes" where "userID" = ? AND "UUID" = ?`, [nonAnonUserID, UUID])) !== undefined;
|
const isOwnSubmission = (await db.prepare("get", `SELECT "UUID" as "submissionCount" FROM "sponsorTimes" where "userID" = ? AND "UUID" = ?`, [nonAnonUserID, UUID])) !== undefined;
|
||||||
|
|
||||||
|
|
||||||
// If not upvote
|
// If not upvote
|
||||||
if (!isVIP && type !== 1) {
|
if (!isVIP && type !== 1) {
|
||||||
const isSegmentLocked = async () => !!(await db.prepare('get', `SELECT "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]))?.locked;
|
const isSegmentLocked = async () => !!(await db.prepare('get', `SELECT "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]))?.locked;
|
||||||
|
|||||||
Reference in New Issue
Block a user