A decentralized music tracking and discovery platform built on AT Protocol 🎵 rocksky.app
spotify atproto lastfm musicbrainz scrobbling listenbrainz
98
fork

Configure Feed

Select the types of activity you want to include in your feed.

add meilisearch sync script

+129
+1
rockskyapi/rocksky-auth/package.json
··· 10 10 "prod": "tsx ./src/index.ts", 11 11 "build": "pkgroll", 12 12 "sync": "tsx ./src/scripts/sync.ts", 13 + "meili:sync": "tsx ./src/scripts/meili.ts", 13 14 "avatar": "tsx ./src/scripts/avatar.ts", 14 15 "pkl:eval": "pkl eval -f json", 15 16 "pkl:gen": "tsx ./scripts/pkl.ts",
+4
rockskyapi/rocksky-auth/src/context.ts
··· 34 34 dropbox: axios.create({ baseURL: env.DROPBOX }), 35 35 googledrive: axios.create({ baseURL: env.GOOGLE_DRIVE }), 36 36 redis: await redis.createClient({ url: env.REDIS_URL }).connect(), 37 + meilisearch: axios.create({ 38 + baseURL: env.MEILISEARCH_URL, 39 + headers: { Authorization: `Bearer ${env.MEILISEARCH_API_KEY}` }, 40 + }), 37 41 authVerifier, 38 42 }; 39 43
+2
rockskyapi/rocksky-auth/src/lib/env.ts
··· 37 37 PRIVATE_KEY_1: str({}), 38 38 PRIVATE_KEY_2: str({}), 39 39 PRIVATE_KEY_3: str({}), 40 + MEILISEARCH_URL: str({ devDefault: "http://localhost:7700" }), 41 + MEILISEARCH_API_KEY: str({}), 40 42 });
+122
rockskyapi/rocksky-auth/src/scripts/meili.ts
··· 1 + import chalk from "chalk"; 2 + import { ctx } from "context"; 3 + import { count } from "drizzle-orm"; 4 + import tables from "schema"; 5 + 6 + async function main() { 7 + console.log(chalk.cyan("Starting Meilisearch sync...")); 8 + 9 + try { 10 + await Promise.all([ 11 + createAlbums(), 12 + createArtists(), 13 + createTracks(), 14 + createUsers(), 15 + ]); 16 + console.log(chalk.green("Meilisearch sync completed successfully.")); 17 + } catch (error) { 18 + console.error(chalk.red("Error during Meilisearch sync:"), error); 19 + } 20 + } 21 + 22 + main() 23 + .then(() => { 24 + console.log(chalk.green("Meilisearch sync script finished.")); 25 + }) 26 + .catch((error) => { 27 + console.error(chalk.red("Error in Meilisearch sync script:"), error); 28 + }); 29 + 30 + async function createAlbums() { 31 + const { meilisearch } = ctx; 32 + let skip = 0; 33 + let size = 100; 34 + const total = await ctx.db 35 + .select({ value: count() }) 36 + .from(tables.albums) 37 + .execute() 38 + .then(([row]) => row.value); 39 + const results = await ctx.db 40 + .select() 41 + .from(tables.albums) 42 + .limit(size) 43 + .offset(skip) 44 + .execute(); 45 + 46 + await meilisearch.post(`indexes/albums/documents?primaryKey=id`, results); 47 + } 48 + 49 + async function createArtists() { 50 + const { meilisearch } = ctx; 51 + let size = 100; 52 + const total = await ctx.db 53 + .select({ value: count() }) 54 + .from(tables.artists) 55 + .execute() 56 + .then(([row]) => row.value); 57 + for (let i = 0; i < total; i += size) { 58 + const skip = i; 59 + console.log( 60 + `Processing ${chalk.magentaBright("artists")}: ${chalk.magentaBright(skip)} to ${chalk.magentaBright(skip + size)}` 61 + ); 62 + const results = await ctx.db 63 + .select() 64 + .from(tables.artists) 65 + .limit(size) 66 + .offset(skip) 67 + .execute(); 68 + 69 + await meilisearch.post(`indexes/artists/documents?primaryKey=id`, results); 70 + } 71 + } 72 + 73 + async function createTracks() { 74 + const { meilisearch } = ctx; 75 + let size = 100; 76 + const total = await ctx.db 77 + .select({ value: count() }) 78 + .from(tables.tracks) 79 + .execute() 80 + .then(([row]) => row.value); 81 + for (let i = 0; i < total; i += size) { 82 + const skip = i; 83 + console.log( 84 + `Processing ${chalk.magentaBright("tracks")}: ${chalk.magentaBright(skip)} to ${chalk.magentaBright(skip + size)}` 85 + ); 86 + const results = await ctx.db 87 + .select() 88 + .from(tables.tracks) 89 + .limit(size) 90 + .offset(skip) 91 + .execute(); 92 + 93 + await meilisearch.post(`/indexes/tracks/documents?primaryKey=id`, results); 94 + } 95 + } 96 + 97 + async function createUsers() { 98 + const { meilisearch } = ctx; 99 + let size = 100; 100 + const total = await ctx.db 101 + .select({ value: count() }) 102 + .from(tables.users) 103 + .execute() 104 + .then(([row]) => row.value); 105 + 106 + for (let i = 0; i < total; i += size) { 107 + const skip = i; 108 + console.log( 109 + `Processing ${chalk.magentaBright("users")}: ${chalk.magentaBright(skip)} to ${chalk.magentaBright(skip + size)}` 110 + ); 111 + const results = await ctx.db 112 + .select() 113 + .from(tables.users) 114 + .limit(size) 115 + .offset(skip) 116 + .execute(); 117 + 118 + await meilisearch.post(`/indexes/users/documents?primaryKey=id`, results); 119 + } 120 + } 121 + 122 + process.exit(0);