-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateDetails.ts
42 lines (37 loc) · 1006 Bytes
/
updateDetails.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import chalk from "npm:chalk";
export default async function updateDetails(
id: string,
token: string,
description: string
): Promise<null> {
const headers = new Headers({
Authorization: `Bearer ${token}`,
Accept: "application/json",
"Content-Type": "application/json",
});
const date = new Date();
date.setMonth(date.getMonth() - 1);
const name = `Doom Charts - ${date.toLocaleString("en-US", {
month: "long",
year: "numeric",
})}`;
try {
const res = await fetch(`https://api.spotify.com/v1/playlists/${id}`, {
method: "PUT",
headers,
body: JSON.stringify({
name,
description,
}),
});
if (!res.ok) {
console.error(`Error: ${res.status} - ${res.statusText}`);
return null;
}
console.log(chalk.green("Updated details"));
return null;
} catch (error) {
console.error(`Error while updating playlist details`, error);
throw error;
}
}