@ -1,8 +1,9 @@
import { getMyUser , init , isHttpError } from '@immich/sdk' ;
import { getMyUser , init , isHttpError } from '@immich/sdk' ;
import { glob } from 'fast-glob' ;
import { convertPathToPattern, glob } from 'fast-glob' ;
import { createHash } from 'node:crypto' ;
import { createHash } from 'node:crypto' ;
import { createReadStream } from 'node:fs' ;
import { createReadStream } from 'node:fs' ;
import { readFile , stat , writeFile } from 'node:fs/promises' ;
import { readFile , stat , writeFile } from 'node:fs/promises' ;
import { platform } from 'node:os' ;
import { join , resolve } from 'node:path' ;
import { join , resolve } from 'node:path' ;
import yaml from 'yaml' ;
import yaml from 'yaml' ;
@ -106,6 +107,11 @@ export interface CrawlOptions {
exclusionPattern? : string ;
exclusionPattern? : string ;
extensions : string [ ] ;
extensions : string [ ] ;
}
}
const convertPathToPatternOnWin = ( path : string ) = > {
return platform ( ) === 'win32' ? convertPathToPattern ( path ) : path ;
} ;
export const crawl = async ( options : CrawlOptions ) : Promise < string [ ] > = > {
export const crawl = async ( options : CrawlOptions ) : Promise < string [ ] > = > {
const { extensions : extensionsWithPeriod , recursive , pathsToCrawl , exclusionPattern , includeHidden } = options ;
const { extensions : extensionsWithPeriod , recursive , pathsToCrawl , exclusionPattern , includeHidden } = options ;
const extensions = extensionsWithPeriod . map ( ( extension ) = > extension . replace ( '.' , '' ) ) ;
const extensions = extensionsWithPeriod . map ( ( extension ) = > extension . replace ( '.' , '' ) ) ;
@ -124,11 +130,11 @@ export const crawl = async (options: CrawlOptions): Promise<string[]> => {
if ( stats . isFile ( ) || stats . isSymbolicLink ( ) ) {
if ( stats . isFile ( ) || stats . isSymbolicLink ( ) ) {
crawledFiles . push ( absolutePath ) ;
crawledFiles . push ( absolutePath ) ;
} else {
} else {
patterns . push ( absolutePath) ;
patterns . push ( convertPathToPatternOnWin( absolutePath) ) ;
}
}
} catch ( error : any ) {
} catch ( error : any ) {
if ( error . code === 'ENOENT' ) {
if ( error . code === 'ENOENT' ) {
patterns . push ( c urrentPath) ;
patterns . push ( c onvertPathToPatternOnWin( c urrentPath) ) ;
} else {
} else {
throw error ;
throw error ;
}
}