Files
punimtag/viewer-frontend/lib/photo-utils.ts
T
ilia ffddeca268
CI / skip-ci-check (pull_request) Successful in 6s
CI / docker-ci (pull_request) Successful in 7s
CI / secret-scan (pull_request) Successful in 11s
fix: address open triage issues (#21,#26,#45,#46,#47,#30-33)
- #45: re-read local folder when recursive checkbox toggles
- #47: clear Identify crop spinner when image is already cached
- #46: search selected people by person_ids; AND for "First Last"
- #21: enqueue network import without blocking API walk
- #26: serve resized grid thumbnails for photos
- #30/#31/#33: re-enable small-face filters in auto-match
2026-07-09 14:42:08 -04:00

73 lines
2.1 KiB
TypeScript

import { Photo } from '@prisma/client';
/**
* Determines if a path is a URL (http/https) or a file system path
*/
export function isUrl(path: string): boolean {
return path.startsWith('http://') || path.startsWith('https://');
}
/**
* Check if photo is a video
*/
export function isVideo(photo: Photo): boolean {
// Handle both camelCase (Prisma client) and snake_case (direct DB access)
return (photo as any).mediaType === 'video' || (photo as any).media_type === 'video';
}
/**
* Gets the appropriate image source URL
* - URLs (SharePoint, CDN, etc.) → use directly
* - File system paths → use API proxy
* - Videos → use thumbnail endpoint (for grid display)
*/
export function getImageSrc(photo: Photo, options?: { watermark?: boolean; thumbnail?: boolean }): string {
// Grid thumbnails: resize on server (images) or video poster (#26)
if (options?.thumbnail) {
const params = new URLSearchParams();
params.set('thumbnail', 'true');
if (options.watermark) {
params.set('watermark', 'true');
}
return `/api/photos/${photo.id}/image?${params.toString()}`;
}
if (isUrl(photo.path)) {
if (typeof window !== 'undefined' && process.env.NODE_ENV === 'development') {
console.log(`✅ Photo ${photo.id}: Using DIRECT access for URL:`, photo.path);
}
return photo.path;
}
const params = new URLSearchParams();
if (options?.watermark) {
params.set('watermark', 'true');
}
const query = params.toString();
if (typeof window !== 'undefined' && process.env.NODE_ENV === 'development') {
console.log(`📁 Photo ${photo.id}: Using API PROXY for file path:`, photo.path);
}
return `/api/photos/${photo.id}/image${query ? `?${query}` : ''}`;
}
/**
* Gets the appropriate video source URL
*/
export function getVideoSrc(photo: Photo): string {
if (isUrl(photo.path)) {
return photo.path;
}
return `/api/photos/${photo.id}/image`;
}
/**
* Browser-safe transcoded MP4 URL (after prepare + status=ready).
*/
export function getWebPlaybackStreamUrl(photo: Photo): string {
return `/api/photos/${photo.id}/web-playback`;
}