feat: Implement basic general folder support (#2051)

- Related: #1748
This commit is contained in:
Dermot Duffy
2025-05-21 19:59:21 -07:00
committed by GitHub
parent 2eb0d9e35e
commit c6a4c8aea2
350 changed files with 12837 additions and 4509 deletions
+67
View File
@@ -0,0 +1,67 @@
import { describe, expect, it } from 'vitest';
import { transformPathURLToPathArray } from '../../../src/config/schema/folders';
import { NonEmptyTuple } from 'type-fest';
describe('transformURLToMediaSourceRoot', () => {
const prefixes: NonEmptyTuple<string>[] = [
['http://card.camera/' as const],
['/' as const],
['' as const],
];
describe('should return the media source root when given a root URL', () => {
it.each(prefixes)('with prefix %s', (urlPrefix: string) => {
const url = `${urlPrefix}media-browser/browser`;
const result = transformPathURLToPathArray(url);
expect(result).toEqual([{ id: 'media-source://' }]);
});
});
describe('should return the media source root when given a valid URL', () => {
it.each(prefixes)('with prefix %s', (urlPrefix: string) => {
const url = `${urlPrefix}media-browser/browser/app%2Cmedia-source%3A%2F%2Fcamera`;
const result = transformPathURLToPathArray(url);
expect(result).toEqual([
{ id: 'media-source://' },
{ id: 'media-source://camera' },
]);
});
});
describe('should return the decoded frigate URL', () => {
it.each(prefixes)('with prefix %s', (urlPrefix: string) => {
const url =
`${urlPrefix}media-browser/browser/app%2Cmedia-source%3A%2F%2F` +
'frigate/image%2Cmedia-source%3A%2F%2Ffrigate%2Ffrigate%2F' +
'event-search%2Fsnapshots%2F%2F%2F%2F%2F%2F/image%2C' +
'media-source%3A%2F%2Ffrigate%2Ffrigate%2Fevent-search' +
'%2Fsnapshots%2F.this_month%2F1746082800%2F%2F%2F%2F';
const result = transformPathURLToPathArray(url);
expect(result).toEqual([
{ id: 'media-source://' },
{ id: 'media-source://frigate' },
{ id: 'media-source://frigate/frigate/event-search/snapshots//////' },
{
id: 'media-source://frigate/frigate/event-search/snapshots/.this_month/1746082800////',
},
]);
});
});
describe('should return the root for unknown URLs', () => {
it.each(prefixes)('with prefix %s', (urlPrefix: string) => {
const url = `${urlPrefix}something-completely-different`;
const result = transformPathURLToPathArray(url);
expect(result).toEqual([{ id: 'media-source://' }]);
});
});
describe('should throw error for non-media source path component', () => {
it.each(prefixes)('with prefix %s', (urlPrefix: string) => {
const url = `${urlPrefix}media-browser/browser,does-not-start-with-media-source`;
expect(() => transformPathURLToPathArray(url)).toThrowError(
/Could not parse valid media source URL/,
);
});
});
});