@unchainedshop/core-files 4.4.0 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,6 +2,14 @@ import type { ModuleInput } from '@unchainedshop/mongodb';
|
|
|
2
2
|
import { mongodb } from '@unchainedshop/mongodb';
|
|
3
3
|
import { type File } from '../db/MediaObjectsCollection.ts';
|
|
4
4
|
import { type FilesSettingsOptions } from '../files-settings.ts';
|
|
5
|
+
export interface FileQuery {
|
|
6
|
+
fileIds?: string[];
|
|
7
|
+
excludeFileId?: string;
|
|
8
|
+
path?: string;
|
|
9
|
+
paths?: string[];
|
|
10
|
+
meta?: Record<string, any>;
|
|
11
|
+
createdBefore?: Date;
|
|
12
|
+
}
|
|
5
13
|
export declare const configureFilesModule: ({ db, options: filesOptions, }: ModuleInput<FilesSettingsOptions>) => Promise<{
|
|
6
14
|
normalizeUrl: (url: string, params: Record<string, any>) => string;
|
|
7
15
|
findFile: (params: {
|
|
@@ -9,7 +17,7 @@ export declare const configureFilesModule: ({ db, options: filesOptions, }: Modu
|
|
|
9
17
|
} | {
|
|
10
18
|
url: string;
|
|
11
19
|
}, options?: mongodb.FindOptions) => Promise<File | null>;
|
|
12
|
-
findFiles: (
|
|
20
|
+
findFiles: (query: FileQuery, options?: mongodb.FindOptions) => Promise<File[]>;
|
|
13
21
|
deleteMany: (fileIds: string[]) => Promise<number>;
|
|
14
22
|
create: (doc: Omit<File, "_id" | "created"> & Pick<Partial<File>, "_id" | "created">) => Promise<string>;
|
|
15
23
|
update: (fileId: string, doc: Partial<File>) => Promise<string>;
|
|
@@ -3,13 +3,13 @@ import { generateDbFilterById, generateDbObjectId, mongodb } from '@unchainedsho
|
|
|
3
3
|
import { MediaObjectsCollection } from "../db/MediaObjectsCollection.js";
|
|
4
4
|
import { filesSettings } from "../files-settings.js";
|
|
5
5
|
const FILE_EVENTS = ['FILE_CREATE', 'FILE_UPDATE', 'FILE_REMOVE'];
|
|
6
|
-
const { ROOT_URL = 'http://localhost:4010' } = process.env;
|
|
7
6
|
export const configureFilesModule = async ({ db, options: filesOptions = {}, }) => {
|
|
8
7
|
registerEvents(FILE_EVENTS);
|
|
9
8
|
await filesSettings.configureSettings(filesOptions);
|
|
10
9
|
const Files = await MediaObjectsCollection(db);
|
|
11
10
|
return {
|
|
12
11
|
normalizeUrl: (url, params) => {
|
|
12
|
+
const { ROOT_URL = 'http://localhost:4010' } = process.env;
|
|
13
13
|
const transformedURLString = filesSettings.transformUrl(url, params);
|
|
14
14
|
if (URL.canParse(transformedURLString)) {
|
|
15
15
|
const finalURL = new URL(transformedURLString);
|
|
@@ -27,7 +27,28 @@ export const configureFilesModule = async ({ db, options: filesOptions = {}, })
|
|
|
27
27
|
}
|
|
28
28
|
return Files.findOne(generateDbFilterById(params.fileId), options);
|
|
29
29
|
},
|
|
30
|
-
findFiles: async (
|
|
30
|
+
findFiles: async (query, options) => {
|
|
31
|
+
const selector = {};
|
|
32
|
+
if (query.fileIds) {
|
|
33
|
+
selector._id = { $in: query.fileIds };
|
|
34
|
+
}
|
|
35
|
+
if (query.excludeFileId) {
|
|
36
|
+
selector._id = { $ne: query.excludeFileId };
|
|
37
|
+
}
|
|
38
|
+
if (query.path) {
|
|
39
|
+
selector.path = query.path;
|
|
40
|
+
}
|
|
41
|
+
if (query.paths) {
|
|
42
|
+
selector.path = { $in: query.paths };
|
|
43
|
+
}
|
|
44
|
+
if (query.meta) {
|
|
45
|
+
Object.entries(query.meta).forEach(([key, value]) => {
|
|
46
|
+
selector[`meta.${key}`] = value;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (query.createdBefore) {
|
|
50
|
+
selector.created = { $lt: query.createdBefore };
|
|
51
|
+
}
|
|
31
52
|
return Files.find(selector, options).toArray();
|
|
32
53
|
},
|
|
33
54
|
deleteMany: async (fileIds) => {
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-files",
|
|
3
|
-
"
|
|
3
|
+
"description": "File management module for the Unchained Engine",
|
|
4
|
+
"version": "4.6.0",
|
|
4
5
|
"main": "lib/files-index.js",
|
|
5
6
|
"types": "lib/files-index.d.ts",
|
|
6
7
|
"type": "module",
|
|
8
|
+
"sideEffects": false,
|
|
7
9
|
"scripts": {
|
|
8
10
|
"clean": "tsc -b --clean",
|
|
9
11
|
"build": "tsc -b",
|
|
@@ -33,10 +35,10 @@
|
|
|
33
35
|
},
|
|
34
36
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@unchainedshop/events": "^4.
|
|
37
|
-
"@unchainedshop/file-upload": "^4.
|
|
38
|
-
"@unchainedshop/logger": "^4.
|
|
39
|
-
"@unchainedshop/utils": "^4.
|
|
38
|
+
"@unchainedshop/events": "^4.6.0",
|
|
39
|
+
"@unchainedshop/file-upload": "^4.6.0",
|
|
40
|
+
"@unchainedshop/logger": "^4.6.0",
|
|
41
|
+
"@unchainedshop/utils": "^4.6.0"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
44
|
"@types/node": "^25.0.0",
|