This commit is contained in:
Timothy Jaeryang Baek
2026-08-24 18:06:59 -04:00
parent 98ee2bdfd3
commit fd8cc2ba4a
14 changed files with 117 additions and 18 deletions
+21
View File
@@ -0,0 +1,21 @@
export const normalizeDocumentTargetPage = (page: unknown): number | null => {
if (page === undefined || page === null || page === '') {
return null;
}
const value = Number(page);
if (!Number.isFinite(value)) {
return null;
}
const targetPage = Math.trunc(value);
return targetPage > 0 ? targetPage : null;
};
export const clampDocumentTargetPage = (page: number | null | undefined, pageCount: number) => {
if (!page || pageCount < 1) {
return null;
}
return Math.min(Math.max(1, page), pageCount);
};
+6 -2
View File
@@ -3,6 +3,8 @@ import { v4 as uuidv4 } from 'uuid';
import sha256 from 'js-sha256';
import DOMPurify from 'dompurify';
import { WEBUI_BASE_URL } from '$lib/constants';
import type { FileNavOpenRequest } from '$lib/stores';
import { normalizeDocumentTargetPage } from '$lib/utils/documentPreview';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
@@ -2321,10 +2323,12 @@ export const formatSkillName = (name) => {
*/
export const displayFileHandler = (
path: string,
stores: { showControls: Writable<boolean>; showFileNavPath: Writable<string | null> }
stores: { showControls: Writable<boolean>; showFileNavPath: Writable<FileNavOpenRequest | null> },
options: { page?: unknown } = {}
) => {
if (path) {
stores.showControls.set(true);
stores.showFileNavPath.set(path);
const page = normalizeDocumentTargetPage(options.page);
stores.showFileNavPath.set(page ? { path, page } : path);
}
};