@manablox/media 0.3.0 → 0.4.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.
- package/dist/index.d.ts +7 -0
- package/dist/index.js +38 -2
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -106,8 +106,15 @@ export declare class MediaService {
|
|
|
106
106
|
* the next request renders through the new edits.
|
|
107
107
|
*/
|
|
108
108
|
setImageEdits(assetId: string, edits: AssetImageEdits): Promise<AssetRow>;
|
|
109
|
+
/** The name, alt text and title; the file itself never changes after upload. */
|
|
110
|
+
update(assetId: string, data: {
|
|
111
|
+
name?: string | undefined;
|
|
112
|
+
alt?: string | null | undefined;
|
|
113
|
+
title?: string | null | undefined;
|
|
114
|
+
}): Promise<AssetRow>;
|
|
109
115
|
verify(assetId: string, preset: string, format: string, signature: string | undefined): boolean;
|
|
110
116
|
delete(assetId: string): Promise<void>;
|
|
117
|
+
private audit;
|
|
111
118
|
}
|
|
112
119
|
//#endregion
|
|
113
120
|
//#region src/signing.d.ts
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ManabloxError, mimeTypeAllowed, withinInstance } from "@manablox/core";
|
|
1
|
+
import { ManabloxError, diffRecords, mimeTypeAllowed, snapshotChanges, withinInstance } from "@manablox/core";
|
|
2
2
|
import { createHash, createHmac, timingSafeEqual } from "node:crypto";
|
|
3
3
|
import { buildStorageKey } from "@manablox/storage";
|
|
4
4
|
import sharp from "sharp";
|
|
@@ -150,6 +150,16 @@ const IMAGE_FORMATS = /* @__PURE__ */ new Set([
|
|
|
150
150
|
"jpeg",
|
|
151
151
|
"png"
|
|
152
152
|
]);
|
|
153
|
+
/** The storage key and the checksum are the file, which never changes; the rest is the record. */
|
|
154
|
+
const ASSET_DIFF = {
|
|
155
|
+
expand: ["meta"],
|
|
156
|
+
ignore: [
|
|
157
|
+
"driver",
|
|
158
|
+
"key",
|
|
159
|
+
"checksum",
|
|
160
|
+
"actorId"
|
|
161
|
+
]
|
|
162
|
+
};
|
|
153
163
|
/** Upload, probing, and on-demand image derivatives. */
|
|
154
164
|
var MediaService = class {
|
|
155
165
|
repos;
|
|
@@ -204,6 +214,7 @@ var MediaService = class {
|
|
|
204
214
|
title: input.title ?? null,
|
|
205
215
|
actorId: input.actorId ?? null
|
|
206
216
|
});
|
|
217
|
+
await this.audit("asset.upload", asset, snapshotChanges(asset, "created", ASSET_DIFF));
|
|
207
218
|
for (const preset of this.config.eager ?? []) if (this.config.presets?.[preset] && dimensions) await this.derive(asset, preset, this.config.presets[preset]?.format ?? "webp").catch(() => void 0);
|
|
208
219
|
return asset;
|
|
209
220
|
}
|
|
@@ -290,7 +301,17 @@ var MediaService = class {
|
|
|
290
301
|
const variants = await this.repos.assets.variants([assetId]);
|
|
291
302
|
await Promise.all(variants.map((variant) => this.storage.delete(variant.key).catch(() => void 0)));
|
|
292
303
|
await this.repos.assets.deleteVariants(assetId);
|
|
293
|
-
|
|
304
|
+
const saved = await this.repos.assets.update(assetId, { meta });
|
|
305
|
+
await this.audit("asset.setImageEdits", saved, diffRecords(asset, saved, ASSET_DIFF));
|
|
306
|
+
return saved;
|
|
307
|
+
}
|
|
308
|
+
/** The name, alt text and title; the file itself never changes after upload. */
|
|
309
|
+
async update(assetId, data) {
|
|
310
|
+
const asset = await this.repos.assets.findById(assetId);
|
|
311
|
+
if (!asset) throw ManabloxError.notFound("asset.notFound", { id: assetId });
|
|
312
|
+
const saved = await this.repos.assets.update(assetId, data);
|
|
313
|
+
await this.audit("asset.update", saved, diffRecords(asset, saved, ASSET_DIFF));
|
|
314
|
+
return saved;
|
|
294
315
|
}
|
|
295
316
|
verify(assetId, preset, format, signature) {
|
|
296
317
|
const secret = this.config.signingSecret;
|
|
@@ -309,6 +330,21 @@ var MediaService = class {
|
|
|
309
330
|
await Promise.all(variants.map((variant) => this.storage.delete(variant.key).catch(() => void 0)));
|
|
310
331
|
await this.storage.delete(asset.key).catch(() => void 0);
|
|
311
332
|
await this.repos.assets.delete(assetId);
|
|
333
|
+
await this.audit("asset.delete", asset, snapshotChanges(asset, "deleted", ASSET_DIFF));
|
|
334
|
+
}
|
|
335
|
+
audit(action, asset, changes) {
|
|
336
|
+
return this.repos.audit.record({
|
|
337
|
+
spaceId: asset.spaceId,
|
|
338
|
+
action,
|
|
339
|
+
targetKind: "asset",
|
|
340
|
+
targetId: asset.id,
|
|
341
|
+
targetLabel: asset.name,
|
|
342
|
+
changes,
|
|
343
|
+
meta: {
|
|
344
|
+
mimeType: asset.mimeType,
|
|
345
|
+
filename: asset.filename
|
|
346
|
+
}
|
|
347
|
+
});
|
|
312
348
|
}
|
|
313
349
|
};
|
|
314
350
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manablox/media",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"main": "./dist/index.js",
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@manablox/core": "0.
|
|
15
|
-
"@manablox/db": "0.
|
|
16
|
-
"@manablox/storage": "0.
|
|
14
|
+
"@manablox/core": "0.4.0",
|
|
15
|
+
"@manablox/db": "0.4.0",
|
|
16
|
+
"@manablox/storage": "0.4.0",
|
|
17
17
|
"sharp": "^0.35.4"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|