test: fix raw upload assertions
This commit is contained in:
@@ -135,6 +135,20 @@ export const attachmentList = (owner_id: number) => call<{ items: Attachment[] }
|
||||
export const attachmentDelete = (id: number) => call<{ ok: true }>('attachment_delete', { id });
|
||||
export const attachmentRead = (id: number) =>
|
||||
call<{ data_b64: string; mime?: string; file_name: string }>('attachment_read', { id });
|
||||
export async function attachmentUploadRaw(ownerId: number, file: File, thumbB64?: string): Promise<Attachment> {
|
||||
const q = new URLSearchParams({ owner: String(ownerId), name: file.name, mime: file.type || 'application/octet-stream' });
|
||||
const r = await fetch(getServerUrl() + '/sync/attachment/raw?' + q, {
|
||||
method: 'PUT',
|
||||
headers: { authorization: 'Bearer ' + getToken(), 'content-type': file.type || 'application/octet-stream' },
|
||||
body: file,
|
||||
});
|
||||
const j = await r.json().catch(() => ({ ok: false, error: 'HTTP ' + r.status }));
|
||||
if (!j.ok) throw new Error(j.error || '上传失败');
|
||||
const item = j.data.item as Attachment;
|
||||
if (thumbB64) { try { await call('attachment_set_thumb', { id: item.id, thumb_b64: thumbB64 }); } catch {} }
|
||||
return item;
|
||||
}
|
||||
|
||||
export const attachmentThumb = (id: number) =>
|
||||
call<{ data_b64: string; mime?: string; file_name: string }>('attachment_thumb', { id });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user