refactor: cli (#8199)

* refactor(cli): upload asset

* chore: e2e tests
This commit is contained in:
Jason Rasmussen 2024-03-22 14:38:00 -04:00 committed by GitHub
parent db744f500b
commit 5b7417bf64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 341 additions and 410 deletions

View file

@ -1,5 +1,7 @@
import { defaults, getMyUserInfo, isHttpError } from '@immich/sdk';
import { glob } from 'glob';
import { createHash } from 'node:crypto';
import { createReadStream } from 'node:fs';
import { readFile, stat, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import yaml from 'yaml';
@ -100,7 +102,7 @@ export const crawl = async (options: CrawlOptions): Promise<string[]> => {
const { extensions: extensionsWithPeriod, recursive, pathsToCrawl, exclusionPatterns, includeHidden } = options;
const extensions = extensionsWithPeriod.map((extension) => extension.replace('.', ''));
if (!pathsToCrawl) {
if (pathsToCrawl.length === 0) {
return [];
}
@ -149,3 +151,13 @@ export const crawl = async (options: CrawlOptions): Promise<string[]> => {
return [...crawledFiles, ...globbedFiles].sort();
};
export const sha1 = (filepath: string) => {
const hash = createHash('sha1');
return new Promise<string>((resolve, reject) => {
const rs = createReadStream(filepath);
rs.on('error', reject);
rs.on('data', (chunk) => hash.update(chunk));
rs.on('end', () => resolve(hash.digest('hex')));
});
};