107 lines
3.7 KiB
TypeScript
107 lines
3.7 KiB
TypeScript
import type { VMState } from "../index.js";
|
|
import type { FilePreviewStatus, FileScanStatus } from "./file-browser.vm.js";
|
|
|
|
/**
|
|
* File detail view-model (AK-P4a §9). Pure function, i18n keys only.
|
|
* Preview/download URLs point at the auth-proxy route (AD-23).
|
|
*/
|
|
export interface FileLinkedEntity {
|
|
readonly entityType: string;
|
|
readonly entityId: string;
|
|
readonly linkRole: string | null;
|
|
/** Internal route to the target entity (loader-built) or null. */
|
|
readonly href: string | null;
|
|
}
|
|
|
|
export interface FileDetailData {
|
|
readonly id: string;
|
|
readonly displayName: string;
|
|
readonly mimeType: string;
|
|
readonly sizeBytes: number;
|
|
readonly createdAtIso: string;
|
|
readonly tags: readonly string[];
|
|
readonly notes: string | null;
|
|
readonly source: string;
|
|
readonly previewStatus: FilePreviewStatus;
|
|
readonly scanStatus: FileScanStatus;
|
|
/** Proxy URL of the preview (or null). */
|
|
readonly previewUrl: string | null;
|
|
/** Proxy URL of the original for download. */
|
|
readonly downloadUrl: string;
|
|
readonly assignedToUserId: string | null;
|
|
readonly linkedEntities: readonly FileLinkedEntity[];
|
|
/** Plain-text hint key when previewStatus=not_supported/failed. */
|
|
readonly previewFallbackKey: string | null;
|
|
/** Plain-text key when scanStatus=infected (download blocked) or pending. */
|
|
readonly scanNoticeKey: string | null;
|
|
readonly canWrite: boolean;
|
|
readonly canDelete: boolean;
|
|
readonly canAdmin: boolean;
|
|
/** Regenerating the preview only makes sense when it failed. */
|
|
readonly canRegeneratePreview: boolean;
|
|
}
|
|
|
|
export type FileDetailVM = VMState<FileDetailData>;
|
|
|
|
export interface BuildFileDetailVMInput {
|
|
readonly id: string;
|
|
readonly displayName: string;
|
|
readonly mimeType: string;
|
|
readonly sizeBytes: number;
|
|
readonly createdAtIso: string;
|
|
readonly tags: readonly string[];
|
|
readonly notes: string | null;
|
|
readonly source: string;
|
|
readonly previewStatus: FilePreviewStatus;
|
|
readonly scanStatus: FileScanStatus;
|
|
readonly previewUrl: string | null;
|
|
readonly downloadUrl: string;
|
|
readonly assignedToUserId: string | null;
|
|
readonly linkedEntities: readonly FileLinkedEntity[];
|
|
readonly canWrite: boolean;
|
|
readonly canDelete: boolean;
|
|
readonly canAdmin: boolean;
|
|
}
|
|
|
|
function previewFallbackKey(status: FilePreviewStatus): string | null {
|
|
if (status === "not_supported") return "files.detail.preview.notSupported";
|
|
if (status === "failed") return "files.detail.preview.failed";
|
|
if (status === "pending" || status === "generating") return "files.detail.preview.pending";
|
|
return null;
|
|
}
|
|
|
|
function scanNoticeKey(status: FileScanStatus): string | null {
|
|
if (status === "infected") return "files.detail.scan.infected";
|
|
if (status === "pending") return "files.detail.scan.pending";
|
|
return null;
|
|
}
|
|
|
|
export function buildFileDetailVM(input: BuildFileDetailVMInput): FileDetailVM {
|
|
return {
|
|
status: "ready",
|
|
data: {
|
|
id: input.id,
|
|
displayName: input.displayName,
|
|
mimeType: input.mimeType,
|
|
sizeBytes: input.sizeBytes,
|
|
createdAtIso: input.createdAtIso,
|
|
tags: input.tags,
|
|
notes: input.notes,
|
|
source: input.source,
|
|
previewStatus: input.previewStatus,
|
|
scanStatus: input.scanStatus,
|
|
// An infected file never exposes a preview URL (fail-closed).
|
|
previewUrl: input.scanStatus === "infected" ? null : input.previewUrl,
|
|
downloadUrl: input.downloadUrl,
|
|
assignedToUserId: input.assignedToUserId,
|
|
linkedEntities: input.linkedEntities,
|
|
previewFallbackKey: previewFallbackKey(input.previewStatus),
|
|
scanNoticeKey: scanNoticeKey(input.scanStatus),
|
|
canWrite: input.canWrite,
|
|
canDelete: input.canDelete,
|
|
canAdmin: input.canAdmin,
|
|
canRegeneratePreview: input.canWrite && input.previewStatus === "failed",
|
|
},
|
|
};
|
|
}
|