mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 21:46:49 +00:00
67c1633155
Two preparations the provider conversion needs, and neither changes behaviour. The ServiceResult envelope, the provider-agnostic asset shapes and pipeAsset move to nest/memories/memories.helpers.ts, which touches no database. The controllers and the provider services can name them without importing each other - the same reason notifications/notification-events.ts exists. What is left in services/memories/helpersService.ts is the DB-backed half (the access checks, the album-link lookups) and it folds with the providers. pipeAsset stays a free function over the Express response on purpose. It is not a StreamableFile candidate: it forwards the upstream's 206 and Content-Range so a <video> can seek (#823), swaps Cache-Control to no-store on an error status, and has to answer differently once headers are already sent. All three controllers take @Res() anyway. The three copies of `path.join(__dirname, '../../../uploads')` become one UPLOADS_ROOT. __dirname moves with the file and none of these would have thrown on a wrong depth - mkdirSync and multer create the wrong tree without a word, and every stored photo lands somewhere nobody serves from. UPLOADS-ROOT-001 pins it. The depth happens to be identical for nest/memories, so nothing moves today; the point is that the next move only has one place to get wrong.
18 lines
791 B
TypeScript
18 lines
791 B
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import path from 'node:path';
|
|
import { UPLOADS_ROOT } from '../../../src/nest/memories/uploads-root';
|
|
|
|
/**
|
|
* The anchor three separate `__dirname` joins used to duplicate. A wrong depth
|
|
* does not throw — multer and mkdirSync would happily create the wrong tree and
|
|
* every stored photo would land somewhere nobody serves from.
|
|
*/
|
|
describe('UPLOADS_ROOT', () => {
|
|
it('UPLOADS-ROOT-001: resolves to <server>/uploads, whatever the process cwd is', () => {
|
|
// tests run from server/, so the repo-relative answer is unambiguous
|
|
expect(UPLOADS_ROOT).toBe(path.resolve(process.cwd(), 'uploads'));
|
|
expect(path.basename(UPLOADS_ROOT)).toBe('uploads');
|
|
expect(path.basename(path.dirname(UPLOADS_ROOT))).toBe('server');
|
|
});
|
|
});
|