/** * 图片 API */ import { api } from '../client'; /** * 搜索图片 */ export async function search(libraryId, params = {}, options = {}) { const query = new URLSearchParams({ libraryId, ...params }); return api.get(`/image?${query}`, options); } /** * 获取图片总数 */ export async function getCount(libraryId, params = {}) { const query = new URLSearchParams({ libraryId, ...params }); return api.get(`/image/count?${query}`); } /** * 获取统计信息 */ export async function getStats(libraryId) { return api.get(`/image/stats?libraryId=${libraryId}`); } /** * 获取文件夹列表 */ export async function getFolders(libraryId) { return api.get(`/image/folders?libraryId=${libraryId}`); } /** * 获取缓存元数据 */ export async function getCacheMeta(libraryId) { return api.get(`/image/cache-meta?libraryId=${libraryId}`); } /** * 获取缩略图 URL * 使用分片结构,不再需要 size 参数 */ export function getThumbnailUrl(libraryId, filename, version) { const encoded = encodeURIComponent(filename); const base = `/api/image/thumbnail/${libraryId}/${encoded}`; // version=文件 modified_at,编辑保存后变化以穿透浏览器缓存 return version ? `${base}?v=${version}` : base; } /** * 获取原图 URL */ export function getOriginalUrl(libraryId, path) { // 按 '/' 分段编码,避免中文/空格/#/? 等字符导致原图 URL 404(灯箱/新窗口打开失败) const encoded = String(path).split('/').map(encodeURIComponent).join('/'); return `/api/image/original/${libraryId}/${encoded}`; } /** * 在文件管理器中打开 */ export async function openInExplorer(libraryId, path) { return api.post(`/image/${libraryId}/open-file`, { path }); } /** * 更新图片评分(支持批量) */ export async function updateRating(libraryId, paths, rating) { return api.put('/image/rating', { libraryId, paths: Array.isArray(paths) ? paths : [paths], rating }); }