Commit 78cd894a authored by nanahira's avatar nanahira

better upload thing

parent f9ce2975
Pipeline #40959 passed with stages
in 9 minutes and 35 seconds
......@@ -365,9 +365,9 @@ export class PackagerService extends ConsoleLogger {
});
const hashObject = createHash('sha256');
const md5Object = createHash('md5');
// let length = 0;
let length = 0;
child.stdout.on('data', (chunk) => {
// length += chunk.length;
length += chunk.length;
// this.log(`Received ${length} bytes of archive ${archiveName}.`);
hashObject.update(chunk);
md5Object.update(chunk);
......@@ -397,15 +397,17 @@ export class PackagerService extends ConsoleLogger {
const uploadPromise = this.s3.uploadStream(archiveName, uploadStream, {
ContentType: 'application/tar+zstd',
});
const [, { object }] = await Promise.all([childPromise, uploadPromise]);
const [, uploadRes] = await Promise.all([childPromise, uploadPromise]);
archive.hash = hashObject.digest('hex');
const md5 = md5Object.digest('hex');
const md5InS3 = await this.s3.getObjectHash(archiveName);
if (md5InS3 !== md5) {
throw new Error(`MD5 mismatch for archive ${archiveName}: local ${md5} vs s3 ${md5InS3}`);
if (length !== uploadRes.object.ContentLength) {
throw new Error(`Length mismatch for archive ${archiveName}: local ${length} vs s3 ${uploadRes.object.ContentLength}`);
}
if (uploadRes.md5 !== md5) {
throw new Error(`MD5 mismatch for archive ${archiveName}: local ${md5} vs s3 ${uploadRes.md5}`);
}
await this.redis.set(`hash:${archive.path}`, archive.hash, 'EX', 60 * 60 * 24);
archive.size = object.Size;
archive.size = length;
this.log(`Finished archiving ${archiveName}.`);
return archive;
} catch (e) {
......
......@@ -198,9 +198,13 @@ export class S3Service extends ConsoleLogger {
},
});
await upload.done();
const {
Contents: [object],
} = await this.listObjects(path);
return { object, url: this.getCdnUrl(path) };
const object = await this.s3.send(
new HeadObjectCommand({
Bucket: this.bucket,
Key: key,
})
);
const md5 = object.ETag ? object.ETag.replace(/"/g, '') : undefined;
return { object, md5, url: this.getCdnUrl(path) };
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment