Skip to content

Commit

Permalink
fix: PR Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
studiowebux committed Nov 10, 2023
1 parent 18d6fce commit 9270504
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 40 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "spotify-link",
"name": "Spotify Link",
"version": "1.0.2",
"version": "1.0.3",
"minAppVersion": "0.15.0",
"description": "Include the song you're currently listening to in your note.",
"author": "Studio Webux",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spotify-link",
"version": "1.0.2",
"version": "1.0.3",
"description": "Include the song you're currently listening to in your Obsidian (https://obsidian.md) note",
"main": "main.js",
"scripts": {
Expand Down
53 changes: 26 additions & 27 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RequestUrlResponse, requestUrl } from "obsidian";
import {
AccessTokenResponse,
AuthorizationCodeResponse,
Expand Down Expand Up @@ -61,14 +62,15 @@ async function requestAccessToken(
redirect_uri: redirect_uri,
grant_type: "authorization_code",
};
return await fetch("https://accounts.spotify.com/api/token", {
return await requestUrl({
url: "https://accounts.spotify.com/api/token",
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: `Basic ${btoa(clientId + ":" + clientSecret)}`,
},
body: prepareData(data),
}).then((res) => res.json());
}).then((res) => res.json);
}

// Step 4
Expand Down Expand Up @@ -96,17 +98,15 @@ export async function requestRefreshToken(
refresh_token: refreshToken,
grant_type: "refresh_token",
};
const response: RefreshTokenResponse = await fetch(
"https://accounts.spotify.com/api/token",
{
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: `Basic ${btoa(clientId + ":" + clientSecret)}`,
},
body: prepareData(data),
}
).then((res) => res.json());
const response: RefreshTokenResponse = await requestUrl({
url: "https://accounts.spotify.com/api/token",
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: `Basic ${btoa(clientId + ":" + clientSecret)}`,
},
body: prepareData(data),
}).then((res) => res.json);

setAccessToken(response.access_token);
setRefreshToken(response.refresh_token || refreshToken);
Expand All @@ -126,17 +126,15 @@ export async function getCurrentlyPlayingTrack(
const token = await getAccessToken(clientId, clientSecret);

try {
const response: Response = await fetch(
`${SPOTIFY_API_BASE_ADDRESS}/me/player/currently-playing`,
{
method: "GET",
headers: {
Authorization: `Bearer ${token}`,
},
}
);
const json = await response.json();
if (!response.ok) {
const response: RequestUrlResponse = await requestUrl({
url: `${SPOTIFY_API_BASE_ADDRESS}/me/player/currently-playing`,
method: "GET",
headers: {
Authorization: `Bearer ${token}`,
},
});
const { json } = response;
if (response.status !== 200) {
throw new Error(json?.error?.message || response.status);
}

Expand All @@ -163,14 +161,15 @@ export async function getMe(
): Promise<Me> {
const token = await getAccessToken(clientId, clientSecret);

const response: Response = await fetch(`${SPOTIFY_API_BASE_ADDRESS}/me`, {
const response: RequestUrlResponse = await requestUrl({
url: `${SPOTIFY_API_BASE_ADDRESS}/me`,
method: "GET",
headers: {
Authorization: `Bearer ${token}`,
},
});
const json = await response.json();
if (!response.ok) {
const { json } = response;
if (response.status !== 200) {
throw new Error(json?.error?.message || response.status);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default class SpotifyLinkPlugin extends Plugin {
//
this.addCommand({
id: "append-currently-playing-track",
name: "Append Spotify Currently Playing Track with Timestamp",
name: "Append Spotify currently playing track with timestamp",
editorCallback: async (editor: Editor) => {
await handleEditor(
editor,
Expand All @@ -104,7 +104,7 @@ export default class SpotifyLinkPlugin extends Plugin {
});
this.addCommand({
id: "refresh-session",
name: "Refresh Session",
name: "Refresh session",
callback: async () => {
try {
await requestRefreshToken(
Expand Down
8 changes: 1 addition & 7 deletions src/settingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ export default class SettingsTab extends PluginSettingTab {
const { containerEl } = this;

containerEl.empty();

containerEl.createEl("h2", { text: "Spotify Link Settings" });

containerEl.createEl("hr");

containerEl.createEl("h5", { text: "Spotify Integration" });


// INSTRUCTIONS
const div = containerEl.createDiv();
div.createEl("p", {
Expand Down

0 comments on commit 9270504

Please sign in to comment.