mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 09:07:47 +01:00
Use object for merging locks
Co-authored-by: Nishant Arora <whizzzkid@users.noreply.github.com>
This commit is contained in:
parent
acb5a9467e
commit
8759f8dbf2
1 changed files with 7 additions and 7 deletions
|
@ -19,27 +19,27 @@ interface DBLock {
|
|||
actionType: ActionType,
|
||||
}
|
||||
|
||||
const mergeLocks = (source: DBLock[], actionTypes: ActionType[]) => {
|
||||
const dest: LockResultByHash[] = [];
|
||||
const mergeLocks = (source: DBLock[], actionTypes: ActionType[]): LockResultByHash[] => {
|
||||
const dest: { [videoID: VideoID]: LockResultByHash } = {};
|
||||
for (const obj of source) {
|
||||
if (!actionTypes.includes(obj.actionType)) continue;
|
||||
// videoID already exists
|
||||
const destMatch = dest.find(s => s.videoID === obj.videoID);
|
||||
if (destMatch) {
|
||||
if (obj.videoID in dest) {
|
||||
// override longer reason
|
||||
const destMatch = dest[obj.videoID];
|
||||
if (obj.reason?.length > destMatch.reason?.length) destMatch.reason = obj.reason;
|
||||
// push to categories
|
||||
destMatch.categories.push(obj.category);
|
||||
} else {
|
||||
dest.push({
|
||||
dest[obj.videoID] = {
|
||||
videoID: obj.videoID,
|
||||
hash: obj.hash,
|
||||
reason: obj.reason,
|
||||
categories: [obj.category]
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
return dest;
|
||||
return Object.values(dest);
|
||||
};
|
||||
|
||||
export async function getLockCategoriesByHash(req: Request, res: Response): Promise<Response> {
|
||||
|
|
Loading…
Reference in a new issue