import assert from 'node:assert/strict'; import test from 'node:test'; import { buildPublicImagePaths, buildImgproxyDisplayUrl, formatImageDateFolder, isPublicImageStorageKey, } from './user-image-url.mjs'; test('buildPublicImagePaths uses date folder under user images namespace', () => { const paths = buildPublicImagePaths({ userId: 'user-1', assetId: 'asset-1', mimeType: 'image/png', originalFilename: '封面.png', date: new Date('2026-06-29T10:00:00+08:00'), }); assert.equal(paths.dateFolder, '2026-06-29'); assert.equal( paths.storageKey, 'users/user-1/images/2026-06-29/封面.png', ); assert.equal( paths.workspaceRelativePath, 'public/images/2026-06-29/封面.png', ); }); test('buildImgproxyDisplayUrl falls back to unsafe local path without signer', () => { const url = buildImgproxyDisplayUrl('users/u1/images/2026-06-29/a.jpg', { baseUrl: 'http://localhost:20081', signer: null, }); assert.match(url, /^http:\/\/localhost:20081\/unsafe\//); assert.match(url, /plain\/local:\/\/\/users\/u1\/images\/2026-06-29\/a\.jpg@jpg$/); }); test('isPublicImageStorageKey detects dated image storage keys', () => { assert.equal(isPublicImageStorageKey('users/u1/images/2026-06-29/a.jpg'), true); assert.equal(isPublicImageStorageKey('users/u1/public/.tmp-images/a.jpg'), false); }); test('formatImageDateFolder uses local calendar date', () => { assert.equal(formatImageDateFolder(new Date('2026-01-02T01:00:00+08:00')), '2026-01-02'); });