mirror of
https://github.com/LBRYFoundation/Watch-on-LBRY.git
synced 2025-08-23 17:47:26 +00:00
🍱 Refactor, removed not used backend code. bugfixes
This commit is contained in:
parent
205a8fd151
commit
4cdcc4c9a4
2 changed files with 3 additions and 36 deletions
|
@ -1,42 +1,9 @@
|
|||
import { appRedirectUrl, parseProtocolUrl } from '../common/lbry-url'
|
||||
import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, TargetPlatformName } from '../common/settings'
|
||||
import { YtIdResolverDescriptor, ytService } from '../common/yt'
|
||||
import { TargetPlatformName } from '../common/settings'
|
||||
import { YtIdResolverDescriptor } from '../common/yt'
|
||||
export interface UpdateContext {
|
||||
descriptor: YtIdResolverDescriptor
|
||||
/** LBRY URL fragment */
|
||||
lbryPathname: string
|
||||
redirect: boolean
|
||||
targetPlatform: TargetPlatformName
|
||||
}
|
||||
|
||||
async function resolveYT(descriptor: YtIdResolverDescriptor) {
|
||||
const lbryProtocolUrl: string | null = await ytService.resolveById([descriptor]).then(a => a[0]);
|
||||
const segments = parseProtocolUrl(lbryProtocolUrl || '', { encode: true });
|
||||
if (segments.length === 0) return;
|
||||
return segments.join('/');
|
||||
}
|
||||
|
||||
const ctxFromURLOnGoingPromise: Record<string, Promise<UpdateContext | void>> = {}
|
||||
async function ctxFromURL(href: string): Promise<UpdateContext | void> {
|
||||
if (!href) return;
|
||||
|
||||
const url = new URL(href);
|
||||
if (!getSourcePlatfromSettingsFromHostname(url.hostname)) return
|
||||
if (!(url.pathname.startsWith('/watch') || url.pathname.startsWith('/channel'))) return
|
||||
|
||||
const descriptor = ytService.getId(href);
|
||||
if (!descriptor) return; // couldn't get the ID, so we're done
|
||||
|
||||
// Don't create a new Promise for same ID until on going one is over.
|
||||
const promise = ctxFromURLOnGoingPromise[descriptor.id] ?? (ctxFromURLOnGoingPromise[descriptor.id] = (async () => {
|
||||
// NOTE: API call cached by resolveYT method automatically
|
||||
const res = await resolveYT(descriptor)
|
||||
if (!res) return // couldn't find it on lbry, so we're done
|
||||
|
||||
const { redirect, targetPlatform } = await getExtensionSettingsAsync()
|
||||
return { descriptor, lbryPathname: res, redirect, targetPlatform }
|
||||
})())
|
||||
await promise
|
||||
delete ctxFromURLOnGoingPromise[descriptor.id]
|
||||
return await promise
|
||||
}
|
|
@ -22,7 +22,7 @@ async function lbryChannelsFromFile(file: File) {
|
|||
const lbryUrls = await ytService.resolveById(
|
||||
Array.from(ids).map(id => ({ id, type: 'channel' } as const)),
|
||||
(progress) => render(<YTtoLBRY progress={progress} />, document.getElementById('root')!));
|
||||
const { targetPlatform: platform } = await getExtensionSettingsAsync('targetPlatform');
|
||||
const { targetPlatform: platform } = await getExtensionSettingsAsync();
|
||||
const urlPrefix = targetPlatformSettings[platform].domainPrefix;
|
||||
return lbryUrls.map(channel => urlPrefix + channel);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue