hardcoded whatever idc for now
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { importPKCS8, SignJWT, GeneralSign } from "jose";
|
||||
|
||||
const TEAM_ID = process.env.TEAM_ID!;
|
||||
const KEY_ID = process.env.KEY_ID!;
|
||||
const privateKey = await Bun.file(process.env.AUTHKEY_PATH!).text();
|
||||
const realKey = await importPKCS8(privateKey, "ES256");
|
||||
|
||||
let currentTime = Date.now();
|
||||
const jwt = new SignJWT()
|
||||
.setIssuer(TEAM_ID)
|
||||
.setIssuedAt(Math.floor(currentTime / 1000))
|
||||
.setExpirationTime(Math.floor(currentTime / 1000) + 60 * 60 * 72)
|
||||
|
||||
jwt.setProtectedHeader({
|
||||
alg: 'ES256',
|
||||
kid: KEY_ID
|
||||
});
|
||||
|
||||
const apmToken = await jwt.sign(realKey);
|
||||
|
||||
export async function appleMusicFetch(url: string): Promise<any> {
|
||||
return fetch("https://api.music.apple.com/v1" + url, {
|
||||
headers: {
|
||||
"Authorization": `Bearer ${apmToken}`
|
||||
}
|
||||
}).then(res => res.json());
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
const s = new URLSearchParams();
|
||||
s.append("grant_type", "client_credentials");
|
||||
const spotify_response = await fetch("https://accounts.spotify.com/api/token", {
|
||||
headers: {
|
||||
"Authorization": `Basic ${Buffer.from(process.env.SPOTIFY_CLIENT + ":" + process.env.SPOTIFY_SECRET).toString('base64')}`,
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
body: s.toString(),
|
||||
method: "POST"
|
||||
}).then(res => res.json());
|
||||
|
||||
const sptToken = spotify_response.access_token;
|
||||
|
||||
export async function spotifyFetch(url: string): Promise<any> {
|
||||
return fetch("https://api.spotify.com/v1" + url, {
|
||||
headers: {
|
||||
"Authorization": `Bearer ${sptToken}`
|
||||
}
|
||||
}).then(res => res.json());
|
||||
}
|
||||
Reference in New Issue
Block a user