feat(worker): sharp pipeline with orientation, variants, exif strip

Task 20: services/worker package (@photo/worker, commonjs) with jest
unit/e2e configs mirroring api conventions (root .env via test/load-env.ts,
moduleNameMapper to @photo/contracts/db-cn/storage TS sources, maxWorkers 1,
test/reset.ts = MySQL TRUNCATE + MinIO photo-live/dev prefix wipe) and the
sharp processing pipeline runPipeline(): metadata whitelist gate
(jpeg/png/webp/avif/heif/tiff, else PipelineError UNSUPPORTED_TYPE),
decode failures mapped to PipelineError DECODE_FAILED, no-arg .rotate()
auto-orientation (EXIF 5-8 swaps stored width/height), thumb <=480w q75
and browse <=1920 q82 JPEG variants with withoutEnlargement, and no
withMetadata so outputs carry no EXIF/GPS at all. sharp 0.35 prebuilt
loads script-free under pnpm 10; its win32 libvips lacks a HEVC encoder,
so the HEVC-HEIF unit case self-skips with a console note (G2 verifies
with real iPhone samples) while the AV1-HEIF case covers the same
libheif decode path / 'heif' format bucket.

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-17 23:16:20 +08:00
parent f5f1855b58
commit 64a2cec788
10 changed files with 820 additions and 6 deletions
+26
View File
@@ -0,0 +1,26 @@
// services/worker/jest.config.cjs —— 单测(src/*.spec.ts;Task 20 pipeline 单测)。
// 镜像 services/api/jest.config.ts 的约定(CJS 包直接用 .cjs,无需 ts-node):
// · maxWorkers 1:单进程串行(e2e 配置继承后共享同一 MySQL/Redis/MinIO,
// spec 间以 test/reset.ts TRUNCATE + 前缀清理隔离,并行会互相清掉对方数据);
// · setupFiles 经 test/load-env.ts 载入仓库根 .env(全仓库唯一 env 文件);
// · @photo/contracts(ESM)/@photo/db-cn/@photo/storage(CJS)经 moduleNameMapper
// 直指 TS 源码,ts-jest 以 CJS 编译,无需先 build 依赖包 dist;
// · contracts 源码 NodeNext 风格 .js 后缀导入 → 映射回 .ts。
/** @type {import('jest').Config} */
module.exports = {
maxWorkers: 1,
testEnvironment: 'node',
rootDir: '.',
setupFiles: ['./test/load-env.ts'],
transform: {
'^.+\\.tsx?$': ['ts-jest', { tsconfig: 'tsconfig.json' }],
},
moduleNameMapper: {
'^@photo/contracts$': '<rootDir>/../../packages/contracts/src/index.ts',
'^@photo/db-cn$': '<rootDir>/../../packages/db-cn/src/index.ts',
'^@photo/storage$': '<rootDir>/../../packages/storage/src/index.ts',
'^(\\.{1,2}/.*)\\.js$': '$1',
},
testMatch: ['<rootDir>/src/**/*.spec.ts', '<rootDir>/test/**/*.spec.ts'],
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
};