Commit 876dd458 authored by nanahira's avatar nanahira

check hash from remote

parent 9291d82e
Pipeline #5391 passed with stages
in 2 minutes and 29 seconds
......@@ -340,20 +340,24 @@ export class AppService extends ConsoleLogger {
if (archive) {
return archive.hash;
}
return null;
return this.checkHashFromUrl(`${this.packageS3.cdnUrl}/${path}.tar.zst`);
}
async getHashForMigrate(fullPath: string): Promise<string> {
const url = `${this.packageS3.cdnUrl}/${fullPath}`;
this.log(`Migrating hash: ${url} `);
async checkHashFromUrl(url: string) {
const { data } = await axios.get<internal.Readable>(url, { responseType: 'stream' });
//data.pipe(hashObject);
const hash = await new Promise<string>((resolve, reject) => {
return new Promise<string>((resolve, reject) => {
const hashObject = createHash('sha256');
data.on('data', (data) => hashObject.update(data));
data.on('error', reject);
data.on('end', () => resolve(hashObject.digest('hex')));
});
}
async getHashForMigrate(fullPath: string): Promise<string> {
const url = `${this.packageS3.cdnUrl}/${fullPath}`;
this.log(`Migrating hash: ${url} `);
const hash = await this.checkHashFromUrl(url);
this.log(`Migrated hash: ${url} => ${hash}`);
return hash;
}
......
......@@ -16,6 +16,8 @@ import { AppService } from '../app.service';
import { createHash } from 'crypto';
import delay from 'delay';
import { Cache } from '@cityssm/map-expire';
import axios from 'axios';
import internal from 'stream';
export interface FileWithHash {
file: readdirp.EntryInfo;
......@@ -207,11 +209,8 @@ export class PackagerService extends ConsoleLogger {
return hash;
}
hash = await this.appService.lookForExistingArchiveHash(path);
if (hash) {
this.hashCache.set(path, hash, 24 * 60 * 60 * 1000);
return hash;
}
return null;
this.hashCache.set(path, hash, 24 * 60 * 60 * 1000);
return hash;
}
async archive(root: string, archiveTask: ArchiveTask): Promise<Archive> {
......@@ -220,13 +219,10 @@ export class PackagerService extends ConsoleLogger {
await this.waitForLock(archiveTask.path);
const existing = await this.s3.fileExists(archiveName);
if (existing) {
const hash = await this.lookForExistingArchiveHash(archiveTask.path);
if (hash) {
this.log(`Archive ${archiveName} exists, skipping.`);
archive.size = existing.Size;
archive.hash = hash;
return archive;
}
archive.hash = await this.lookForExistingArchiveHash(archiveTask.path);
archive.size = existing.Size;
this.log(`Archive ${archiveName} exists, skipping.`);
return archive;
}
const files = archiveTask.filePaths;
this.log(`Packaging archive ${archiveName} with ${archiveTask.exactFilePaths.length} files.`);
......
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