Skip to content

Commit

Permalink
Merge pull request #500 from matt8707/youtube
Browse files Browse the repository at this point in the history
Update youtube addon
  • Loading branch information
matt8707 authored Jun 17, 2024
2 parents fdc82ab + 79254bb commit a401c95
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@
"svelte-ripple": "^0.1.1",
"svelte-tiny-virtual-list": "^2.1.2",
"weekstart": "^2.0.0",
"youtubei.js": "^9.4.0"
"youtubei.js": "^10.0.0"
}
}
11 changes: 8 additions & 3 deletions src/lib/Modal/YoutubeModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@
const result = await response.json();
data = result;
if (!response.ok) {
throw new Error(result?.message);
}
clearInterval(interval);
} catch (err: any) {
if (err?.name === 'AbortError') {
// ignore
} else {
event = { message: 'error', error: 'Failed to initiate authentication' };
console.error('Failed to initiate authentication:', err);
event = { message: 'error', error: err?.message };
console.error(err);
}
clearInterval(interval);
}
Expand Down Expand Up @@ -183,7 +188,7 @@
<div class="user-info">
<img src={account_photo} alt="" />

<span>{account_name}</span>
<span>{account_name || ''}</span>

<button
class="action remove"
Expand Down
22 changes: 13 additions & 9 deletions src/routes/_api/youtube/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ export const POST: RequestHandler = async ({ request }) => {

// logout
} else if (message === 'logout') {
if (!youtube) {
return json({
message: 'error',
error: 'YouTube not initialized'
});
}

try {
await youtube.session.signOut();
// catch error if not signed in
// so credentials can be removed anyway
try {
await youtube?.session.signOut();
} catch (err) {
console.error(err);
}
unlinkSync(credentialsFilePath);
const configFilePath = './data/configuration.yaml';
let config = await loadFile(configFilePath);
Expand Down Expand Up @@ -156,7 +155,12 @@ export const GET: RequestHandler = async () => {
};
});

const auth = await loadFile(credentialsFilePath);
let auth = await loadFile(credentialsFilePath);

// load function returned empty object
// signIn expects undefined if empty
if (!Object.keys(auth)?.length) auth = undefined;

await youtube.session.signIn(auth);

const data = await youtube.account.getInfo();
Expand Down

0 comments on commit a401c95

Please sign in to comment.