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 { ...@@ -365,9 +365,9 @@ export class PackagerService extends ConsoleLogger {
}); });
const hashObject = createHash('sha256'); const hashObject = createHash('sha256');
const md5Object = createHash('md5'); const md5Object = createHash('md5');
// let length = 0; let length = 0;
child.stdout.on('data', (chunk) => { child.stdout.on('data', (chunk) => {
// length += chunk.length; length += chunk.length;
// this.log(`Received ${length} bytes of archive ${archiveName}.`); // this.log(`Received ${length} bytes of archive ${archiveName}.`);
hashObject.update(chunk); hashObject.update(chunk);
md5Object.update(chunk); md5Object.update(chunk);
...@@ -397,15 +397,17 @@ export class PackagerService extends ConsoleLogger { ...@@ -397,15 +397,17 @@ export class PackagerService extends ConsoleLogger {
const uploadPromise = this.s3.uploadStream(archiveName, uploadStream, { const uploadPromise = this.s3.uploadStream(archiveName, uploadStream, {
ContentType: 'application/tar+zstd', ContentType: 'application/tar+zstd',
}); });
const [, { object }] = await Promise.all([childPromise, uploadPromise]); const [, uploadRes] = await Promise.all([childPromise, uploadPromise]);
archive.hash = hashObject.digest('hex'); archive.hash = hashObject.digest('hex');
const md5 = md5Object.digest('hex'); const md5 = md5Object.digest('hex');
const md5InS3 = await this.s3.getObjectHash(archiveName); if (length !== uploadRes.object.ContentLength) {
if (md5InS3 !== md5) { throw new Error(`Length mismatch for archive ${archiveName}: local ${length} vs s3 ${uploadRes.object.ContentLength}`);
throw new Error(`MD5 mismatch for archive ${archiveName}: local ${md5} vs s3 ${md5InS3}`); }
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); 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}.`); this.log(`Finished archiving ${archiveName}.`);
return archive; return archive;
} catch (e) { } catch (e) {
......
...@@ -198,9 +198,13 @@ export class S3Service extends ConsoleLogger { ...@@ -198,9 +198,13 @@ export class S3Service extends ConsoleLogger {
}, },
}); });
await upload.done(); await upload.done();
const { const object = await this.s3.send(
Contents: [object], new HeadObjectCommand({
} = await this.listObjects(path); Bucket: this.bucket,
return { object, url: this.getCdnUrl(path) }; 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