High performance self-hosted photo and video management solution.
TypeScript backup-toolfluttergoogle-photosgoogle-photos-alternativejavascriptmobile-appnestjsnodejsphoto-galleryphotosphotos-managementself-hostedsveltesveltekittypescriptvideos
fix(server): support special characters in library paths (#9385)
Sushain Cherivirala4e6aeeda4dbb
diff --git a/server/src/repositories/storage.repository.spec.ts b/server/src/repositories/storage.repository.spec.tsindex 44c81d76a6..e770ce6c1b 100644--- a/server/src/repositories/storage.repository.spec.ts+++ b/server/src/repositories/storage.repository.spec.ts@@ -76,17 +76,6 @@ const tests: Test[] = ['/albums/image3.jpg': true,},},- {- test: 'should support globbing paths',- options: {- pathsToCrawl: ['/photos*'],- },- files: {- '/photos1/image1.jpg': true,- '/photos2/image2.jpg': true,- '/images/image3.jpg': false,- },- },{test: 'should crawl a single path without trailing slash',options: {@@ -179,6 +168,15 @@ const tests: Test[] = [[`/photos/3.jpg`]: false,},},+ {+ test: 'should support special characters in paths',+ options: {+ pathsToCrawl: ['/photos (new)'],+ },+ files: {+ ['/photos (new)/1.jpg']: true,+ },+ },];describe(StorageRepository.name, () => {diff --git a/server/src/repositories/storage.repository.ts b/server/src/repositories/storage.repository.tsindex ae374ac812..0d0be5c062 100644--- a/server/src/repositories/storage.repository.ts+++ b/server/src/repositories/storage.repository.ts@@ -1,7 +1,7 @@import { Inject, Injectable } from '@nestjs/common';import archiver from 'archiver';import chokidar, { WatchOptions } from 'chokidar';-import { glob, globStream } from 'fast-glob';+import { escapePath, glob, globStream } from 'fast-glob';import { constants, createReadStream, existsSync, mkdirSync } from 'node:fs';import fs from 'node:fs/promises';import path from 'node:path';@@ -186,7 +186,8 @@ export class StorageRepository implements IStorageRepository {}private asGlob(pathsToCrawl: string[]): string {- const base = pathsToCrawl.length === 1 ? pathsToCrawl[0] : `{${pathsToCrawl.join(',')}}`;+ const escapedPaths = pathsToCrawl.map((path) => escapePath(path));+ const base = escapedPaths.length === 1 ? escapedPaths[0] : `{${escapedPaths.join(',')}}`;const extensions = `*{${mimeTypes.getSupportedFileExtensions().join(',')}}`;return `${base}/**/${extensions}`;}