Minor fixes to associateAvatar

This commit is contained in:
WardPearce
2026-03-08 01:48:09 +13:00
parent feb6e19b94
commit 1d52898205
6 changed files with 14 additions and 18 deletions
@@ -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;
+1 -1
View File
@@ -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 {
+1 -1
View File
@@ -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 = [];
}
+8 -13
View File
@@ -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