arocapi 5.0.0-beta.6 → 5.0.0-beta.8
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.
- package/README.md +10 -10
- package/dist/app.d.ts +3 -4
- package/dist/app.js +10 -7
- package/dist/app.js.map +1 -1
- package/dist/routes/file.d.ts +2 -2
- package/dist/routes/file.js +25 -72
- package/dist/routes/file.js.map +1 -1
- package/dist/routes/metadata.d.ts +5 -5
- package/dist/routes/metadata.js +22 -61
- package/dist/routes/metadata.js.map +1 -1
- package/dist/storage/backend.d.ts +58 -0
- package/dist/storage/backend.js +2 -0
- package/dist/storage/backend.js.map +1 -0
- package/dist/storage/deliver.d.ts +12 -0
- package/dist/storage/deliver.js +34 -0
- package/dist/storage/deliver.js.map +1 -0
- package/dist/storage/directory/directory.d.ts +6 -0
- package/dist/storage/directory/directory.js +24 -0
- package/dist/storage/directory/directory.js.map +1 -0
- package/dist/storage/entity-meta/entity-meta.d.ts +5 -0
- package/dist/storage/entity-meta/entity-meta.js +14 -0
- package/dist/storage/entity-meta/entity-meta.js.map +1 -0
- package/dist/storage/location.d.ts +20 -0
- package/dist/storage/location.js +40 -0
- package/dist/storage/location.js.map +1 -0
- package/dist/storage/ocfl/ocfl.d.ts +7 -0
- package/dist/storage/ocfl/ocfl.js +79 -0
- package/dist/storage/ocfl/ocfl.js.map +1 -0
- package/dist/storage/ocfl/ocflFs.d.ts +7 -0
- package/dist/storage/ocfl/ocflFs.js +33 -0
- package/dist/storage/ocfl/ocflFs.js.map +1 -0
- package/dist/storage/results.d.ts +7 -0
- package/dist/storage/results.js +22 -0
- package/dist/storage/results.js.map +1 -0
- package/dist/storage/s3/s3.d.ts +10 -0
- package/dist/storage/s3/s3.js +47 -0
- package/dist/storage/s3/s3.js.map +1 -0
- package/dist/utils/headers.d.ts +1 -1
- package/dist/utils/headers.js +10 -1
- package/dist/utils/headers.js.map +1 -1
- package/package.json +27 -7
- package/src/app.ts +32 -24
- package/src/routes/file.ts +23 -99
- package/src/routes/metadata.ts +24 -86
- package/src/storage/backend.ts +75 -0
- package/src/storage/deliver.ts +65 -0
- package/src/storage/directory/directory.ts +39 -0
- package/src/storage/entity-meta/entity-meta.ts +25 -0
- package/src/storage/location.ts +85 -0
- package/src/storage/ocfl/ocfl.ts +129 -0
- package/src/storage/ocfl/ocflFs.ts +67 -0
- package/src/storage/results.ts +32 -0
- package/src/storage/s3/s3.ts +79 -0
- package/src/utils/headers.ts +22 -2
- package/dist/types/fileHandlers.d.ts +0 -37
- package/dist/types/fileHandlers.js +0 -2
- package/dist/types/fileHandlers.js.map +0 -1
- package/src/types/fileHandlers.ts +0 -57
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Entity, File, Prisma } from '../generated/prisma/client.js';
|
|
2
|
+
import type { StorageLocate } from './backend.js';
|
|
3
|
+
export declare const isJsonObject: (value: Prisma.JsonValue | undefined) => value is Prisma.JsonObject;
|
|
4
|
+
export declare const metaValue: (meta: Prisma.JsonValue, key: string) => import("@prisma/client/runtime/client").JsonValue | undefined;
|
|
5
|
+
export declare const metaString: <Meta>(meta: Prisma.JsonValue, id: string, key: Extract<keyof Meta, string>) => string | null;
|
|
6
|
+
export declare const safeKey: (key: string, id: string) => string;
|
|
7
|
+
export declare const inside: (root: string, path: string) => boolean;
|
|
8
|
+
type DefaultKeys<Key> = {
|
|
9
|
+
metadata: (entity: Entity) => Key | null;
|
|
10
|
+
content: (file: File) => Key | null;
|
|
11
|
+
};
|
|
12
|
+
export declare const locator: <Key>(locate: StorageLocate<Key>, defaults: DefaultKeys<Key>, check: (key: Key, id: string) => unknown) => {
|
|
13
|
+
metadata: (entity: Entity) => Promise<Key | null>;
|
|
14
|
+
content: (file: File, entity: Entity) => Promise<Key | null>;
|
|
15
|
+
};
|
|
16
|
+
export declare const keyLocator: <Meta>(locate: StorageLocate, key: Extract<keyof Meta, string>) => {
|
|
17
|
+
metadata: (entity: Entity) => Promise<string | null>;
|
|
18
|
+
content: (file: File, entity: Entity) => Promise<string | null>;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isAbsolute, relative, sep } from 'node:path';
|
|
2
|
+
export const isJsonObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3
|
+
export const metaValue = (meta, key) => (isJsonObject(meta) ? meta[key] : undefined);
|
|
4
|
+
export const metaString = (meta, id, key) => {
|
|
5
|
+
const value = metaValue(meta, key);
|
|
6
|
+
if (value === undefined) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
if (typeof value !== 'string') {
|
|
10
|
+
throw new Error(`${id} has a meta.${key} that is not a string`);
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
};
|
|
14
|
+
export const safeKey = (key, id) => {
|
|
15
|
+
if (isAbsolute(key) || key.split(/[\\/]/).includes('..')) {
|
|
16
|
+
throw new Error(`${id} has an unsafe storage key ${JSON.stringify(key)}`);
|
|
17
|
+
}
|
|
18
|
+
return key;
|
|
19
|
+
};
|
|
20
|
+
export const inside = (root, path) => {
|
|
21
|
+
const rel = relative(root, path);
|
|
22
|
+
return rel !== '' && rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);
|
|
23
|
+
};
|
|
24
|
+
export const locator = (locate, defaults, check) => {
|
|
25
|
+
const checked = (key, id) => {
|
|
26
|
+
if (key !== null) {
|
|
27
|
+
check(key, id);
|
|
28
|
+
}
|
|
29
|
+
return key;
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
metadata: async (entity) => checked(await (locate.metadata ?? defaults.metadata)(entity), entity.id),
|
|
33
|
+
content: async (file, entity) => checked(await (locate.content ?? defaults.content)(file, entity), file.id),
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export const keyLocator = (locate, key) => locator(locate, {
|
|
37
|
+
metadata: (entity) => metaString(entity.meta, entity.id, key),
|
|
38
|
+
content: (file) => metaString(file.meta, file.id, key),
|
|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,MAAM,EACN;IACE,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAO,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC;IACnE,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAO,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC;CAC7D,EACD,OAAO,CACR,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MaybePromise, OcflLocation, StorageBackend, StorageLocate } from '../backend.js';
|
|
2
|
+
export type OcflStorageOptions = {
|
|
3
|
+
root: string;
|
|
4
|
+
objectRoot?: (id: string) => MaybePromise<string>;
|
|
5
|
+
locate?: StorageLocate<OcflLocation>;
|
|
6
|
+
};
|
|
7
|
+
export declare const OcflStorage: ({ root, objectRoot: custom, locate, }: OcflStorageOptions) => Promise<StorageBackend>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { inside, locator, metaString, safeKey } from '../location.js';
|
|
4
|
+
import { nullIfMissing, pathDelivery, withContentType } from '../results.js';
|
|
5
|
+
import { headFile, layoutObjectRoot } from './ocflFs.js';
|
|
6
|
+
const LAYOUTS = new Set([
|
|
7
|
+
'0002-flat-direct-storage-layout',
|
|
8
|
+
'0003-hash-and-id-n-tuple-storage-layout',
|
|
9
|
+
'0004-hashed-n-tuple-storage-layout',
|
|
10
|
+
'000N-path-direct-storage-layout',
|
|
11
|
+
]);
|
|
12
|
+
const METADATA_PATH = 'ro-crate-metadata.json';
|
|
13
|
+
const MARKERS = ['0=ocfl_1.1', '0=ocfl_1.0'];
|
|
14
|
+
const readJson = async (path) => {
|
|
15
|
+
const text = await nullIfMissing(readFile(path, 'utf8'));
|
|
16
|
+
return text === null ? null : JSON.parse(text);
|
|
17
|
+
};
|
|
18
|
+
const readLayoutObjectRoot = async (base) => {
|
|
19
|
+
const layout = await readJson(join(base, 'ocfl_layout.json'));
|
|
20
|
+
const extension = layout?.extension;
|
|
21
|
+
if (typeof extension !== 'string') {
|
|
22
|
+
throw new Error(`${base} has no ocfl_layout.json naming its storage layout; pass objectRoot`);
|
|
23
|
+
}
|
|
24
|
+
if (!LAYOUTS.has(extension)) {
|
|
25
|
+
throw new Error(`${base} uses the storage layout ${extension}, which OcflStorage doesn't implement; pass objectRoot`);
|
|
26
|
+
}
|
|
27
|
+
const config = await readJson(join(base, 'extensions', extension, 'config.json'));
|
|
28
|
+
return layoutObjectRoot(base, extension, config);
|
|
29
|
+
};
|
|
30
|
+
const metaKey = (row, key) => metaString(row.meta, row.id, key);
|
|
31
|
+
const defaultLocations = {
|
|
32
|
+
metadata: (entity) => {
|
|
33
|
+
const object = metaKey(entity, 'ocflObject');
|
|
34
|
+
const path = metaKey(entity, 'ocflPath') ?? METADATA_PATH;
|
|
35
|
+
return object === null ? null : { object, path };
|
|
36
|
+
},
|
|
37
|
+
content: (file) => {
|
|
38
|
+
const object = metaKey(file, 'ocflObject');
|
|
39
|
+
const path = metaKey(file, 'ocflPath');
|
|
40
|
+
return object === null || path === null ? null : { object, path };
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const safeLocation = ({ path }, id) => safeKey(path, id);
|
|
44
|
+
export const OcflStorage = async ({ root, objectRoot: custom, locate = {}, }) => {
|
|
45
|
+
const base = resolve(root);
|
|
46
|
+
const markers = await Promise.all(MARKERS.map((name) => nullIfMissing(stat(join(base, name)))));
|
|
47
|
+
if (!markers.some(Boolean)) {
|
|
48
|
+
throw new Error(`${base} is not an OCFL storage root`);
|
|
49
|
+
}
|
|
50
|
+
const objectRoot = custom ?? (await readLayoutObjectRoot(base));
|
|
51
|
+
const locations = locator(locate, defaultLocations, safeLocation);
|
|
52
|
+
const deliver = async (location, id) => {
|
|
53
|
+
if (location === null) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const objectPath = resolve(base, await objectRoot(location.object));
|
|
57
|
+
if (!inside(base, objectPath)) {
|
|
58
|
+
throw new Error(`${id}: the root of OCFL object ${location.object} is outside the storage root`);
|
|
59
|
+
}
|
|
60
|
+
const file = await headFile(objectPath, location.path);
|
|
61
|
+
if (file === null) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
const path = resolve(objectPath, file.contentPath);
|
|
65
|
+
if (!inside(objectPath, path)) {
|
|
66
|
+
throw new Error(`${id}: OCFL object ${location.object} has a manifest path outside its root`);
|
|
67
|
+
}
|
|
68
|
+
const stats = await stat(path);
|
|
69
|
+
if (!stats.isFile()) {
|
|
70
|
+
throw new Error(`${id}: OCFL object ${location.object} has a manifest path that is not a file`);
|
|
71
|
+
}
|
|
72
|
+
return pathDelivery(path, stats, `"${file.digest}"`);
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
metadata: async (entity) => deliver(await locations.metadata(entity), entity.id),
|
|
76
|
+
content: async (file, entity) => withContentType(await deliver(await locations.content(file, entity), file.id), file.mediaType),
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=ocfl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ocfl.js","sourceRoot":"","sources":["../../../src/storage/ocfl/ocfl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAU1C,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAWzD,MAAM,OAAO,GAAG,IAAI,GAAG,CAA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M,EAAE,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,GAAG,EAAE,iBAAiB,QAAQ,CAAC,MAAM,yCAAyC,CAAC,CAAC;QAClG,CAAC;QAED,OAAO,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IACvD,CAAC,CAAC;IAEF,OAAO;QACL,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC;QAChF,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAC9B,eAAe,CAAC,MAAM,OAAO,CAAC,MAAM,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC;KACjG,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type InventoryFile = {
|
|
2
|
+
digest: string;
|
|
3
|
+
contentPath: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const layoutObjectRoot: (root: string, extension: string, config: object | null) => Promise<(id: string) => string>;
|
|
6
|
+
export declare const headFile: (root: string, logicalPath: string) => Promise<InventoryFile | null>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { dirname, join } from 'node:path';
|
|
2
|
+
import ocfl from '@ocfl/ocfl-fs';
|
|
3
|
+
const { loadStorage, object, storageLayout } = ocfl;
|
|
4
|
+
const HASH_AND_ID = '0003-hash-and-id-n-tuple-storage-layout';
|
|
5
|
+
const encapsulate = (id, digest) => {
|
|
6
|
+
const encoded = Array.from(new TextEncoder().encode(id), (byte) => {
|
|
7
|
+
const char = String.fromCharCode(byte);
|
|
8
|
+
return /[A-Za-z0-9_-]/.test(char) ? char : `%${byte.toString(16).padStart(2, '0')}`;
|
|
9
|
+
}).join('');
|
|
10
|
+
return encoded.length > 100 ? `${encoded.slice(0, 100)}-${digest}` : encoded;
|
|
11
|
+
};
|
|
12
|
+
export const layoutObjectRoot = async (root, extension, config) => {
|
|
13
|
+
const layout = storageLayout(config ? { ...config, extensionName: extension } : extension);
|
|
14
|
+
const digestAlgorithm = layout.get('digestAlgorithm');
|
|
15
|
+
if (digestAlgorithm) {
|
|
16
|
+
await loadStorage({ root });
|
|
17
|
+
}
|
|
18
|
+
if (extension !== HASH_AND_ID) {
|
|
19
|
+
return (id) => layout.map(id);
|
|
20
|
+
}
|
|
21
|
+
const digest = storageLayout({
|
|
22
|
+
extensionName: '0004-hashed-n-tuple-storage-layout',
|
|
23
|
+
digestAlgorithm,
|
|
24
|
+
tupleSize: 0,
|
|
25
|
+
numberOfTuples: 0,
|
|
26
|
+
});
|
|
27
|
+
return (id) => join(dirname(layout.map(id)), encapsulate(id, digest.map(id)));
|
|
28
|
+
};
|
|
29
|
+
export const headFile = async (root, logicalPath) => {
|
|
30
|
+
const inventory = await object({ root }).getInventory();
|
|
31
|
+
return inventory?.getFile(logicalPath) ?? null;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=ocflFs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ocflFs.js","sourceRoot":"","sources":["../../../src/storage/ocfl/ocflFs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,IAAI,MAAM,eAAe,CAAC;AAYjC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,IAAc,CAAC;AAE9D,MAAM,WAAW,GAAG,yCAAyC,CAAC;AAG9D,MAAM,WAAW,GAAG,CAAC,EAAU,EAAE,MAAc,EAAE,EAAE;IACjD,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CA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,OAAO,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACxF,CAAC,CAAC;AAMF,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAAE,IAAY,EAAE,WAAmB,EAAE,EAAE;IAClE,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,YAAY,EAAE,CAAC;IAExD,OAAO,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC;AACjD,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Stats } from 'node:fs';
|
|
2
|
+
import type { PathDelivery } from './backend.js';
|
|
3
|
+
export declare const nullIfMissing: <T>(promise: Promise<T>, missing?: ReadonlySet<string>) => Promise<T | null>;
|
|
4
|
+
export declare const pathDelivery: (path: string, stats: Stats, etag: string) => PathDelivery;
|
|
5
|
+
export declare const withContentType: <Delivery extends object>(delivery: Delivery | null, contentType: string) => (Delivery & {
|
|
6
|
+
contentType: string;
|
|
7
|
+
}) | null;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const FS_MISSING = new Set(['ENOENT', 'ENOTDIR']);
|
|
2
|
+
export const nullIfMissing = async (promise, missing = FS_MISSING) => {
|
|
3
|
+
try {
|
|
4
|
+
return await promise;
|
|
5
|
+
}
|
|
6
|
+
catch (error) {
|
|
7
|
+
const { code, name } = error;
|
|
8
|
+
if (missing.has(String(code)) || missing.has(name)) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
throw error;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export const pathDelivery = (path, stats, etag) => ({
|
|
15
|
+
type: 'path',
|
|
16
|
+
path,
|
|
17
|
+
contentLength: stats.size,
|
|
18
|
+
etag,
|
|
19
|
+
lastModified: stats.mtime,
|
|
20
|
+
});
|
|
21
|
+
export const withContentType = (delivery, contentType) => delivery && { ...delivery, contentType };
|
|
22
|
+
//# sourceMappingURL=results.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.js","sourceRoot":"","sources":["../../src/storage/results.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,GAAwB,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAKvE,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAK,OAAmB,EAAE,OAAO,GAAG,UAAU,EAAqB,EAAE;IACrG,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,KAA8B,CAAC;QACtD,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACnD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,KAAY,EAAE,IAAY,EAAgB,EAAE,CAAC,CAAC;IACvF,IAAI,EAAE,MAAM;IACZ,IAAI;IACJ,aAAa,EAAE,KAAK,CAAC,IAAI;IACzB,IAAI;IACJ,YAAY,EAAE,KAAK,CAAC,KAAK;CAC1B,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,eAAe,GAAG,CAA0B,QAAyB,EAAE,WAAmB,EAAE,EAAE,CACzG,QAAQ,IAAI,EAAE,GAAG,QAAQ,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type S3Client } from '@aws-sdk/client-s3';
|
|
2
|
+
import type { StorageBackend, StorageLocate } from '../backend.js';
|
|
3
|
+
export type S3StorageOptions = {
|
|
4
|
+
client: S3Client;
|
|
5
|
+
bucket: string;
|
|
6
|
+
locate?: StorageLocate;
|
|
7
|
+
delivery?: 'redirect' | 'stream';
|
|
8
|
+
expiresIn?: number;
|
|
9
|
+
};
|
|
10
|
+
export declare const S3Storage: ({ client, bucket, locate, delivery, expiresIn, }: S3StorageOptions) => StorageBackend;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { GetObjectCommand, HeadObjectCommand } from '@aws-sdk/client-s3';
|
|
2
|
+
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
3
|
+
import { keyLocator } from '../location.js';
|
|
4
|
+
import { nullIfMissing, withContentType } from '../results.js';
|
|
5
|
+
const MISSING = new Set(['NoSuchKey', 'NotFound']);
|
|
6
|
+
export const S3Storage = ({ client, bucket, locate = {}, delivery = 'redirect', expiresIn = 300, }) => {
|
|
7
|
+
const keys = keyLocator(locate, 'storageKey');
|
|
8
|
+
const stream = async (key) => {
|
|
9
|
+
if (key === null) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const head = await nullIfMissing(client.send(new HeadObjectCommand({ Bucket: bucket, Key: key })), MISSING);
|
|
13
|
+
if (!head) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
type: 'stream',
|
|
18
|
+
contentLength: Number(head.ContentLength),
|
|
19
|
+
etag: head.ETag,
|
|
20
|
+
lastModified: head.LastModified,
|
|
21
|
+
open: async () => {
|
|
22
|
+
const object = await client.send(new GetObjectCommand({ Bucket: bucket, Key: key, IfMatch: head.ETag }));
|
|
23
|
+
return object.Body;
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
metadata: async (entity) => stream(await keys.metadata(entity)),
|
|
29
|
+
content: async (file, entity, { contentDisposition }) => {
|
|
30
|
+
const Key = await keys.content(file, entity);
|
|
31
|
+
if (delivery === 'stream') {
|
|
32
|
+
return withContentType(await stream(Key), file.mediaType);
|
|
33
|
+
}
|
|
34
|
+
if (Key === null) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const command = new GetObjectCommand({
|
|
38
|
+
Bucket: bucket,
|
|
39
|
+
Key,
|
|
40
|
+
ResponseContentType: file.mediaType,
|
|
41
|
+
ResponseContentDisposition: contentDisposition,
|
|
42
|
+
});
|
|
43
|
+
return { type: 'redirect', url: await getSignedUrl(client, command, { expiresIn }) };
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=s3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3.js","sourceRoot":"","sources":["../../../src/storage/s3/s3.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAiB,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAc/D,MAAM,OAAO,GAAwB,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;AAKxE,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EACxB,MAAM,EACN,MAAM,EACN,MAAM,GAAG,EAAE,EACX,QAAQ,GAAG,UAAU,EACrB,SAAS,GAAG,GAAG,GACE,EAAkB,EAAE;IACrC,MAAM,IAAI,GAAG,UAAU,CAAgB,MAAM,EAAE,YAAY,CAAC,CAAC;IAE7D,MAAM,MAAM,GAAG,KAAK,EAAE,GAAkB,EAAkC,EAAE;QAC1E,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,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AAC;gBACnC,MAAM,EAAE,MAAM;gBACd,GAAG;gBACH,mBAAmB,EAAE,IAAI,CAAC,SAAS;gBACnC,0BAA0B,EAAE,kBAAkB;aAC/C,CAAC,CAAC;YAEH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;QACvF,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/utils/headers.d.ts
CHANGED
package/dist/utils/headers.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
const contentSecurityPolicy = "default-src 'none'; style-src 'unsafe-inline'; sandbox";
|
|
2
|
+
const token = "[!#$%&'*+\\-.^_`|~0-9a-z]+";
|
|
3
|
+
const quotedString = '"(?:[^"\\\\]|\\\\.)*"';
|
|
4
|
+
const mediaType = new RegExp(`^(?:audio|video)/${token}(?:[ \\t]*;[ \\t]*${token}=(?:${token}|${quotedString}))*[ \\t]*$`, 'i');
|
|
5
|
+
const isMedia = (contentType) => mediaType.test(contentType);
|
|
6
|
+
export const setDeliveryHeaders = (reply, metadata) => {
|
|
2
7
|
reply.header('Content-Type', metadata.contentType);
|
|
3
8
|
reply.header('Content-Length', metadata.contentLength.toString());
|
|
4
9
|
if (metadata.etag) {
|
|
@@ -7,5 +12,9 @@ export const setFileHeaders = (reply, metadata) => {
|
|
|
7
12
|
if (metadata.lastModified) {
|
|
8
13
|
reply.header('Last-Modified', metadata.lastModified.toUTCString());
|
|
9
14
|
}
|
|
15
|
+
reply.header('X-Content-Type-Options', 'nosniff');
|
|
16
|
+
if (!isMedia(metadata.contentType)) {
|
|
17
|
+
reply.header('Content-Security-Policy', contentSecurityPolicy);
|
|
18
|
+
}
|
|
10
19
|
};
|
|
11
20
|
//# sourceMappingURL=headers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/utils/headers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/utils/headers.ts"],"names":[],"mappings":"AAGA,MAAM,qBAAqB,GAAG,wDAAwD,CAAC;AAEvF,MAAM,KAAK,GAAG,4BAA4B,CAAC;AAC3C,MAAM,YAAY,GAAG,uBAAuB,CAAC;AAC7C,MAAM,SAAS,GAAG,IAAI,MAAM,CAC1B,oBAAoB,KAAK,qBAAqB,KAAK,OAAO,KAAK,IAAI,YAAY,aAAa,EAC5F,GAAG,CACJ,CAAC;AAKF,MAAM,OAAO,GAAG,CAAC,WAAmB,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAErE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,KAAmB,EACnB,QAA4F,EAC5F,EAAE;IACF,KAAK,CAAC,MAAM,CAAC,cAAc,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IACnD,KAAK,CAAC,MAAM,CAAC,gBAAgB,EAAE,QAAQ,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC;IAClE,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IACD,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;QAC1B,KAAK,CAAC,MAAM,CAAC,eAAe,EAAE,QAAQ,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC;IACrE,CAAC;IAGD,KAAK,CAAC,MAAM,CAAC,wBAAwB,EAAE,SAAS,CAAC,CAAC;IAClD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QACnC,KAAK,CAAC,MAAM,CAAC,yBAAyB,EAAE,qBAAqB,CAAC,CAAC;IACjE,CAAC;AACH,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "arocapi",
|
|
4
|
-
"version": "5.0.0-beta.
|
|
4
|
+
"version": "5.0.0-beta.8",
|
|
5
5
|
"description": "An RO-Crate API",
|
|
6
6
|
"main": "dist/app.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./dist/app.js",
|
|
9
|
-
"./opensearch": "./dist/search/opensearch/opensearch.js",
|
|
10
|
-
"./postgres": "./dist/search/postgres/postgres.js"
|
|
9
|
+
"./search/opensearch": "./dist/search/opensearch/opensearch.js",
|
|
10
|
+
"./search/postgres": "./dist/search/postgres/postgres.js",
|
|
11
|
+
"./storage/directory": "./dist/storage/directory/directory.js",
|
|
12
|
+
"./storage/entity-meta": "./dist/storage/entity-meta/entity-meta.js",
|
|
13
|
+
"./storage/s3": "./dist/storage/s3/s3.js",
|
|
14
|
+
"./storage/ocfl": "./dist/storage/ocfl/ocfl.js"
|
|
11
15
|
},
|
|
12
16
|
"keywords": [
|
|
13
17
|
"rocrate",
|
|
@@ -22,9 +26,12 @@
|
|
|
22
26
|
"zod": "^4.6.7"
|
|
23
27
|
},
|
|
24
28
|
"devDependencies": {
|
|
25
|
-
"@
|
|
29
|
+
"@aws-sdk/client-s3": "^3.1157.0",
|
|
30
|
+
"@aws-sdk/s3-request-presigner": "^3.1157.0",
|
|
31
|
+
"@biomejs/biome": "^2.6.3",
|
|
26
32
|
"@commitlint/cli": "^21.2.4",
|
|
27
33
|
"@commitlint/config-conventional": "^21.2.4",
|
|
34
|
+
"@ocfl/ocfl-fs": "^0.4.0",
|
|
28
35
|
"@opensearch-project/opensearch": "^3.9.0",
|
|
29
36
|
"@prisma/adapter-pg": "^7.10.1",
|
|
30
37
|
"@prisma/client": "^7.10.1",
|
|
@@ -37,10 +44,10 @@
|
|
|
37
44
|
"@vitest/ui": "^5.0.5",
|
|
38
45
|
"concurrently": "^10.0.6",
|
|
39
46
|
"conventional-changelog-conventionalcommits": "^9.3.1",
|
|
40
|
-
"dotenv": "^18.0.
|
|
47
|
+
"dotenv": "^18.0.9",
|
|
41
48
|
"fastify": "^5.12.7",
|
|
42
49
|
"fastify-tsconfig": "^3.0.0",
|
|
43
|
-
"knip": "^6.
|
|
50
|
+
"knip": "^6.43.0",
|
|
44
51
|
"lefthook": "^2.2.2",
|
|
45
52
|
"prisma": "^7.10.1",
|
|
46
53
|
"semantic-release": "^25.0.9",
|
|
@@ -50,6 +57,9 @@
|
|
|
50
57
|
"vitest-mock-extended": "^5.1.1"
|
|
51
58
|
},
|
|
52
59
|
"peerDependencies": {
|
|
60
|
+
"@aws-sdk/client-s3": "^3",
|
|
61
|
+
"@aws-sdk/s3-request-presigner": "^3",
|
|
62
|
+
"@ocfl/ocfl-fs": "^0.4.0",
|
|
53
63
|
"@opensearch-project/opensearch": "^3.9.0",
|
|
54
64
|
"@prisma/client": "^7.10.0",
|
|
55
65
|
"fastify": "^5.12.7"
|
|
@@ -79,6 +89,7 @@
|
|
|
79
89
|
"dev:clean": "rm -rf dist",
|
|
80
90
|
"dbconsole": "docker compose exec db psql -U postgres catalog",
|
|
81
91
|
"load-test-data": "tsx scripts/loadEntities.ts",
|
|
92
|
+
"fixtures:ocfl": "node scripts/buildOcflFixtures.ts",
|
|
82
93
|
"lint:biome": "biome check",
|
|
83
94
|
"lint:types": "tsc --noEmit",
|
|
84
95
|
"lint:examples": "tsc --emitDeclarationOnly && tsc -p website/examples",
|
|
@@ -103,8 +114,17 @@
|
|
|
103
114
|
"registry": "https://registry.npmjs.org/",
|
|
104
115
|
"provenance": true
|
|
105
116
|
},
|
|
106
|
-
"packageManager": "pnpm@12.
|
|
117
|
+
"packageManager": "pnpm@12.15.0",
|
|
107
118
|
"peerDependenciesMeta": {
|
|
119
|
+
"@aws-sdk/client-s3": {
|
|
120
|
+
"optional": true
|
|
121
|
+
},
|
|
122
|
+
"@aws-sdk/s3-request-presigner": {
|
|
123
|
+
"optional": true
|
|
124
|
+
},
|
|
125
|
+
"@ocfl/ocfl-fs": {
|
|
126
|
+
"optional": true
|
|
127
|
+
},
|
|
108
128
|
"@opensearch-project/opensearch": {
|
|
109
129
|
"optional": true
|
|
110
130
|
}
|
package/src/app.ts
CHANGED
|
@@ -10,9 +10,9 @@ import metadata from './routes/metadata.js';
|
|
|
10
10
|
import search from './routes/search.js';
|
|
11
11
|
import type { SearchBackend } from './search/backend.js';
|
|
12
12
|
import type { SearchVisibilityWhere } from './search/visibility.js';
|
|
13
|
+
import type { StorageBackend } from './storage/backend.js';
|
|
13
14
|
import type { AccessFunction } from './types/access.js';
|
|
14
15
|
import type { IsAuthenticated, RequestContext } from './types/context.js';
|
|
15
|
-
import type { FileHandler, RoCrateHandler } from './types/fileHandlers.js';
|
|
16
16
|
import type { EntityTransformer, FileTransformer } from './types/transformers.js';
|
|
17
17
|
import type { EntityVisibilityFilter } from './types/visibility.js';
|
|
18
18
|
import { notFoundHandler } from './utils/errors.js';
|
|
@@ -41,6 +41,24 @@ export type {
|
|
|
41
41
|
export { capabilitiesFromFields } from './search/fields.js';
|
|
42
42
|
export type { SearchVisibilityWhere, VisibilityCondition } from './search/visibility.js';
|
|
43
43
|
export { checkSearchVisibility } from './search/visibility.js';
|
|
44
|
+
export type {
|
|
45
|
+
ContentContext,
|
|
46
|
+
ContentDelivery,
|
|
47
|
+
ContentSource,
|
|
48
|
+
DeliveryHeaders,
|
|
49
|
+
DirectoryStorageMeta,
|
|
50
|
+
JsonDelivery,
|
|
51
|
+
MetadataDelivery,
|
|
52
|
+
MetadataSource,
|
|
53
|
+
OcflLocation,
|
|
54
|
+
OcflStorageMeta,
|
|
55
|
+
PathDelivery,
|
|
56
|
+
RedirectDelivery,
|
|
57
|
+
S3StorageMeta,
|
|
58
|
+
StorageBackend,
|
|
59
|
+
StorageLocate,
|
|
60
|
+
StreamDelivery,
|
|
61
|
+
} from './storage/backend.js';
|
|
44
62
|
export type {
|
|
45
63
|
AuthorisedEntity,
|
|
46
64
|
AuthorisedFile,
|
|
@@ -50,19 +68,6 @@ export type {
|
|
|
50
68
|
} from './transformers/default.js';
|
|
51
69
|
export type { AccessFunction, AccessInfo } from './types/access.js';
|
|
52
70
|
export type { IsAuthenticated, RequestContext } from './types/context.js';
|
|
53
|
-
export type {
|
|
54
|
-
FileHandler,
|
|
55
|
-
FileMetadata,
|
|
56
|
-
FilePathResult,
|
|
57
|
-
FileRedirectResult,
|
|
58
|
-
FileResult,
|
|
59
|
-
FileStreamResult,
|
|
60
|
-
GetFileHandler,
|
|
61
|
-
GetRoCrateHandler,
|
|
62
|
-
HeadFileHandler,
|
|
63
|
-
HeadRoCrateHandler,
|
|
64
|
-
RoCrateHandler,
|
|
65
|
-
} from './types/fileHandlers.js';
|
|
66
71
|
export type { EntityTransformer, FileTransformer } from './types/transformers.js';
|
|
67
72
|
export type { EntityVisibilityFilter, SearchVisibilityFilter } from './types/visibility.js';
|
|
68
73
|
export type { LicenceAccessOptions } from './utils/access.js';
|
|
@@ -107,8 +112,8 @@ export type Options = {
|
|
|
107
112
|
access: AccessFunction;
|
|
108
113
|
entityTransformers?: EntityTransformer[];
|
|
109
114
|
fileTransformers?: FileTransformer[];
|
|
110
|
-
|
|
111
|
-
|
|
115
|
+
/** Where Metadata and Content come from */
|
|
116
|
+
storage: StorageBackend;
|
|
112
117
|
entityVisibilityFilter: EntityVisibilityFilter;
|
|
113
118
|
/** A `SearchVisibilityFilter<typeof fields>` for the search backend's declared fields */
|
|
114
119
|
searchVisibilityFilter: (context: RequestContext) => Promise<SearchVisibilityWhere> | SearchVisibilityWhere;
|
|
@@ -121,8 +126,7 @@ const app: FastifyPluginAsync<Options> = async (fastify, options) => {
|
|
|
121
126
|
access,
|
|
122
127
|
entityTransformers,
|
|
123
128
|
fileTransformers,
|
|
124
|
-
|
|
125
|
-
roCrateHandler,
|
|
129
|
+
storage,
|
|
126
130
|
entityVisibilityFilter,
|
|
127
131
|
searchVisibilityFilter,
|
|
128
132
|
isAuthenticated,
|
|
@@ -154,12 +158,16 @@ const app: FastifyPluginAsync<Options> = async (fastify, options) => {
|
|
|
154
158
|
throw new Error('access is required');
|
|
155
159
|
}
|
|
156
160
|
|
|
157
|
-
if (!
|
|
158
|
-
throw new Error('
|
|
161
|
+
if (!storage) {
|
|
162
|
+
throw new Error('storage is required');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (!storage.metadata) {
|
|
166
|
+
throw new Error('storage.metadata is required');
|
|
159
167
|
}
|
|
160
168
|
|
|
161
|
-
if (!
|
|
162
|
-
throw new Error('
|
|
169
|
+
if (!storage.content) {
|
|
170
|
+
throw new Error('storage.content is required');
|
|
163
171
|
}
|
|
164
172
|
|
|
165
173
|
if (!entityVisibilityFilter) {
|
|
@@ -189,8 +197,8 @@ const app: FastifyPluginAsync<Options> = async (fastify, options) => {
|
|
|
189
197
|
fastify.register(entities, { prisma, access, entityTransformers, entityVisibilityFilter });
|
|
190
198
|
fastify.register(entity, { prisma, access, entityTransformers, entityVisibilityFilter, refusal });
|
|
191
199
|
fastify.register(files, { prisma, access, fileTransformers, entityVisibilityFilter });
|
|
192
|
-
fastify.register(file, { prisma,
|
|
193
|
-
fastify.register(metadata, { prisma,
|
|
200
|
+
fastify.register(file, { prisma, content: storage.content, access, entityVisibilityFilter, refusal });
|
|
201
|
+
fastify.register(metadata, { prisma, metadata: storage.metadata, access, entityVisibilityFilter, refusal });
|
|
194
202
|
fastify.register(search, {
|
|
195
203
|
prisma,
|
|
196
204
|
search: searchBackend,
|