@adatechnology/content-module 0.2.2 → 0.3.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.cjs +45 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -7
- package/dist/index.d.ts +25 -7
- package/dist/index.js +43 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -23,6 +23,7 @@ var index_exports = {};
|
|
|
23
23
|
__export(index_exports, {
|
|
24
24
|
ArchivePostUseCase: () => ArchivePostUseCase,
|
|
25
25
|
BuildFeedUseCase: () => BuildFeedUseCase,
|
|
26
|
+
CONTENT_IMAGE: () => CONTENT_IMAGE,
|
|
26
27
|
CONTENT_MIGRATIONS_TABLE: () => CONTENT_MIGRATIONS_TABLE,
|
|
27
28
|
COVER_IMAGE: () => COVER_IMAGE,
|
|
28
29
|
CountPostsUseCase: () => CountPostsUseCase,
|
|
@@ -50,6 +51,7 @@ __export(index_exports, {
|
|
|
50
51
|
UpdatePostUseCase: () => UpdatePostUseCase,
|
|
51
52
|
UpdateRecurrenceUseCase: () => UpdateRecurrenceUseCase,
|
|
52
53
|
UploadCoverImageUseCase: () => UploadCoverImageUseCase,
|
|
54
|
+
UploadImageUseCase: () => UploadImageUseCase,
|
|
53
55
|
contentMigrationsFolder: () => contentMigrationsFolder,
|
|
54
56
|
contentSchema: () => contentSchema,
|
|
55
57
|
createContentModule: () => createContentModule,
|
|
@@ -1336,11 +1338,11 @@ var PublishDueUseCase = class extends PostUseCaseBase {
|
|
|
1336
1338
|
}
|
|
1337
1339
|
};
|
|
1338
1340
|
|
|
1339
|
-
// src/use-cases/
|
|
1341
|
+
// src/use-cases/UploadImage.use-case.ts
|
|
1340
1342
|
var import_content_contracts12 = require("@adatechnology/content-contracts");
|
|
1341
1343
|
|
|
1342
1344
|
// src/shared/coverImage.constant.ts
|
|
1343
|
-
var
|
|
1345
|
+
var CONTENT_IMAGE = {
|
|
1344
1346
|
MAX_BYTES: 1024 * 1024,
|
|
1345
1347
|
KEY_PREFIX: "content/posts",
|
|
1346
1348
|
EXTENSION_BY_MIME: {
|
|
@@ -1349,11 +1351,12 @@ var COVER_IMAGE = {
|
|
|
1349
1351
|
"image/webp": "webp"
|
|
1350
1352
|
}
|
|
1351
1353
|
};
|
|
1354
|
+
var COVER_IMAGE = CONTENT_IMAGE;
|
|
1352
1355
|
|
|
1353
|
-
// src/use-cases/
|
|
1354
|
-
var
|
|
1356
|
+
// src/use-cases/UploadImage.use-case.ts
|
|
1357
|
+
var UploadImageUseCase = class {
|
|
1355
1358
|
static {
|
|
1356
|
-
__name(this, "
|
|
1359
|
+
__name(this, "UploadImageUseCase");
|
|
1357
1360
|
}
|
|
1358
1361
|
dependencies;
|
|
1359
1362
|
constructor(dependencies) {
|
|
@@ -1363,11 +1366,11 @@ var UploadCoverImageUseCase = class {
|
|
|
1363
1366
|
const storage = this.dependencies.imageStorage;
|
|
1364
1367
|
if (!storage) throw new import_content_contracts12.ImageStorageDisabledError();
|
|
1365
1368
|
const mimeType = (params.mimeType.split(";")[0] ?? "").trim().toLowerCase();
|
|
1366
|
-
const extension =
|
|
1369
|
+
const extension = CONTENT_IMAGE.EXTENSION_BY_MIME[mimeType];
|
|
1367
1370
|
if (!extension) throw new import_content_contracts12.InvalidCoverImageError("unsupported_type");
|
|
1368
1371
|
if (params.bytes.byteLength === 0) throw new import_content_contracts12.InvalidCoverImageError("empty");
|
|
1369
|
-
if (params.bytes.byteLength >
|
|
1370
|
-
const key = `${
|
|
1372
|
+
if (params.bytes.byteLength > CONTENT_IMAGE.MAX_BYTES) throw new import_content_contracts12.InvalidCoverImageError("too_large");
|
|
1373
|
+
const key = `${CONTENT_IMAGE.KEY_PREFIX}/${params.companyId}/${crypto.randomUUID()}.${extension}`;
|
|
1371
1374
|
return storage.upload({
|
|
1372
1375
|
buffer: params.bytes,
|
|
1373
1376
|
mimeType,
|
|
@@ -1376,6 +1379,13 @@ var UploadCoverImageUseCase = class {
|
|
|
1376
1379
|
}
|
|
1377
1380
|
};
|
|
1378
1381
|
|
|
1382
|
+
// src/use-cases/UploadCoverImage.use-case.ts
|
|
1383
|
+
var UploadCoverImageUseCase = class extends UploadImageUseCase {
|
|
1384
|
+
static {
|
|
1385
|
+
__name(this, "UploadCoverImageUseCase");
|
|
1386
|
+
}
|
|
1387
|
+
};
|
|
1388
|
+
|
|
1379
1389
|
// src/ContentModule.ts
|
|
1380
1390
|
var SYSTEM_CLOCK = {
|
|
1381
1391
|
now: /* @__PURE__ */ __name(() => /* @__PURE__ */ new Date(), "now")
|
|
@@ -1433,7 +1443,8 @@ function createContentModule(params) {
|
|
|
1433
1443
|
removeRecurrence: new RemoveRecurrenceUseCase(dependencies),
|
|
1434
1444
|
publishDue: new PublishDueUseCase(dependencies),
|
|
1435
1445
|
...dependencies.imageStorage ? {
|
|
1436
|
-
uploadCoverImage: new UploadCoverImageUseCase(dependencies)
|
|
1446
|
+
uploadCoverImage: new UploadCoverImageUseCase(dependencies),
|
|
1447
|
+
uploadImage: new UploadImageUseCase(dependencies)
|
|
1437
1448
|
} : {},
|
|
1438
1449
|
...config.feed ? {
|
|
1439
1450
|
buildFeed: new BuildFeedUseCase(dependencies, config.feed),
|
|
@@ -1502,6 +1513,28 @@ function buildAdminRoutes(module2) {
|
|
|
1502
1513
|
}
|
|
1503
1514
|
}
|
|
1504
1515
|
] : [];
|
|
1516
|
+
const imageRoutes = useCases.uploadImage ? [
|
|
1517
|
+
{
|
|
1518
|
+
...admin,
|
|
1519
|
+
method: "POST",
|
|
1520
|
+
path: "/posts/images",
|
|
1521
|
+
operationId: "uploadPostImage",
|
|
1522
|
+
summary: "Envia uma foto do corpo do post (bytes crus, Content-Type jpeg/png/webp) e devolve a URL",
|
|
1523
|
+
async handler(context) {
|
|
1524
|
+
const upload = useCases.uploadImage;
|
|
1525
|
+
if (!upload) return {
|
|
1526
|
+
kind: "empty",
|
|
1527
|
+
status: 404
|
|
1528
|
+
};
|
|
1529
|
+
const result = await upload.execute({
|
|
1530
|
+
companyId: requireCompany(context),
|
|
1531
|
+
bytes: context.rawBody ?? new Uint8Array(),
|
|
1532
|
+
mimeType: context.headers["content-type"] ?? ""
|
|
1533
|
+
});
|
|
1534
|
+
return json(201, result);
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
] : [];
|
|
1505
1538
|
return [
|
|
1506
1539
|
{
|
|
1507
1540
|
...admin,
|
|
@@ -1565,6 +1598,7 @@ function buildAdminRoutes(module2) {
|
|
|
1565
1598
|
},
|
|
1566
1599
|
...recurrenceRoutes(module2),
|
|
1567
1600
|
...uploadRoutes,
|
|
1601
|
+
...imageRoutes,
|
|
1568
1602
|
{
|
|
1569
1603
|
...admin,
|
|
1570
1604
|
method: "GET",
|
|
@@ -2155,6 +2189,7 @@ __name(createInMemoryRecurrenceStore, "createInMemoryRecurrenceStore");
|
|
|
2155
2189
|
0 && (module.exports = {
|
|
2156
2190
|
ArchivePostUseCase,
|
|
2157
2191
|
BuildFeedUseCase,
|
|
2192
|
+
CONTENT_IMAGE,
|
|
2158
2193
|
CONTENT_MIGRATIONS_TABLE,
|
|
2159
2194
|
COVER_IMAGE,
|
|
2160
2195
|
CountPostsUseCase,
|
|
@@ -2182,6 +2217,7 @@ __name(createInMemoryRecurrenceStore, "createInMemoryRecurrenceStore");
|
|
|
2182
2217
|
UpdatePostUseCase,
|
|
2183
2218
|
UpdateRecurrenceUseCase,
|
|
2184
2219
|
UploadCoverImageUseCase,
|
|
2220
|
+
UploadImageUseCase,
|
|
2185
2221
|
contentMigrationsFolder,
|
|
2186
2222
|
contentSchema,
|
|
2187
2223
|
createContentModule,
|