@opencloudcms/assets 0.0.0-stage → 0.1.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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -2
  3. package/dist/constants.d.ts +10 -0
  4. package/dist/constants.js +10 -0
  5. package/dist/constants.js.map +1 -0
  6. package/dist/index.d.ts +19 -0
  7. package/dist/index.js +53 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/nest/assets.controller.d.ts +113 -0
  10. package/dist/nest/assets.controller.js +298 -0
  11. package/dist/nest/assets.controller.js.map +1 -0
  12. package/dist/nest/assets.module.d.ts +16 -0
  13. package/dist/nest/assets.module.js +69 -0
  14. package/dist/nest/assets.module.js.map +1 -0
  15. package/dist/nest/assets.service.d.ts +184 -0
  16. package/dist/nest/assets.service.js +569 -0
  17. package/dist/nest/assets.service.js.map +1 -0
  18. package/dist/nest/folders.service.d.ts +40 -0
  19. package/dist/nest/folders.service.js +205 -0
  20. package/dist/nest/folders.service.js.map +1 -0
  21. package/dist/nest/local-static.middleware.d.ts +6 -0
  22. package/dist/nest/local-static.middleware.js +57 -0
  23. package/dist/nest/local-static.middleware.js.map +1 -0
  24. package/dist/nest/signed-link.d.ts +11 -0
  25. package/dist/nest/signed-link.js +42 -0
  26. package/dist/nest/signed-link.js.map +1 -0
  27. package/dist/pipeline/image-pipeline.d.ts +42 -0
  28. package/dist/pipeline/image-pipeline.js +130 -0
  29. package/dist/pipeline/image-pipeline.js.map +1 -0
  30. package/dist/provider/create-provider.d.ts +4 -0
  31. package/dist/provider/create-provider.js +32 -0
  32. package/dist/provider/create-provider.js.map +1 -0
  33. package/dist/provider/gcs.provider.d.ts +25 -0
  34. package/dist/provider/gcs.provider.js +46 -0
  35. package/dist/provider/gcs.provider.js.map +1 -0
  36. package/dist/provider/local.provider.d.ts +8 -0
  37. package/dist/provider/local.provider.js +75 -0
  38. package/dist/provider/local.provider.js.map +1 -0
  39. package/dist/provider/s3.provider.d.ts +11 -0
  40. package/dist/provider/s3.provider.js +44 -0
  41. package/dist/provider/s3.provider.js.map +1 -0
  42. package/dist/provider/storage-provider.d.ts +19 -0
  43. package/dist/provider/storage-provider.js +8 -0
  44. package/dist/provider/storage-provider.js.map +1 -0
  45. package/dist/seo/missing-alt.d.ts +4 -0
  46. package/dist/seo/missing-alt.js +11 -0
  47. package/dist/seo/missing-alt.js.map +1 -0
  48. package/dist/seo/slug.d.ts +4 -0
  49. package/dist/seo/slug.js +23 -0
  50. package/dist/seo/slug.js.map +1 -0
  51. package/dist/sniff.d.ts +18 -0
  52. package/dist/sniff.js +130 -0
  53. package/dist/sniff.js.map +1 -0
  54. package/dist/types.d.ts +54 -0
  55. package/dist/types.js +3 -0
  56. package/dist/types.js.map +1 -0
  57. package/package.json +69 -3
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createGcsProvider = createGcsProvider;
4
+ function loadStorage() {
5
+ let sdk;
6
+ try {
7
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
8
+ sdk = require('@google-cloud/storage');
9
+ }
10
+ catch (err) {
11
+ throw new Error('Provider "gcs" requires optional peer @google-cloud/storage', { cause: err });
12
+ }
13
+ return new sdk.Storage();
14
+ }
15
+ function createGcsProvider(cfg, deps) {
16
+ let storage;
17
+ const open = (name) => (storage ??= loadStorage()).bucket(name);
18
+ const bucket = deps?.bucket ?? open(cfg.bucket);
19
+ // Private objects go to `privateBucket` when configured, otherwise they share the main bucket.
20
+ const privateBucket = cfg.privateBucket ? (deps?.privateBucket ?? open(cfg.privateBucket)) : bucket;
21
+ const bucketFor = (visibility = 'public') => (visibility === 'private' ? privateBucket : bucket);
22
+ const baseUrl = (cfg.publicBaseUrl ?? `https://storage.googleapis.com/${cfg.bucket}`).replace(/\/+$/, '');
23
+ return {
24
+ kind: 'gcs',
25
+ async put(key, body, contentType, visibility) {
26
+ await bucketFor(visibility).file(key).save(body, { contentType, resumable: false });
27
+ },
28
+ async delete(key, visibility) {
29
+ await bucketFor(visibility).file(key).delete({ ignoreNotFound: true });
30
+ },
31
+ publicUrl(key) {
32
+ return `${baseUrl}/${key}`;
33
+ },
34
+ async get(key, visibility) {
35
+ // Fail before streaming when the object is missing (the stream would only error later).
36
+ const file = bucketFor(visibility).file(key);
37
+ if (file.exists) {
38
+ const [exists] = await file.exists();
39
+ if (!exists)
40
+ throw Object.assign(new Error(`GCS object "${key}" not found`), { code: 'ENOENT' });
41
+ }
42
+ return file.createReadStream();
43
+ },
44
+ };
45
+ }
46
+ //# sourceMappingURL=gcs.provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gcs.provider.js","sourceRoot":"","sources":["../../src/provider/gcs.provider.ts"],"names":[],"mappings":";;AAqCA,8CAkCC;AA7CD,SAAS,WAAW;IAClB,IAAI,GAAW,CAAC;IAChB,IAAI,CAAC;QACH,iEAAiE;QACjE,GAAG,GAAG,OAAO,CAAC,uBAAuB,CAAW,CAAC;IACnD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,6DAA6D,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IACjG,CAAC;IACD,OAAO,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;AAC3B,CAAC;AAED,SAAgB,iBAAiB,CAAC,GAAoB,EAAE,IAAsB;IAC5E,IAAI,OAAwD,CAAC;IAC7D,MAAM,IAAI,GAAG,CAAC,IAAY,EAAa,EAAE,CAAC,CAAC,OAAO,KAAK,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACnF,MAAM,MAAM,GAAG,IAAI,EAAE,MAAM,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAChD,+FAA+F;IAC/F,MAAM,aAAa,GAAG,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,aAAa,IAAI,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AAI,KAAK,CAAC,eAAe,GAAG,aAAa,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;YACnG,CAAC;YACD,OAAO,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { LocalAssetsConfig } from '../types';
2
+ import { type StorageProvider } from './storage-provider';
3
+ /**
4
+ * Private files live in `privateRoot`, by default `private-assets` next to `root`: outside the directory the
5
+ * local-static middleware serves.
6
+ */
7
+ export declare function localPrivateRoot(cfg: LocalAssetsConfig): string;
8
+ export declare function createLocalServerProvider(cfg: LocalAssetsConfig): StorageProvider;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.localPrivateRoot = localPrivateRoot;
7
+ exports.createLocalServerProvider = createLocalServerProvider;
8
+ const node_fs_1 = __importDefault(require("node:fs"));
9
+ const promises_1 = __importDefault(require("node:fs/promises"));
10
+ const node_path_1 = __importDefault(require("node:path"));
11
+ const storage_provider_1 = require("./storage-provider");
12
+ /**
13
+ * Private files live in `privateRoot`, by default `private-assets` next to `root`: outside the directory the
14
+ * local-static middleware serves.
15
+ */
16
+ function localPrivateRoot(cfg) {
17
+ return node_path_1.default.resolve(cfg.privateRoot ?? node_path_1.default.join(node_path_1.default.dirname(node_path_1.default.resolve(cfg.root)), 'private-assets'));
18
+ }
19
+ /** Real path of `p`: its nearest existing ancestor resolved through symlinks, plus the part that does not exist yet. */
20
+ function realish(p) {
21
+ const abs = node_path_1.default.resolve(p);
22
+ let existing = abs;
23
+ const rest = [];
24
+ while (!node_fs_1.default.existsSync(existing)) {
25
+ const parent = node_path_1.default.dirname(existing);
26
+ if (parent === existing)
27
+ break;
28
+ rest.unshift(node_path_1.default.basename(existing));
29
+ existing = parent;
30
+ }
31
+ return node_path_1.default.join(node_fs_1.default.realpathSync.native(existing), ...rest);
32
+ }
33
+ const within = (child, parent) => child === parent || child.startsWith(parent + node_path_1.default.sep);
34
+ function createLocalServerProvider(cfg) {
35
+ const { root, publicBaseUrl } = cfg;
36
+ const baseUrl = publicBaseUrl.replace(/\/$/, '');
37
+ const privateRoot = localPrivateRoot(cfg);
38
+ const realPublic = realish(root);
39
+ const realPrivate = realish(privateRoot);
40
+ if (within(realPrivate, realPublic) || within(realPublic, realPrivate)) {
41
+ throw new Error('assets.local.privateRoot and assets.local.root must not contain each other (root is served statically)');
42
+ }
43
+ // Private keys carry the `private/` prefix; inside privateRoot it is dropped.
44
+ const filePath = (key, visibility = 'public') => visibility === 'private'
45
+ ? node_path_1.default.join(privateRoot, key.startsWith(storage_provider_1.PRIVATE_KEY_PREFIX) ? key.slice(storage_provider_1.PRIVATE_KEY_PREFIX.length) : key)
46
+ : node_path_1.default.join(root, key);
47
+ return {
48
+ kind: 'local',
49
+ async put(key, body, _contentType, visibility) {
50
+ const p = filePath(key, visibility);
51
+ await promises_1.default.mkdir(node_path_1.default.dirname(p), { recursive: true });
52
+ await promises_1.default.writeFile(p, body);
53
+ },
54
+ async delete(key, visibility) {
55
+ try {
56
+ await promises_1.default.unlink(filePath(key, visibility));
57
+ }
58
+ catch (err) {
59
+ if (err && typeof err === 'object' && 'code' in err && err.code === 'ENOENT') {
60
+ return;
61
+ }
62
+ throw err;
63
+ }
64
+ },
65
+ publicUrl(key) {
66
+ return `${baseUrl}/${key}`;
67
+ },
68
+ async get(key, visibility) {
69
+ // Open first, so that a missing file rejects here rather than erroring mid-stream.
70
+ const handle = await promises_1.default.open(filePath(key, visibility), 'r');
71
+ return handle.createReadStream();
72
+ },
73
+ };
74
+ }
75
+ //# sourceMappingURL=local.provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local.provider.js","sourceRoot":"","sources":["../../src/provider/local.provider.ts"],"names":[],"mappings":";;;;;AAWA,4CAEC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AAE,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC;YAC7C,CAAC;YAAC,OAAO,GAAY,EAAE,CAAC;gBACtB,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;oBAC7E,OAAO;gBACT,CAAC;gBACD,MAAM,GAAG,CAAC;YACZ,CAAC;QACH,CAAC;QAED,SAAS,CAAC,GAAW;YACnB,OAAO,GAAG,OAAO,IAAI,GAAG,EAAE,CAAC;QAC7B,CAAC;QAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,UAA4B;YACjD,mFAAmF;YACnF,MAAM,MAAM,GAAG,MAAM,kBAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC,EAAE,GAAG,CAAC,CAAC;YAC7D,OAAO,MAAM,CAAC,gBAAgB,EAAE,CAAC;QACnC,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { S3AssetsConfig } from '../types';
2
+ import type { StorageProvider } from './storage-provider';
3
+ interface S3Client {
4
+ send(cmd: unknown): Promise<unknown>;
5
+ }
6
+ export interface S3ProviderDeps {
7
+ /** Pre-built client (tests / custom credentials). Defaults to `new S3Client({ region })`. */
8
+ client?: S3Client;
9
+ }
10
+ export declare function createS3Provider(cfg: S3AssetsConfig, deps?: S3ProviderDeps): StorageProvider;
11
+ export {};
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createS3Provider = createS3Provider;
4
+ const node_stream_1 = require("node:stream");
5
+ function loadSdk() {
6
+ try {
7
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
8
+ return require('@aws-sdk/client-s3');
9
+ }
10
+ catch (err) {
11
+ throw new Error('Provider "s3" requires optional peer @aws-sdk/client-s3', { cause: err });
12
+ }
13
+ }
14
+ function createS3Provider(cfg, deps) {
15
+ const sdk = loadSdk();
16
+ const client = deps?.client ?? new sdk.S3Client({ region: cfg.region });
17
+ const { bucket, region } = cfg;
18
+ // Private objects go to `privateBucket` when configured, otherwise they share the main bucket.
19
+ const bucketFor = (visibility = 'public') => visibility === 'private' && cfg.privateBucket ? cfg.privateBucket : bucket;
20
+ const baseUrl = (cfg.publicBaseUrl ?? `https://${bucket}.s3.${region}.amazonaws.com`).replace(/\/+$/, '');
21
+ return {
22
+ kind: 's3',
23
+ async put(key, body, contentType, visibility) {
24
+ await client.send(new sdk.PutObjectCommand({ Bucket: bucketFor(visibility), Key: key, Body: body, ContentType: contentType }));
25
+ },
26
+ async delete(key, visibility) {
27
+ await client.send(new sdk.DeleteObjectCommand({ Bucket: bucketFor(visibility), Key: key }));
28
+ },
29
+ publicUrl(key) {
30
+ return `${baseUrl}/${key}`;
31
+ },
32
+ async get(key, visibility) {
33
+ const out = (await client.send(new sdk.GetObjectCommand({ Bucket: bucketFor(visibility), Key: key })));
34
+ const body = out?.Body;
35
+ if (body instanceof node_stream_1.Readable)
36
+ return body;
37
+ if (body && typeof body.transformToByteArray === 'function') {
38
+ return node_stream_1.Readable.from([Buffer.from(await body.transformToByteArray())]);
39
+ }
40
+ throw new Error(`S3 object "${key}" has no readable body`);
41
+ },
42
+ };
43
+ }
44
+ //# sourceMappingURL=s3.provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s3.provider.js","sourceRoot":"","sources":["../../src/provider/s3.provider.ts"],"names":[],"mappings":";;AA6BA,4CAkCC;AA/DD,6CAAuC;AAoBvC,SAAS,OAAO;IACd,IAAI,CAAC;QACH,iEAAiE;QACjE,OAAO,OAAO,CAAC,oBAAoB,CAAU,CAAC;IAChD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,yDAAyD,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7F,CAAC;AACH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E,CAAC;QAC7B,CAAC;QAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,UAA4B;YACjD,MAAM,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,UAAU,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAuB,CAAC;YAC7H,MAAM,IAAI,GAAG,GAAG,EAAE,IAAI,CAAC;YACvB,IAAI,IAAI,YAAY,sBAAQ;gBAAE,OAAO,IAAI,CAAC;YAC1C,IAAI,IAAI,IAAI,OAAQ,IAA2C,CAAC,oBAAoB,KAAK,UAAU,EAAE,CAAC;gBACpG,OAAO,sBAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAO,IAAwD,CAAC,oBAAoB,EAAE,CAAC,CAAC,CAAC,CAAC;YAC9H,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,cAAc,GAAG,wBAAwB,CAAC,CAAC;QAC7D,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { Readable } from 'node:stream';
2
+ import type { StorageProviderKind } from '../types';
3
+ /** Keys of private files start with this prefix (spec §7), so that S3/GCS bucket policies can keep them private. */
4
+ export declare const PRIVATE_KEY_PREFIX = "private/";
5
+ export declare const isPrivateKey: (key: string) => boolean;
6
+ /** Where an object lives: `public` files may have a public URL, `private` ones never do. */
7
+ export type AssetVisibility = 'public' | 'private';
8
+ /**
9
+ * Every call takes the object's visibility explicitly (default `public`), so where an object is stored never depends
10
+ * on how its key looks (the local provider keeps private files in a separate directory).
11
+ */
12
+ export interface StorageProvider {
13
+ readonly kind: StorageProviderKind;
14
+ put(key: string, body: Buffer, contentType: string, visibility?: AssetVisibility): Promise<void>;
15
+ delete(key: string, visibility?: AssetVisibility): Promise<void>;
16
+ publicUrl(key: string): string;
17
+ /** Streams a stored object (private downloads). Rejects when it does not exist. */
18
+ get(key: string, visibility?: AssetVisibility): Promise<Readable>;
19
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPrivateKey = exports.PRIVATE_KEY_PREFIX = void 0;
4
+ /** Keys of private files start with this prefix (spec §7), so that S3/GCS bucket policies can keep them private. */
5
+ exports.PRIVATE_KEY_PREFIX = 'private/';
6
+ const isPrivateKey = (key) => key.startsWith(exports.PRIVATE_KEY_PREFIX);
7
+ exports.isPrivateKey = isPrivateKey;
8
+ //# sourceMappingURL=storage-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-provider.js","sourceRoot":"","sources":["../../src/provider/storage-provider.ts"],"names":[],"mappings":";;;AAGA,oHAAoH;AACvG,QAAA,kBAAkB,GAAG,UAAU,CAAC;AAEtC,MAAM,YAAY,GAAG,CAAC,GAAW,EAAW,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,0BAAkB,CAAC,CAAC;AAA5E,QAAA,YAAY,gBAAgE"}
@@ -0,0 +1,4 @@
1
+ export declare function missingAlt(asset: {
2
+ mimeType?: string | null;
3
+ alt?: string | null;
4
+ }): boolean;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.missingAlt = missingAlt;
4
+ function missingAlt(asset) {
5
+ const mime = asset.mimeType ?? '';
6
+ if (!mime.startsWith('image/')) {
7
+ return false;
8
+ }
9
+ return !asset.alt?.trim();
10
+ }
11
+ //# sourceMappingURL=missing-alt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"missing-alt.js","sourceRoot":"","sources":["../../src/seo/missing-alt.ts"],"names":[],"mappings":";;AAAA,gCASC;AATD,SAAgB,UAAU,CAAC,KAG1B;IACC,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC;IAClC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare function slugifyFilename(originalName: string, extOverride?: string): {
2
+ slug: string;
3
+ ext: string;
4
+ };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.slugifyFilename = slugifyFilename;
4
+ const COMBINING_MARKS = /[\u0300-\u036f]/g;
5
+ function slugifyFilename(originalName, extOverride) {
6
+ const lastDot = originalName.lastIndexOf('.');
7
+ const hasExt = lastDot > 0 && lastDot < originalName.length - 1;
8
+ const baseName = hasExt ? originalName.slice(0, lastDot) : originalName;
9
+ const extFromName = hasExt ? originalName.slice(lastDot + 1) : '';
10
+ const ext = (extOverride ?? extFromName).replace(/^\./, '').toLowerCase();
11
+ let slug = baseName
12
+ .normalize('NFKD')
13
+ .replace(COMBINING_MARKS, '')
14
+ .toLowerCase()
15
+ .replace(/[^a-z0-9]+/g, '-')
16
+ .replace(/^-+|-+$/g, '')
17
+ .slice(0, 80);
18
+ if (!slug) {
19
+ slug = 'file';
20
+ }
21
+ return { slug, ext };
22
+ }
23
+ //# sourceMappingURL=slug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slug.js","sourceRoot":"","sources":["../../src/seo/slug.ts"],"names":[],"mappings":";;AAEA,0CAuBC;AAzBD,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAE3C,SAAgB,eAAe,CAC7B,YAAoB,EACpB,WAAoB;IAEpB,MAAM,OAAO,GAAG,YAAY,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,OAAO,GAAG,CAAC,IAAI,OAAO,GAAG,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;IAChE,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC;IACxE,MAAM,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAClE,MAAM,GAAG,GAAG,CAAC,WAAW,IAAI,WAAW,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IAE1E,IAAI,IAAI,GAAG,QAAQ;SAChB,SAAS,CAAC,MAAM,CAAC;SACjB,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC;SAC5B,WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;SAC3B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEhB,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,IAAI,GAAG,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AACvB,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Content sniffing for private uploads (spec §7): the type of a file is decided from its bytes, never from its
3
+ * extension or declared type.
4
+ */
5
+ /**
6
+ * The MIME type of `buf` from its leading bytes: PDF, PNG, JPEG, GIF, WEBP, DOCX/XLSX/PPTX, ZIP, DOC/XLS/PPT (OLE),
7
+ * else `text/plain` for valid UTF-8 without control bytes, else null (unknown).
8
+ */
9
+ export declare function sniffMime(buf: Buffer): string | null;
10
+ /** Whether `mime` satisfies an `accept` list (`type/subtype`, `type/*`, `*\/*`). No list = any known type. */
11
+ export declare function acceptsMime(accept: readonly string[] | undefined | null, mime: string | null): boolean;
12
+ /**
13
+ * The stored type of an upload into a field with `accept`, or null when it is not acceptable. Binary formats must
14
+ * sniff to an accepted type. Plain text cannot be told apart further, so a declared text-like type (`text/csv`,
15
+ * `application/json`, …) is used when the field accepts it. Active types (HTML, XHTML, SVG, XML, JavaScript) are
16
+ * always stored as `text/plain`.
17
+ */
18
+ export declare function resolveUploadMime(buf: Buffer, declared: string | null | undefined, accept?: readonly string[] | null): string | null;
package/dist/sniff.js ADDED
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ /**
3
+ * Content sniffing for private uploads (spec §7): the type of a file is decided from its bytes, never from its
4
+ * extension or declared type.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.sniffMime = sniffMime;
8
+ exports.acceptsMime = acceptsMime;
9
+ exports.resolveUploadMime = resolveUploadMime;
10
+ const startsWith = (buf, sig, at = 0) => buf.length >= at + sig.length && sig.every((b, i) => buf[at + i] === b);
11
+ const ascii = (s) => [...s].map((c) => c.charCodeAt(0));
12
+ const DOCX = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
13
+ const XLSX = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
14
+ const PPTX = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
15
+ /** How many leading bytes the plain-text heuristic looks at. */
16
+ const TEXT_PROBE = 8192;
17
+ function sniffZip(buf) {
18
+ // File names are stored uncompressed in the local headers and the central directory.
19
+ if (buf.includes('[Content_Types].xml')) {
20
+ if (buf.includes('word/'))
21
+ return DOCX;
22
+ if (buf.includes('xl/'))
23
+ return XLSX;
24
+ if (buf.includes('ppt/'))
25
+ return PPTX;
26
+ }
27
+ return 'application/zip';
28
+ }
29
+ function sniffOle(buf) {
30
+ // Directory entry names are UTF-16LE.
31
+ if (buf.includes(Buffer.from('WordDocument', 'utf16le')))
32
+ return 'application/msword';
33
+ if (buf.includes(Buffer.from('Workbook', 'utf16le')) || buf.includes(Buffer.from('Book', 'utf16le')))
34
+ return 'application/vnd.ms-excel';
35
+ if (buf.includes(Buffer.from('PowerPoint Document', 'utf16le')))
36
+ return 'application/vnd.ms-powerpoint';
37
+ return 'application/x-ole-storage';
38
+ }
39
+ function looksLikeText(buf) {
40
+ let probe = buf.subarray(0, TEXT_PROBE);
41
+ // Do not fail on a multi-byte character cut by the probe boundary: drop an incomplete trailing sequence.
42
+ if (buf.length > TEXT_PROBE) {
43
+ let i = probe.length - 1;
44
+ let back = 0;
45
+ while (i >= 0 && back < 3 && (probe[i] & 0xc0) === 0x80) {
46
+ i--;
47
+ back++;
48
+ }
49
+ if (i >= 0 && probe[i] >= 0xc0)
50
+ probe = probe.subarray(0, i);
51
+ }
52
+ try {
53
+ new TextDecoder('utf-8', { fatal: true }).decode(probe);
54
+ }
55
+ catch {
56
+ return false;
57
+ }
58
+ for (const b of probe) {
59
+ // Control bytes other than tab, LF, FF, CR and ESC mean binary.
60
+ if (b < 0x20 && b !== 0x09 && b !== 0x0a && b !== 0x0c && b !== 0x0d && b !== 0x1b)
61
+ return false;
62
+ if (b === 0x7f)
63
+ return false;
64
+ }
65
+ return true;
66
+ }
67
+ /**
68
+ * The MIME type of `buf` from its leading bytes: PDF, PNG, JPEG, GIF, WEBP, DOCX/XLSX/PPTX, ZIP, DOC/XLS/PPT (OLE),
69
+ * else `text/plain` for valid UTF-8 without control bytes, else null (unknown).
70
+ */
71
+ function sniffMime(buf) {
72
+ if (!buf || buf.length === 0)
73
+ return null;
74
+ if (startsWith(buf, ascii('%PDF-')))
75
+ return 'application/pdf';
76
+ if (startsWith(buf, [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]))
77
+ return 'image/png';
78
+ if (startsWith(buf, [0xff, 0xd8, 0xff]))
79
+ return 'image/jpeg';
80
+ if (startsWith(buf, ascii('GIF87a')) || startsWith(buf, ascii('GIF89a')))
81
+ return 'image/gif';
82
+ if (startsWith(buf, ascii('RIFF')) && startsWith(buf, ascii('WEBP'), 8))
83
+ return 'image/webp';
84
+ if (startsWith(buf, [0x50, 0x4b, 0x03, 0x04]) || startsWith(buf, [0x50, 0x4b, 0x05, 0x06]))
85
+ return sniffZip(buf);
86
+ if (startsWith(buf, [0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1]))
87
+ return sniffOle(buf);
88
+ return looksLikeText(buf) ? 'text/plain' : null;
89
+ }
90
+ /** Whether `mime` satisfies an `accept` list (`type/subtype`, `type/*`, `*\/*`). No list = any known type. */
91
+ function acceptsMime(accept, mime) {
92
+ if (!mime)
93
+ return false;
94
+ if (!accept?.length)
95
+ return true;
96
+ const m = mime.toLowerCase();
97
+ return accept.some((a) => {
98
+ const p = a.trim().toLowerCase();
99
+ if (p === '*/*')
100
+ return true;
101
+ if (p.endsWith('/*'))
102
+ return m.startsWith(p.slice(0, -1));
103
+ return p === m;
104
+ });
105
+ }
106
+ /** Text formats that sniff as `text/plain`; a declared one of these is kept when the field accepts it. */
107
+ const TEXT_LIKE = /^(text\/[\w.+-]+|application\/(json|xml|csv))$/;
108
+ /** Types a browser would render or run (markup, scripts in SVG/XML): private files are never stored with these. */
109
+ const ACTIVE = new Set(['text/html', 'application/xhtml+xml', 'image/svg+xml', 'text/xml', 'application/xml', 'text/javascript', 'application/javascript']);
110
+ /**
111
+ * The stored type of an upload into a field with `accept`, or null when it is not acceptable. Binary formats must
112
+ * sniff to an accepted type. Plain text cannot be told apart further, so a declared text-like type (`text/csv`,
113
+ * `application/json`, …) is used when the field accepts it. Active types (HTML, XHTML, SVG, XML, JavaScript) are
114
+ * always stored as `text/plain`.
115
+ */
116
+ function resolveUploadMime(buf, declared, accept) {
117
+ const sniffed = sniffMime(buf);
118
+ let out = null;
119
+ if (sniffed === 'text/plain') {
120
+ const d = (declared ?? '').split(';')[0].trim().toLowerCase();
121
+ if (d && d !== 'text/plain' && (TEXT_LIKE.test(d) || ACTIVE.has(d)) && acceptsMime(accept, d))
122
+ out = d;
123
+ }
124
+ if (!out && sniffed && acceptsMime(accept, sniffed))
125
+ out = sniffed;
126
+ if (!out && !sniffed && (!accept?.length || accept.some((a) => a.trim() === '*/*')))
127
+ out = 'application/octet-stream';
128
+ return out && ACTIVE.has(out) ? 'text/plain' : out;
129
+ }
130
+ //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age object key (used for deletes). */
4
+ key: string;
5
+ url: string;
6
+ width?: number;
7
+ height?: number;
8
+ bytes: number;
9
+ mimeType: string;
10
+ }
11
+ export interface AssetVariants {
12
+ original: VariantInfo;
13
+ thumb?: VariantInfo;
14
+ medium?: VariantInfo;
15
+ large?: VariantInfo;
16
+ }
17
+ export interface LocalAssetsConfig {
18
+ root: string;
19
+ publicBaseUrl: string;
20
+ /** Directory of private files (spec §7). Default: `private-assets` next to `root`; never under `root`. */
21
+ privateRoot?: string;
22
+ }
23
+ export interface S3AssetsConfig {
24
+ bucket: string;
25
+ region: string;
26
+ publicBaseUrl?: string;
27
+ /** Bucket for private files (`private/<apiId>/<uuid>`). When unset they share `bucket`, whose policy must then deny public reads on `private/*`. */
28
+ privateBucket?: string;
29
+ }
30
+ export interface GcsAssetsConfig {
31
+ bucket: string;
32
+ publicBaseUrl?: string;
33
+ /** Bucket for private files (`private/<apiId>/<uuid>`). When unset they share `bucket`, which must then keep `private/*` non-public. */
34
+ privateBucket?: string;
35
+ }
36
+ export interface AssetsImageConfig {
37
+ sizes?: {
38
+ thumb?: number;
39
+ medium?: number;
40
+ large?: number;
41
+ };
42
+ }
43
+ export interface AssetsLimitsConfig {
44
+ maxBytes?: number;
45
+ accept?: string[];
46
+ }
47
+ export interface AssetsModuleOptions {
48
+ provider: StorageProviderKind;
49
+ local?: LocalAssetsConfig;
50
+ s3?: S3AssetsConfig;
51
+ gcs?: GcsAssetsConfig;
52
+ limits?: AssetsLimitsConfig;
53
+ image?: AssetsImageConfig;
54
+ }
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,72 @@
1
1
  {
2
2
  "name": "@opencloudcms/assets",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "publishConfig": {
4
+ "access": "public"
5
+ },
6
+ "version": "0.1.0",
7
+ "description": "Asset upload and storage providers for OpenCloudCMS",
8
+ "license": "MIT",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/anhdev97/Open-CMS.git",
12
+ "directory": "packages/assets"
13
+ },
14
+ "homepage": "https://github.com/anhdev97/Open-CMS#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/anhdev97/Open-CMS/issues"
17
+ },
18
+ "engines": {
19
+ "node": ">=22"
20
+ },
21
+ "main": "dist/index.js",
22
+ "types": "dist/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "dependencies": {
34
+ "kysely": "^0.28.0",
35
+ "sharp": "^0.35.5",
36
+ "@opencloudcms/db": "0.1.0",
37
+ "@opencloudcms/oauth2": "0.1.0",
38
+ "@opencloudcms/schema": "0.1.0"
39
+ },
40
+ "peerDependencies": {
41
+ "@nestjs/common": "^11.0.0",
42
+ "@nestjs/core": "^11.0.0",
43
+ "@nestjs/platform-express": "^11.0.0",
44
+ "reflect-metadata": "^0.2.0",
45
+ "rxjs": "^7.8.0",
46
+ "@aws-sdk/client-s3": "^3.0.0",
47
+ "@google-cloud/storage": "^7.0.0"
48
+ },
49
+ "peerDependenciesMeta": {
50
+ "@aws-sdk/client-s3": {
51
+ "optional": true
52
+ },
53
+ "@google-cloud/storage": {
54
+ "optional": true
55
+ }
56
+ },
57
+ "devDependencies": {
58
+ "@nestjs/common": "^11.2.5",
59
+ "@nestjs/core": "^11.2.5",
60
+ "@nestjs/platform-express": "^11.2.5",
61
+ "@nestjs/testing": "^11.2.5",
62
+ "@types/express": "^5.0.6",
63
+ "@types/supertest": "^6.0.3",
64
+ "reflect-metadata": "^0.2.2",
65
+ "rxjs": "^7.8.2",
66
+ "supertest": "^7.1.0"
67
+ },
68
+ "scripts": {
69
+ "build": "tsc -p tsconfig.json",
70
+ "typecheck": "tsc -p tsconfig.json --noEmit"
71
+ }
6
72
  }