Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions server/src/repositories/storage.repository.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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, () => {
Expand Down
5 changes: 3 additions & 2 deletions server/src/repositories/storage.repository.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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(',')}}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code feels a bit redundant since Array.join should work fine on a singleton array. I just left it as is but can tweak.

const extensions = `*{${mimeTypes.getSupportedFileExtensions().join(',')}}`;
return `${base}/**/${extensions}`;
}
Expand Down
Loading