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

fix: correct formatting and type assertions in app.ts for consistency

+28 -25
+28 -25
apps/api/src/spotify/app.ts
··· 22 22 limit: 10, // max Spotify API calls 23 23 window: 15, // per 10 seconds 24 24 keyPrefix: "spotify-ratelimit", 25 - }), 25 + }) 26 26 ); 27 27 28 28 app.get("/login", async (c) => { ··· 55 55 const redirectUrl = `https://accounts.spotify.com/en/authorize?client_id=${env.SPOTIFY_CLIENT_ID}&response_type=code&redirect_uri=${env.SPOTIFY_REDIRECT_URI}&scope=user-read-private%20user-read-email%20user-read-playback-state%20user-read-currently-playing%20user-modify-playback-state%20playlist-modify-public%20playlist-modify-private%20playlist-read-private%20playlist-read-collaborative&state=${state}`; 56 56 c.header( 57 57 "Set-Cookie", 58 - `session-id=${state}; Path=/; HttpOnly; SameSite=Strict; Secure`, 58 + `session-id=${state}; Path=/; HttpOnly; SameSite=Strict; Secure` 59 59 ); 60 60 return c.json({ redirectUrl }); 61 61 }); ··· 78 78 client_secret: env.SPOTIFY_CLIENT_SECRET, 79 79 }), 80 80 }); 81 - const { access_token, refresh_token } = await response.json<{ 81 + const { 82 + access_token, 83 + refresh_token, 84 + }: { 82 85 access_token: string; 83 86 refresh_token: string; 84 - }>(); 87 + } = await response.json(); 85 88 86 89 if (!state) { 87 90 return c.redirect(env.FRONTEND_URL); ··· 133 136 .where( 134 137 and( 135 138 eq(spotifyAccounts.userId, user.id), 136 - eq(spotifyAccounts.isBetaUser, true), 137 - ), 139 + eq(spotifyAccounts.isBetaUser, true) 140 + ) 138 141 ) 139 142 .limit(1) 140 143 .then((rows) => rows[0]); ··· 251 254 } 252 255 253 256 const cached = await ctx.redis.get( 254 - `${spotifyAccount.spotifyAccount.email}:current`, 257 + `${spotifyAccount.spotifyAccount.email}:current` 255 258 ); 256 259 if (!cached) { 257 260 return c.json({}); ··· 261 264 262 265 const sha256 = createHash("sha256") 263 266 .update( 264 - `${track.item.name} - ${track.item.artists.map((x) => x.name).join(", ")} - ${track.item.album.name}`.toLowerCase(), 267 + `${track.item.name} - ${track.item.artists.map((x) => x.name).join(", ")} - ${track.item.album.name}`.toLowerCase() 265 268 ) 266 269 .digest("hex"); 267 270 ··· 334 337 335 338 const refreshToken = decrypt( 336 339 spotifyToken.refreshToken, 337 - env.SPOTIFY_ENCRYPTION_KEY, 340 + env.SPOTIFY_ENCRYPTION_KEY 338 341 ); 339 342 340 343 // get new access token ··· 351 354 }), 352 355 }); 353 356 354 - const { access_token } = await newAccessToken.json<{ 357 + const { access_token } = (await newAccessToken.json()) as { 355 358 access_token: string; 356 - }>(); 359 + }; 357 360 358 361 const response = await fetch("https://api.spotify.com/v1/me/player/pause", { 359 362 method: "PUT", ··· 410 413 411 414 const refreshToken = decrypt( 412 415 spotifyToken.refreshToken, 413 - env.SPOTIFY_ENCRYPTION_KEY, 416 + env.SPOTIFY_ENCRYPTION_KEY 414 417 ); 415 418 416 419 // get new access token ··· 427 430 }), 428 431 }); 429 432 430 - const { access_token } = await newAccessToken.json<{ 433 + const { access_token } = (await newAccessToken.json()) as { 431 434 access_token: string; 432 - }>(); 435 + }; 433 436 434 437 const response = await fetch("https://api.spotify.com/v1/me/player/play", { 435 438 method: "PUT", ··· 486 489 487 490 const refreshToken = decrypt( 488 491 spotifyToken.refreshToken, 489 - env.SPOTIFY_ENCRYPTION_KEY, 492 + env.SPOTIFY_ENCRYPTION_KEY 490 493 ); 491 494 492 495 // get new access token ··· 503 506 }), 504 507 }); 505 508 506 - const { access_token } = await newAccessToken.json<{ 509 + const { access_token } = (await newAccessToken.json()) as { 507 510 access_token: string; 508 - }>(); 511 + }; 509 512 510 513 const response = await fetch("https://api.spotify.com/v1/me/player/next", { 511 514 method: "POST", ··· 562 565 563 566 const refreshToken = decrypt( 564 567 spotifyToken.refreshToken, 565 - env.SPOTIFY_ENCRYPTION_KEY, 568 + env.SPOTIFY_ENCRYPTION_KEY 566 569 ); 567 570 568 571 // get new access token ··· 579 582 }), 580 583 }); 581 584 582 - const { access_token } = await newAccessToken.json<{ 585 + const { access_token } = (await newAccessToken.json()) as { 583 586 access_token: string; 584 - }>(); 587 + }; 585 588 586 589 const response = await fetch( 587 590 "https://api.spotify.com/v1/me/player/previous", ··· 590 593 headers: { 591 594 Authorization: `Bearer ${access_token}`, 592 595 }, 593 - }, 596 + } 594 597 ); 595 598 596 599 if (response.status === 403) { ··· 641 644 642 645 const refreshToken = decrypt( 643 646 spotifyToken.refreshToken, 644 - env.SPOTIFY_ENCRYPTION_KEY, 647 + env.SPOTIFY_ENCRYPTION_KEY 645 648 ); 646 649 647 650 // get new access token ··· 658 661 }), 659 662 }); 660 663 661 - const { access_token } = await newAccessToken.json<{ 664 + const { access_token } = (await newAccessToken.json()) as { 662 665 access_token: string; 663 - }>(); 666 + }; 664 667 665 668 const position = c.req.query("position_ms"); 666 669 const response = await fetch( ··· 670 673 headers: { 671 674 Authorization: `Bearer ${access_token}`, 672 675 }, 673 - }, 676 + } 674 677 ); 675 678 676 679 if (response.status === 403) {