1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-28 22:51:59 +00:00

fix(server): support special characters in library paths (#9385)

Support special characters in library paths
This commit is contained in:
Sushain Cherivirala 2024-05-13 17:44:21 -04:00 committed by GitHub
parent a05c990718
commit 4e6aeeda4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 13 deletions

View file

@ -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, () => {

View file

@ -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}`;
}