Move insecureRequestImageHandler to images

This commit is contained in:
WardPearce
2026-03-02 18:05:56 +13:00
parent c16be19c13
commit f947566e37
7 changed files with 27 additions and 28 deletions
@@ -1,12 +1,12 @@
<script lang="ts">
import { resolve } from '$app/paths';
import { getBestThumbnail, proxyGoogleImage } from '$lib/images';
import { getBestThumbnail, insecureRequestImageHandler, proxyGoogleImage } from '$lib/images';
import { cleanNumber } from '$lib/numbers';
import { onMount } from 'svelte';
import { _ } from '$lib/i18n';
import { get } from 'svelte/store';
import type { Channel } from '$lib/api/model';
import { insecureRequestImageHandler, truncate } from '$lib/misc';
import { truncate } from '$lib/misc';
import { interfaceLowBandwidthMode } from '$lib/store';
interface Props {
@@ -1,12 +1,12 @@
<script lang="ts">
import { getBestThumbnail } from '$lib/images';
import { getBestThumbnail, insecureRequestImageHandler } from '$lib/images';
import { resolve } from '$app/paths';
import { letterCase } from '$lib/letterCasing';
import { onMount } from 'svelte';
import { _ } from '$lib/i18n';
import { get } from 'svelte/store';
import type { Playlist, PlaylistPage } from '$lib/api/model';
import { insecureRequestImageHandler, truncate } from '$lib/misc';
import { truncate } from '$lib/misc';
import { interfaceLowBandwidthMode } from '$lib/store';
interface Props {
@@ -1,6 +1,6 @@
<script lang="ts">
import { resolve } from '$app/paths';
import { getBestThumbnail } from '$lib/images';
import { getBestThumbnail, insecureRequestImageHandler } from '$lib/images';
import { letterCase } from '$lib/letterCasing';
import { cleanNumber, videoLength } from '$lib/numbers';
import { onDestroy, onMount } from 'svelte';
@@ -14,7 +14,7 @@
VideoBase,
VideoWatchHistory
} from '$lib/api/model';
import { createVideoUrl, insecureRequestImageHandler } from '$lib/misc';
import { createVideoUrl } from '$lib/misc';
import type { PlayerEvents } from '$lib/player';
import {
deArrowEnabledStore,
@@ -2,12 +2,12 @@
import { resolve } from '$app/paths';
import { getComments } from '$lib/api';
import { type Comment, type Comments } from '$lib/api/model';
import { getBestThumbnail, proxyGoogleImage } from '$lib/images';
import { getBestThumbnail, insecureRequestImageHandler, proxyGoogleImage } from '$lib/images';
import { numberWithCommas } from '$lib/numbers';
import { interfaceLowBandwidthMode } from '$lib/store';
import { onMount } from 'svelte';
import CommentSelf from './Comment.svelte';
import { insecureRequestImageHandler, truncate } from '$lib/misc';
import { truncate } from '$lib/misc';
import { _ } from '$lib/i18n';
import { extractActualLink } from '$lib/description';
+18 -1
View File
@@ -1,6 +1,6 @@
import { get } from 'svelte/store';
import type { Image } from './api/model';
import { invidiousInstanceStore } from './store';
import { interfaceAllowInsecureRequests, invidiousInstanceStore } from './store';
import { isYTBackend } from './misc';
export class ImageCache {
@@ -27,6 +27,23 @@ export class ImageCache {
}
}
export async function insecureRequestImageHandler(source: string): Promise<HTMLImageElement> {
const img = new Image();
if (get(interfaceAllowInsecureRequests)) {
const imgResp = await fetch(source);
if (!imgResp.ok) {
img.src = '';
return img;
}
img.src = URL.createObjectURL(await imgResp.blob());
} else {
img.src = source;
}
return img;
}
export function getBestThumbnail(
images: Image[] | null,
maxWidthDimension: number = 480,
-18
View File
@@ -10,7 +10,6 @@ import {
channelCacheStore,
feedCacheStore,
invidiousInstanceStore,
interfaceAllowInsecureRequests,
interfaceAndroidUseNativeShare,
isAndroidTvStore,
playlistCacheStore,
@@ -131,23 +130,6 @@ export function ensureNoTrailingSlash(url: any): string {
return url.endsWith('/') ? url.slice(0, -1) : url;
}
export async function insecureRequestImageHandler(source: string): Promise<HTMLImageElement> {
const img = new Image();
if (get(interfaceAllowInsecureRequests)) {
const imgResp = await fetch(source);
if (!imgResp.ok) {
img.src = '';
return img;
}
img.src = URL.createObjectURL(await imgResp.blob());
} else {
img.src = source;
}
return img;
}
export type feedItem =
| VideoBase
| Video
File diff suppressed because one or more lines are too long