A decentralized music tracking and discovery platform built on AT Protocol 🎵

[api] remove refresh sessions logic

-64
-36
rockskyapi/rocksky-auth/src/bsky/app.ts
··· 1 1 import { BlobRef } from "@atproto/lexicon"; 2 2 import { isValidHandle } from "@atproto/syntax"; 3 3 import { equals } from "@xata.io/client"; 4 - import chalk from "chalk"; 5 4 import { ctx } from "context"; 6 5 import { desc, eq } from "drizzle-orm"; 7 6 import { Hono } from "hono"; ··· 71 70 cli = ctx.kv.get(`cli:${handle}`); 72 71 ctx.kv.delete(`cli:${handle}`); 73 72 74 - await fetch(`http://localhost:8000/refresh/${did}`, { 75 - method: "POST", 76 - headers: { 77 - "Content-Type": "application/json", 78 - }, 79 - body: JSON.stringify({}), 80 - }); 81 - 82 73 const token = jwt.sign( 83 74 { 84 75 did, ··· 110 101 return c.redirect(`${env.FRONTEND_URL}?did=${did}&cli=${cli}`); 111 102 }); 112 103 113 - app.post("/refresh/:did", async (c) => { 114 - const cache = await ctx.redis.get(`refresh:${c.req.param("did")}`); 115 - if (cache) { 116 - return c.text(cache); 117 - } 118 - 119 - const did = c.req.param("did"); 120 - setInterval( 121 - () => { 122 - createAgent(ctx.oauthClient, did).catch(() => {}); 123 - console.log(`Refreshing agent for ${chalk.greenBright(did)}`); 124 - }, 125 - // every 5 minutes 126 - 5 * 60 * 1000 127 - ); 128 - await ctx.redis.set(`refresh:${did}`, did); 129 - return c.text("ok"); 130 - }); 131 - 132 104 app.get("/profile", async (c) => { 133 105 requestCounter.add(1, { method: "GET", route: "/profile" }); 134 106 const bearer = (c.req.header("authorization") || "").split(" ")[1]?.trim(); ··· 148 120 c.status(401); 149 121 return c.text("Unauthorized"); 150 122 } 151 - 152 - await fetch(`http://localhost:8000/refresh/${did}`, { 153 - method: "POST", 154 - headers: { 155 - "Content-Type": "application/json", 156 - }, 157 - body: JSON.stringify({}), 158 - }); 159 123 160 124 const { data: profileRecord } = await agent.com.atproto.repo.getRecord({ 161 125 repo: agent.assertDid,
-3
rockskyapi/rocksky-auth/src/index.ts
··· 14 14 } from "lovedtracks/lovedtracks.service"; 15 15 import { scrobbleTrack } from "nowplaying/nowplaying.service"; 16 16 import { rateLimiter } from "ratelimiter"; 17 - import { refreshSessions } from "sessions"; 18 17 import subscribe from "subscribers"; 19 18 import { saveTrack } from "tracks/tracks.service"; 20 19 import { trackSchema } from "types/track"; ··· 33 32 import webscrobbler from "./webscrobbler/app"; 34 33 35 34 subscribe(ctx); 36 - 37 - refreshSessions(); 38 35 39 36 const app = new Hono(); 40 37 const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app });
-25
rockskyapi/rocksky-auth/src/sessions.ts
··· 1 - import chalk from "chalk"; 2 - import { ctx } from "context"; 3 - import { createAgent } from "lib/agent"; 4 - 5 - export async function refreshSessions() { 6 - const keys = await ctx.redis.keys("refresh:*"); 7 - return new Promise<void>((resolve) => { 8 - for (const key of keys) { 9 - const did = key.split("refresh:")[1]; 10 - setTimeout(() => { 11 - setInterval( 12 - async () => { 13 - createAgent(ctx.oauthClient, did).catch(() => {}); 14 - console.log(`Refreshing agent for ${chalk.greenBright(did)}`); 15 - }, 16 - // every 5 minutes 17 - 5 * 60 * 1000 18 - ); 19 - }, 5 * 1000); 20 - } 21 - 22 - console.log(`Refreshed ${chalk.greenBright(keys.length)} sessions`); 23 - resolve(); 24 - }); 25 - }