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