feat(edit): 编辑上报细节优化

This commit is contained in:
2026-10-06 18:30:05 +08:00
parent e20cd7547f
commit 79b310efe7
92 changed files with 2764 additions and 368 deletions
+18 -3
View File
@@ -1,3 +1,4 @@
const productId = '733d0d73-3d39-4a98-ac0a-5c0e521d8998';
import { createHash } from 'node:crypto';
import { GetObjectCommand, HeadObjectCommand } from '@aws-sdk/client-s3';
import {
@@ -166,7 +167,7 @@ describe('商品图片上传策略', () => {
it('创建商品图片上传意图时持久化用途并签发独立对象路径', async () => {
const query = vi.fn(async (_sql: string, _params?: unknown[]) => ({
rows: [],
rows: [{ id: productId }],
}));
const run = vi.fn(
async (
@@ -193,13 +194,15 @@ describe('商品图片上传策略', () => {
'key',
{
purpose: 'product_image',
product_id: productId,
filename: 'sku.png',
content_type: 'image/png',
byte_size: 1024,
checksum_sha256: 'a'.repeat(64),
},
);
const args = query.mock.calls[0]?.[1] as unknown[];
const args = query.mock.calls.find(([sql]) => sql.includes('INSERT INTO atlas.media_upload_intents'))?.[1] as unknown[];
expect(args[10]).toBe(productId);
expect(args[1]).toBe('product_image');
expect(args[3]).toContain('/product-images/');
const body = result.body as { data: { upload: { url: string } } };
@@ -217,6 +220,7 @@ describe('商品图片上传策略', () => {
createMediaUploadIntentRequestSchema.safeParse({
...request,
purpose: 'product_image',
product_id: productId,
}).success,
).toBe(true);
expect(
@@ -229,11 +233,20 @@ describe('商品图片上传策略', () => {
createMediaUploadIntentRequestSchema.safeParse({
...request,
purpose: 'product_image',
product_id: productId,
byte_size: 21 * 1024 * 1024,
}).success,
).toBe(false);
});
it('商品上传和网络导入必须绑定商品,水印仍无需商品', () => {
const request = { filename: 'image.png', content_type: 'image/png', byte_size: 1024, checksum_sha256: 'a'.repeat(64) };
expect(createMediaUploadIntentRequestSchema.safeParse({ ...request, purpose: 'product_image' }).success).toBe(false);
expect(createMediaUploadIntentRequestSchema.safeParse({ ...request, purpose: 'watermark_image' }).success).toBe(true);
expect(createMediaUploadIntentRequestSchema.safeParse({ ...request, purpose: 'watermark_image', product_id: productId }).success).toBe(false);
expect(importProductImageRequestSchema.safeParse({ url: 'https://example.test/image.png' }).success).toBe(false);
});
it('商品图校验接受 9000px,水印图仍拒绝超过 8192px', async () => {
const bytes = png(9000, 9000);
const service = serviceWithObject(bytes);
@@ -257,6 +270,7 @@ describe('商品图片上传策略', () => {
const query = vi.fn(async (sql: string) => {
expect(sql).toContain("i.purpose = 'product_image'");
expect(sql).toContain("i.status = 'ready'");
expect(sql).toContain('i.product_id = $1');
return {
rows: [
{
@@ -295,7 +309,7 @@ describe('商品图片上传策略', () => {
objectStorageSecretKey: 'test',
} as ConstructorParameters<typeof MediaService>[2],
);
const uploads = await service.productUploads('workspace-id');
const uploads = await service.productUploads('workspace-id', productId);
expect(uploads).toHaveLength(1);
expect(uploads[0]).toMatchObject({
id: '7c910684-7070-4f36-8a7b-b10bd91acd79',
@@ -308,6 +322,7 @@ describe('商品图片上传策略', () => {
expect(
importProductImageRequestSchema.safeParse({
url: 'https://example.com/image.jpg',
product_id: productId,
}).success,
).toBe(true);
expect(