Implement phase 1

This commit is contained in:
Zerebos
2026-05-23 02:18:36 -04:00
parent 6c39ef538f
commit 8cef79b2b4
40 changed files with 2118 additions and 301 deletions
+30
View File
@@ -0,0 +1,30 @@
import {fetchAuthenticated, getAuthMode, getServerBase} from '$lib/core/auth';
function isAbsoluteUrl(value: string): boolean {
return /^https?:\/\//.test(value);
}
export function resolveImageUrl(path: string | null | undefined): string | undefined {
if (!path) return undefined;
if (isAbsoluteUrl(path)) return path;
const normalizedBase = getServerBase().replace(/\/$/, '');
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
return `${normalizedBase}${normalizedPath}`;
}
export async function loadImageObjectUrl(path: string, signal?: AbortSignal): Promise<string> {
const resolved = resolveImageUrl(path);
if (!resolved) throw new Error('Image URL is missing');
if (getAuthMode() === 'NONE') {
return resolved;
}
const response = await fetchAuthenticated(resolved, {}, signal);
if (!response.ok) {
throw new Error(`Failed to load image: ${response.status}`);
}
return URL.createObjectURL(await response.blob());
}