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
Merge branch 'main' into feat/feed-generator
tsiry-sandratraina.com
2 months ago
df6c3f38
922075e3
+37
-15
4 changed files
expand all
collapse all
unified
split
apps
api
src
auth
client.ts
lib
env.ts
xrpc
app
rocksky
charts
getScrobblesChart.ts
feed
getNowPlayings.ts
+4
-2
apps/api/src/auth/client.ts
···
8
9
export const createClient = async (db: Database) => {
10
const publicUrl = env.PUBLIC_URL;
11
-
const url = publicUrl || `http://127.0.0.1:${env.PORT}`;
0
0
12
const enc = encodeURIComponent;
13
14
const redis = new Redis(env.REDIS_URL);
···
26
return new NodeOAuthClient({
27
clientMetadata: {
28
client_name: "Rocksky",
29
-
client_id: publicUrl
30
? `${url}/oauth-client-metadata.json`
31
: `http://localhost?redirect_uri=${enc(
32
`${url}/oauth/callback`,
···
8
9
export const createClient = async (db: Database) => {
10
const publicUrl = env.PUBLIC_URL;
11
+
const url = publicUrl.includes("localhost")
12
+
? `http://127.0.0.1:${env.PORT}`
13
+
: publicUrl;
14
const enc = encodeURIComponent;
15
16
const redis = new Redis(env.REDIS_URL);
···
28
return new NodeOAuthClient({
29
clientMetadata: {
30
client_name: "Rocksky",
31
+
client_id: !publicUrl.includes("localhost")
32
? `${url}/oauth-client-metadata.json`
33
: `http://localhost?redirect_uri=${enc(
34
`${url}/oauth/callback`,
+1
-1
apps/api/src/lib/env.ts
···
10
}),
11
HOST: host({ devDefault: testOnly("localhost") }),
12
PORT: port({ devDefault: testOnly(8000) }),
13
-
PUBLIC_URL: str({}),
14
DB_PATH: str({ devDefault: ":memory:" }),
15
KV_DB_PATH: str({ devDefault: ":memory:" }),
16
COOKIE_SECRET: str({ devDefault: "00000000000000000000000000000000" }),
···
10
}),
11
HOST: host({ devDefault: testOnly("localhost") }),
12
PORT: port({ devDefault: testOnly(8000) }),
13
+
PUBLIC_URL: str({ devDefault: "http://localhost:8000" }),
14
DB_PATH: str({ devDefault: ":memory:" }),
15
KV_DB_PATH: str({ devDefault: ":memory:" }),
16
COOKIE_SECRET: str({ devDefault: "00000000000000000000000000000000" }),
+16
-6
apps/api/src/xrpc/app/rocksky/charts/getScrobblesChart.ts
···
1
import type { Context } from "context";
2
import { eq } from "drizzle-orm";
3
-
import { Effect, Match, pipe } from "effect";
4
import type { Server } from "lexicon";
5
import type { ChartsView } from "lexicon/types/app/rocksky/charts/defs";
6
import type { QueryParams } from "lexicon/types/app/rocksky/charts/getScrobblesChart";
7
import tables from "schema";
8
9
export default function (server: Server, ctx: Context) {
0
0
0
0
0
0
0
0
0
0
0
0
0
10
const getScrobblesChart = (params) =>
11
pipe(
12
-
{ params, ctx },
13
-
retrieve,
14
-
Effect.flatMap(presentation),
15
-
Effect.retry({ times: 3 }),
16
-
Effect.timeout("10 seconds"),
17
Effect.catchAll((err) => {
18
console.error(err);
19
return Effect.succeed({ scrobbles: [] });
···
1
import type { Context } from "context";
2
import { eq } from "drizzle-orm";
3
+
import { Effect, Match, pipe, Cache, Duration } from "effect";
4
import type { Server } from "lexicon";
5
import type { ChartsView } from "lexicon/types/app/rocksky/charts/defs";
6
import type { QueryParams } from "lexicon/types/app/rocksky/charts/getScrobblesChart";
7
import tables from "schema";
8
9
export default function (server: Server, ctx: Context) {
10
+
const getScrobblesCache = Cache.make({
11
+
capacity: 100,
12
+
timeToLive: Duration.seconds(30),
13
+
lookup: (params: QueryParams) =>
14
+
pipe(
15
+
{ params, ctx },
16
+
retrieve,
17
+
Effect.flatMap(presentation),
18
+
Effect.retry({ times: 3 }),
19
+
Effect.timeout("10 seconds"),
20
+
),
21
+
});
22
+
23
const getScrobblesChart = (params) =>
24
pipe(
25
+
getScrobblesCache,
26
+
Effect.flatMap((cache) => cache.get(params)),
0
0
0
27
Effect.catchAll((err) => {
28
console.error(err);
29
return Effect.succeed({ scrobbles: [] });
+16
-6
apps/api/src/xrpc/app/rocksky/feed/getNowPlayings.ts
···
1
import type { Context } from "context";
2
-
import { Effect, pipe } from "effect";
3
import type { Server } from "lexicon";
4
import type { NowPlayingView } from "lexicon/types/app/rocksky/feed/defs";
5
import type { QueryParams } from "lexicon/types/app/rocksky/feed/getNowPlayings";
6
import { deepCamelCaseKeys } from "lib";
7
8
export default function (server: Server, ctx: Context) {
0
0
0
0
0
0
0
0
0
0
0
0
0
9
const getNowPlayings = (params) =>
10
pipe(
11
-
{ params, ctx },
12
-
retrieve,
13
-
Effect.flatMap(presentation),
14
-
Effect.retry({ times: 3 }),
15
-
Effect.timeout("10 seconds"),
16
Effect.catchAll((err) => {
17
console.error(err);
18
return Effect.succeed({});
···
1
import type { Context } from "context";
2
+
import { Effect, pipe, Cache, Duration } from "effect";
3
import type { Server } from "lexicon";
4
import type { NowPlayingView } from "lexicon/types/app/rocksky/feed/defs";
5
import type { QueryParams } from "lexicon/types/app/rocksky/feed/getNowPlayings";
6
import { deepCamelCaseKeys } from "lib";
7
8
export default function (server: Server, ctx: Context) {
9
+
const nowPlayingCache = Cache.make({
10
+
capacity: 100,
11
+
timeToLive: Duration.seconds(30),
12
+
lookup: (params: QueryParams) =>
13
+
pipe(
14
+
{ params, ctx },
15
+
retrieve,
16
+
Effect.flatMap(presentation),
17
+
Effect.retry({ times: 3 }),
18
+
Effect.timeout("10 seconds"),
19
+
),
20
+
});
21
+
22
const getNowPlayings = (params) =>
23
pipe(
24
+
nowPlayingCache,
25
+
Effect.flatMap((cache) => cache.get(params)),
0
0
0
26
Effect.catchAll((err) => {
27
console.error(err);
28
return Effect.succeed({});