fix: address CodeRabbit review comments

- Remove data URL content from error messages (security)
- Replace 'as any' casts with proper type assertions in tests
- Use uploadMediaBatch in WidgetSelectDropdown for single store update
- Localize error strings with i18n (uploadFailed, tempUploadFailed)

Amp-Thread-ID: https://ampcode.com/threads/T-019c0daa-eb18-72eb-bc87-90f09afc3d3a
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
bymyself
2026-01-29 22:59:34 -08:00
parent 07f8a01bc3
commit bc0697baf8
5 changed files with 44 additions and 27 deletions

View File

@@ -26,7 +26,9 @@ describe('uploadService', () => {
})
}
vi.mocked(api.fetchApi).mockResolvedValue(mockResponse as any)
vi.mocked(api.fetchApi).mockResolvedValue(
mockResponse as Partial<Response> as Response
)
const result = await uploadMedia({ source: mockFile })
@@ -46,7 +48,9 @@ describe('uploadService', () => {
})
}
vi.mocked(api.fetchApi).mockResolvedValue(mockResponse as any)
vi.mocked(api.fetchApi).mockResolvedValue(
mockResponse as Partial<Response> as Response
)
const result = await uploadMedia({ source: mockBlob })
@@ -68,7 +72,9 @@ describe('uploadService', () => {
})
}
vi.mocked(api.fetchApi).mockResolvedValue(mockResponse as any)
vi.mocked(api.fetchApi).mockResolvedValue(
mockResponse as Partial<Response> as Response
)
try {
const result = await uploadMedia({ source: dataURL })
@@ -94,7 +100,9 @@ describe('uploadService', () => {
json: vi.fn().mockResolvedValue({ name: 'test.png' })
}
vi.mocked(api.fetchApi).mockResolvedValue(mockResponse as any)
vi.mocked(api.fetchApi).mockResolvedValue(
mockResponse as Partial<Response> as Response
)
await uploadMedia(
{ source: mockFile },
@@ -131,7 +139,9 @@ describe('uploadService', () => {
statusText: 'Internal Server Error'
}
vi.mocked(api.fetchApi).mockResolvedValue(mockResponse as any)
vi.mocked(api.fetchApi).mockResolvedValue(
mockResponse as Partial<Response> as Response
)
const result = await uploadMedia({ source: mockFile })
@@ -157,7 +167,9 @@ describe('uploadService', () => {
json: vi.fn().mockResolvedValue({ name: 'mask.png' })
}
vi.mocked(api.fetchApi).mockResolvedValue(mockResponse as any)
vi.mocked(api.fetchApi).mockResolvedValue(
mockResponse as Partial<Response> as Response
)
const originalRef = {
filename: 'original.png',
@@ -194,8 +206,8 @@ describe('uploadService', () => {
}
vi.mocked(api.fetchApi)
.mockResolvedValueOnce(mockResponse1 as any)
.mockResolvedValueOnce(mockResponse2 as any)
.mockResolvedValueOnce(mockResponse1 as Partial<Response> as Response)
.mockResolvedValueOnce(mockResponse2 as Partial<Response> as Response)
const results = await uploadMediaBatch(
mockFiles.map((source) => ({ source }))

View File

@@ -51,7 +51,7 @@ async function convertToFile(
// dataURL string
if (!isDataURL(source)) {
throw new Error(`Invalid data URL: ${source.substring(0, 50)}...`)
throw new Error('Invalid data URL')
}
try {