tangled
alpha
login
or
join now
rocksky.app
/
rocksky
98
fork
atom
A decentralized music tracking and discovery platform built on AT Protocol 🎵
rocksky.app
spotify
atproto
lastfm
musicbrainz
scrobbling
listenbrainz
98
fork
atom
overview
issues
7
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
import chalk from "chalk";
2
import { ctx } from "context";
3
-
import { and, count, eq, not } from "drizzle-orm";
4
import tables from "schema";
5
import { InsertArtistAlbum } from "schema/artist-albums";
6
···
8
const total = await ctx.db
9
.select({ value: count() })
10
.from(tables.tracks)
11
-
.where(
12
-
and(
13
-
not(eq(tables.tracks.albumUri, null)),
14
-
not(eq(tables.tracks.artistUri, null))
15
-
)
16
-
)
17
.execute()
18
.then(([row]) => row.value);
19
···
27
const results = await ctx.db
28
.select()
29
.from(tables.tracks)
30
-
.where(
31
-
and(
32
-
not(eq(tables.tracks.albumUri, null)),
33
-
not(eq(tables.tracks.artistUri, null))
34
-
)
35
-
)
36
.limit(size)
37
.offset(skip)
38
.execute();
39
40
for (const track of results) {
0
0
0
0
0
0
0
0
0
41
const found = await ctx.db
42
.select()
43
.from(tables.artistAlbums)
···
1
import chalk from "chalk";
2
import { ctx } from "context";
3
+
import { and, count, eq } from "drizzle-orm";
4
import tables from "schema";
5
import { InsertArtistAlbum } from "schema/artist-albums";
6
···
8
const total = await ctx.db
9
.select({ value: count() })
10
.from(tables.tracks)
0
0
0
0
0
0
11
.execute()
12
.then(([row]) => row.value);
13
···
21
const results = await ctx.db
22
.select()
23
.from(tables.tracks)
0
0
0
0
0
0
24
.limit(size)
25
.offset(skip)
26
.execute();
27
28
for (const track of results) {
29
+
if (!track.artistUri || !track.albumUri) {
30
+
console.log(
31
+
`Skipping track ${chalk.cyan(track.title)} due to missing artist or album URI`
32
+
);
33
+
console.log("artistUri", track.artistUri);
34
+
console.log("albumUri", track.albumUri);
35
+
continue;
36
+
}
37
+
38
const found = await ctx.db
39
.select()
40
.from(tables.artistAlbums)