提交 fc4da309 编写于 作者: J Joao Moreno

compute sha256 hash of published assets

上级 cf0d02a2
......@@ -7,6 +7,7 @@
import * as fs from 'fs';
import { execSync } from 'child_process';
import { Readable } from 'stream';
import * as crypto from 'crypto';
import * as azure from 'azure-storage';
import * as mime from 'mime';
......@@ -18,10 +19,9 @@ if (process.argv.length < 6) {
process.exit(-1);
}
function sha1hash(file: string): Promise<string> {
function hashStream(hashName: string, stream: Readable): Promise<string> {
return new Promise<string>((c, e) => {
const shasum = crypto.createHash('sha1');
const stream = fs.createReadStream(file);
const shasum = crypto.createHash(hashName);
stream
.on('data', shasum.update.bind(shasum))
......@@ -67,6 +67,7 @@ interface Asset {
url: string;
mooncakeUrl: string;
hash: string;
sha256hash: string;
}
function createOrUpdate(commit: string, quality: string, platform: string, type: string, release: NewDocument, asset: Asset, isUpdate: boolean): Promise<void> {
......@@ -162,8 +163,11 @@ async function publish(commit: string, quality: string, platform: string, type:
console.log('Is Released:', isReleased);
console.log('File:', file);
const hash = await sha1hash(file);
console.log('Hash:', hash);
const stream = fs.createReadStream(file);
const [sha1hash, sha256hash] = await Promise.all([hashStream('sha1', stream), hashStream('sha256', stream)]);
console.log('SHA1:', sha1hash);
console.log('SHA256:', sha1hash);
const blobName = commit + '/' + name;
const storageAccount = process.env['AZURE_STORAGE_ACCOUNT_2'];
......@@ -207,7 +211,8 @@ async function publish(commit: string, quality: string, platform: string, type:
type: type,
url: `${process.env['AZURE_CDN_URL']}/${quality}/${blobName}`,
mooncakeUrl: `${process.env['MOONCAKE_CDN_URL']}/${quality}/${blobName}`,
hash: hash
hash: sha1hash,
sha256hash
};
const release = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册