Minor fixes to associateAvatar
This commit is contained in:
@@ -12,7 +12,7 @@ export async function getChannelInvidious(
|
||||
const respJson = await resp.json();
|
||||
|
||||
if (resp.ok) {
|
||||
associateAvatar(channelId, respJson.authorBanners);
|
||||
await associateAvatar(channelId, respJson.authorThumbnails);
|
||||
}
|
||||
|
||||
return respJson;
|
||||
|
||||
@@ -25,7 +25,7 @@ export async function getVideoInvidious(
|
||||
const respJson = await resp.json();
|
||||
|
||||
if (resp.ok) {
|
||||
associateAvatar(respJson.authorId, respJson.authorThumbnails);
|
||||
await associateAvatar(respJson.authorId, respJson.authorThumbnails);
|
||||
}
|
||||
|
||||
return respJson;
|
||||
|
||||
@@ -24,9 +24,10 @@ export async function getChannelYTjs(channelId: string): Promise<ChannelPage> {
|
||||
innerResults.header.content?.is(YTNodes.PageHeaderView)
|
||||
) {
|
||||
authorBanners = innerResults.header.content.banner?.image ?? [];
|
||||
associateAvatar(channelId, authorBanners);
|
||||
}
|
||||
|
||||
if (innerResults.metadata.avatar) await associateAvatar(channelId, innerResults.metadata.avatar);
|
||||
|
||||
const description = innerResults.metadata.description ?? '';
|
||||
|
||||
return {
|
||||
|
||||
@@ -151,7 +151,7 @@ export async function getVideoYTjs(videoId: string): Promise<VideoPlay> {
|
||||
const channel = await innertube.getChannel(video.basic_info.channel_id);
|
||||
authorThumbnails = channel.metadata.avatar as Image[];
|
||||
|
||||
associateAvatar(video.basic_info.channel_id, authorThumbnails);
|
||||
await associateAvatar(video.basic_info.channel_id, authorThumbnails);
|
||||
} else {
|
||||
authorThumbnails = [];
|
||||
}
|
||||
|
||||
@@ -2,24 +2,19 @@ import type { Image } from './api/model';
|
||||
import { localDb } from './dexie';
|
||||
import { getBestThumbnail } from './images';
|
||||
|
||||
const updateDebounce: Record<string, ReturnType<typeof setTimeout>> = {};
|
||||
let isInitial = false;
|
||||
|
||||
export async function associateAvatar(channelId: string, avatars: Image[]) {
|
||||
if (avatars.length === 0) return;
|
||||
|
||||
if ('channelId' in updateDebounce) clearTimeout(updateDebounce[channelId]);
|
||||
|
||||
updateDebounce[channelId] = setTimeout(() => {
|
||||
localDb.channelAvatars.put(
|
||||
{
|
||||
channelId: channelId,
|
||||
avatarUrl: getBestThumbnail(avatars),
|
||||
updated: new Date()
|
||||
},
|
||||
{ channelId: channelId }
|
||||
);
|
||||
}, 100);
|
||||
await localDb.channelAvatars.put(
|
||||
{
|
||||
channelId: channelId,
|
||||
avatarUrl: getBestThumbnail(avatars),
|
||||
updated: new Date()
|
||||
},
|
||||
{ channelId: channelId }
|
||||
);
|
||||
|
||||
if (isInitial) {
|
||||
isInitial = true;
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user