fix(ci): read ali-oss head() result through res.headers/meta

head() resolves to { meta, res, status } — raw headers live at
res.headers and x-oss-meta-* values are pre-parsed into meta. The
previous direct res.headers access crashed the post-upload verification
after the first successful put.
This commit is contained in:
go0p
2026-08-18 14:49:44 +08:00
parent 3c7d4bfd41
commit c1476a3337
+5 -3
View File
@@ -60,12 +60,14 @@ const client = new OSS({ accessKeyId, accessKeySecret, bucket, endpoint, secure:
const sha256 = (buffer) => createHash('sha256').update(buffer).digest('hex'); const sha256 = (buffer) => createHash('sha256').update(buffer).digest('hex');
// head() resolves to { meta, res, status }: raw headers live at res.headers
// and x-oss-meta-* values are pre-parsed into meta.
async function headObject(key) { async function headObject(key) {
try { try {
const res = await client.head(key); const result = await client.head(key);
return { return {
size: Number(res.headers['content-length']), size: Number(result.res.headers['content-length']),
sha256: res.headers['x-oss-meta-sha256'] ?? null, sha256: result.meta?.sha256 ?? null,
}; };
} catch (err) { } catch (err) {
if (err && (err.status === 404 || err.code === 'NoSuchKey')) return null; if (err && (err.status === 404 || err.code === 'NoSuchKey')) return null;