test: fix raw upload assertions
This commit is contained in:
+16
-1
@@ -1084,13 +1084,28 @@ function listFootprints(d, query) {
|
||||
if (!row) throw new Error('附件不存在');
|
||||
withTx(d, () => {
|
||||
const h = hlcNext(d);
|
||||
d.prepare('UPDATE attachment SET remote_url=?, remote_thumb=?, hlc=? WHERE id=?')
|
||||
d.prepare('UPDATE attachment SET remote_url=COALESCE(?, remote_url), remote_thumb=COALESCE(?, remote_thumb), hlc=? WHERE id=?')
|
||||
.run(payload.remote_url ?? null, payload.remote_thumb ?? null, h, row.id);
|
||||
touchOplog(d, 'attachment', row.uuid, 'upsert', h);
|
||||
});
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
case 'attachment_set_thumb': {
|
||||
// 客户端上传原始二进制后回填缩略图(本地元数据,不进 oplog)
|
||||
const row = d.prepare('SELECT * FROM attachment WHERE id=?').get(payload.id);
|
||||
if (!row) throw new Error('附件不存在');
|
||||
const tb = Buffer.from(payload.thumb_b64 || '', 'base64');
|
||||
if (!tb.length) throw new Error('缩略图为空');
|
||||
const rel = path.join('attachments', String(row.owner_id), crypto.randomUUID() + '_thumb.webp');
|
||||
const abs = path.join(DATA_DIR, rel);
|
||||
fs.mkdirSync(path.dirname(abs), { recursive: true });
|
||||
fs.writeFileSync(abs, tb);
|
||||
d.prepare('UPDATE attachment SET thumb_rel_path=? WHERE id=?')
|
||||
.run(rel.split(path.sep).join('/'), row.id);
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
case 'view_list':
|
||||
return { items: d.prepare('SELECT * FROM saved_view WHERE deleted_at IS NULL ORDER BY id').all().map(v => ({
|
||||
...v, filter: JSON.parse(v.filter || '{}'), sort: JSON.parse(v.sort || '{}'), is_default: !!v.is_default
|
||||
|
||||
Reference in New Issue
Block a user