alpha
Login
or
Join now
flo-bit.dev
/
youtube-party-dj
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
[READ-ONLY] Mirror of https://github.com/flo-bit/youtube-party-dj. democratic youtube player, everyone can vote and add songs, uni project, made with uix
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
changes in sorting and queue handling
author
thaleius
date
2 years ago
(Jul 7, 2024, 12:51 PM UTC)
commit
0bc37fc6
0bc37fc681ad3ef993b826dbd389531142bc7077
parent
aaf38919
aaf3891972ebad2dd18a6c133081b2627cafbbda
+13
-2
1 changed file
Expand all
Collapse all
Unified
Split
backend
sessions.ts
+13
-2
backend/sessions.ts
View file
Reviewed
···
22
22
// map of session codes to session data
23
23
export const sessions = eternalVar('sessions-1234') ?? $$({} as Record<string, SessionData>);
24
24
25
25
+
const sorter = (a: Item, b: Item) => {
26
26
+
if (a.likes.size > b.likes.size) return -1;
27
27
+
if (a.likes.size < b.likes.size) return 1;
28
28
+
if (a.added > b.added) return 1;
29
29
+
if (a.added < b.added) return -1;
30
30
+
return 0;
31
31
+
}
32
32
+
25
33
export const getAndRemoveNextVideoFromSession = (code: string) => {
26
34
const session = sessions[code];
27
35
console.log(session);
28
36
if (!session) {
29
37
return;
30
38
}
31
31
-
console.log(session.queue);
32
32
-
const video = session.queue.shift();
39
39
+
40
40
+
// sort queue by likes and added date, get and remove the first video
41
41
+
const video = session.queue.sort(sorter).shift();
33
42
if (video) {
34
43
session.currentlyPlaying = video;
44
44
+
} else {
45
45
+
session.currentlyPlaying = null;
35
46
}
36
47
return video;
37
48
}