diff --git a/materialious/src/lib/api/backend.ts b/materialious/src/lib/api/backend.ts index 35534f92..9f25ab1a 100644 --- a/materialious/src/lib/api/backend.ts +++ b/materialious/src/lib/api/backend.ts @@ -85,16 +85,22 @@ export async function deleteUnsubscribeBackend(authorId: string) { }); } -export async function postSubscribeBackend(authorId: string) { +export async function postSubscribeBackend( + authorId: string, + authorName: string | undefined = undefined +) { const rawKey = await getRawKey(); if (!rawKey) return; const internalAuthorId = await getInternalAuthorId(authorId, rawKey); - const channel = await getChannelYTjs(authorId); + if (!authorName) { + const channel = await getChannelYTjs(authorId); + authorName = channel.author; + } const channelId = await encryptWithMasterKey(authorId); - const channelName = await encryptWithMasterKey(channel.author); + const channelName = await encryptWithMasterKey(authorName); const resp = await fetch(`/api/user/subscriptions/${internalAuthorId}`, { method: 'POST', diff --git a/materialious/src/lib/api/youtubejs/subscriptions.ts b/materialious/src/lib/api/youtubejs/subscriptions.ts index 7bd7dfa6..85885867 100644 --- a/materialious/src/lib/api/youtubejs/subscriptions.ts +++ b/materialious/src/lib/api/youtubejs/subscriptions.ts @@ -60,7 +60,7 @@ export async function deleteUnsubscribeYTjs(authorId: string) { export async function parseChannelRSS(channelId: string): Promise { const feedUrl = `https://www.youtube.com/feeds/videos.xml?channel_id=${channelId}`; - const response = await fetch(feedUrl); + const response = await fetch(feedUrl, { priority: 'low' }); if (!response.ok) return; const text = await response.text(); diff --git a/materialious/src/lib/components/settings/Engine.svelte b/materialious/src/lib/components/settings/Engine.svelte index bec09b96..d34cc84d 100644 --- a/materialious/src/lib/components/settings/Engine.svelte +++ b/materialious/src/lib/components/settings/Engine.svelte @@ -7,13 +7,16 @@ engineFallbacksStore, engineMaxConcurrentChannelsStore, invidiousInstanceStore, - backendInUseStore + backendInUseStore, + rawMasterKeyStore } from '$lib/store'; import { useEngineFallback, type EngineFallback } from '$lib/api/misc'; import { get } from 'svelte/store'; import { getSubscriptions, postSubscribe } from '$lib/api'; import { postSubscribeYTjs } from '$lib/api/youtubejs/subscriptions'; import { addToast } from '../Toast.svelte'; + import { isOwnBackend } from '$lib/shared'; + import { postSubscribeBackend } from '$lib/api/backend'; const engineFallbacks: EngineFallback[] = [ 'Channel', @@ -53,9 +56,17 @@ } }); + let subscribeFunction: (id: string, name: string) => Promise; + + if (isOwnBackend()?.internalAuth && $rawMasterKeyStore) { + subscribeFunction = postSubscribeBackend; + } else { + subscribeFunction = postSubscribeYTjs; + } + const subPromises: Promise[] = []; importedSubs.forEach((sub) => { - subPromises.push(postSubscribeYTjs(sub.authorId, sub.author)); + subPromises.push(subscribeFunction(sub.authorId, sub.author)); }); await Promise.all(subPromises);