mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-26 17:38:28 +03:00
Use object for merging locks
Co-authored-by: Nishant Arora <whizzzkid@users.noreply.github.com>
This commit is contained in:
@@ -19,27 +19,27 @@ interface DBLock {
|
|||||||
actionType: ActionType,
|
actionType: ActionType,
|
||||||
}
|
}
|
||||||
|
|
||||||
const mergeLocks = (source: DBLock[], actionTypes: ActionType[]) => {
|
const mergeLocks = (source: DBLock[], actionTypes: ActionType[]): LockResultByHash[] => {
|
||||||
const dest: LockResultByHash[] = [];
|
const dest: { [videoID: VideoID]: LockResultByHash } = {};
|
||||||
for (const obj of source) {
|
for (const obj of source) {
|
||||||
if (!actionTypes.includes(obj.actionType)) continue;
|
if (!actionTypes.includes(obj.actionType)) continue;
|
||||||
// videoID already exists
|
// videoID already exists
|
||||||
const destMatch = dest.find(s => s.videoID === obj.videoID);
|
if (obj.videoID in dest) {
|
||||||
if (destMatch) {
|
|
||||||
// override longer reason
|
// override longer reason
|
||||||
|
const destMatch = dest[obj.videoID];
|
||||||
if (obj.reason?.length > destMatch.reason?.length) destMatch.reason = obj.reason;
|
if (obj.reason?.length > destMatch.reason?.length) destMatch.reason = obj.reason;
|
||||||
// push to categories
|
// push to categories
|
||||||
destMatch.categories.push(obj.category);
|
destMatch.categories.push(obj.category);
|
||||||
} else {
|
} else {
|
||||||
dest.push({
|
dest[obj.videoID] = {
|
||||||
videoID: obj.videoID,
|
videoID: obj.videoID,
|
||||||
hash: obj.hash,
|
hash: obj.hash,
|
||||||
reason: obj.reason,
|
reason: obj.reason,
|
||||||
categories: [obj.category]
|
categories: [obj.category]
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dest;
|
return Object.values(dest);
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function getLockCategoriesByHash(req: Request, res: Response): Promise<Response> {
|
export async function getLockCategoriesByHash(req: Request, res: Response): Promise<Response> {
|
||||||
|
|||||||
Reference in New Issue
Block a user