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
Hydrate artists with DB pictures
tsiry-sandratraina.com
2 months ago
9abf3fe3
e7e631e9
+38
-4
1 changed file
expand all
collapse all
unified
split
apps
api
src
xrpc
app
rocksky
artist
getArtists.ts
+38
-4
apps/api/src/xrpc/app/rocksky/artist/getArtists.ts
···
4
4
import type { ArtistViewBasic } from "lexicon/types/app/rocksky/artist/defs";
5
5
import type { QueryParams } from "lexicon/types/app/rocksky/artist/getArtists";
6
6
import { deepCamelCaseKeys } from "lib";
7
7
+
import tables from "schema";
8
8
+
import { inArray } from "drizzle-orm";
7
9
8
10
export default function (server: Server, ctx: Context) {
9
11
const getArtists = (params) =>
···
35
37
}: {
36
38
params: QueryParams;
37
39
ctx: Context;
38
38
-
}): Effect.Effect<{ data: Artist[] }, Error> => {
40
40
+
}): Effect.Effect<{ data: Artist[]; ctx: Context }, Error> => {
39
41
return Effect.tryPromise({
40
40
-
try: () =>
41
41
-
ctx.analytics.post("library.getArtists", {
42
42
+
try: async () => {
43
43
+
const response = await ctx.analytics.post("library.getArtists", {
42
44
pagination: {
43
45
skip: params.offset || 0,
44
46
take: params.limit || 100,
45
47
},
46
46
-
}),
48
48
+
});
49
49
+
return { data: response.data, ctx };
50
50
+
},
47
51
catch: (error) => new Error(`Failed to retrieve artists: ${error}`),
52
52
+
});
53
53
+
};
54
54
+
55
55
+
const hydrate = ({
56
56
+
data,
57
57
+
ctx,
58
58
+
}: {
59
59
+
data: Artist[];
60
60
+
ctx: Context;
61
61
+
}): Effect.Effect<{ data: Artist[] }, Error> => {
62
62
+
return Effect.tryPromise({
63
63
+
try: async () => {
64
64
+
const artists = await ctx.db
65
65
+
.select()
66
66
+
.from(tables.artists)
67
67
+
.where(
68
68
+
inArray(
69
69
+
tables.artists.id,
70
70
+
data.map((artist) => artist.id),
71
71
+
),
72
72
+
)
73
73
+
.execute();
74
74
+
return {
75
75
+
data: data.map((artist) => ({
76
76
+
...artist,
77
77
+
picture: artists.find((a) => a.id === artist.id)?.picture,
78
78
+
})),
79
79
+
};
80
80
+
},
81
81
+
catch: (error) => new Error(`Failed to hydrate artists: ${error}`),
48
82
});
49
83
};
50
84