tangled
alpha
login
or
join now
t1c.dev
/
rocksky
forked from
rocksky.app/rocksky
2
fork
atom
A decentralized music tracking and discovery platform built on AT Protocol 🎵
2
fork
atom
overview
issues
pulls
pipelines
[api] add sync library script
tsiry-sandratraina.com
8 months ago
96c1026e
e26e734f
+10
-13
1 changed file
expand all
collapse all
unified
split
apps
api
src
scripts
sync-library.ts
+10
-13
apps/api/src/scripts/sync-library.ts
···
1
1
import chalk from "chalk";
2
2
import { ctx } from "context";
3
3
-
import { and, count, eq, not } from "drizzle-orm";
3
3
+
import { and, count, eq } from "drizzle-orm";
4
4
import tables from "schema";
5
5
import { InsertArtistAlbum } from "schema/artist-albums";
6
6
···
8
8
const total = await ctx.db
9
9
.select({ value: count() })
10
10
.from(tables.tracks)
11
11
-
.where(
12
12
-
and(
13
13
-
not(eq(tables.tracks.albumUri, null)),
14
14
-
not(eq(tables.tracks.artistUri, null))
15
15
-
)
16
16
-
)
17
11
.execute()
18
12
.then(([row]) => row.value);
19
13
···
27
21
const results = await ctx.db
28
22
.select()
29
23
.from(tables.tracks)
30
30
-
.where(
31
31
-
and(
32
32
-
not(eq(tables.tracks.albumUri, null)),
33
33
-
not(eq(tables.tracks.artistUri, null))
34
34
-
)
35
35
-
)
36
24
.limit(size)
37
25
.offset(skip)
38
26
.execute();
39
27
40
28
for (const track of results) {
29
29
+
if (!track.artistUri || !track.albumUri) {
30
30
+
console.log(
31
31
+
`Skipping track ${chalk.cyan(track.title)} due to missing artist or album URI`
32
32
+
);
33
33
+
console.log("artistUri", track.artistUri);
34
34
+
console.log("albumUri", track.albumUri);
35
35
+
continue;
36
36
+
}
37
37
+
41
38
const found = await ctx.db
42
39
.select()
43
40
.from(tables.artistAlbums)