@dnax/core 0.9.4 → 0.9.6
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/app/hono.ts +79 -22
- package/package.json +5 -1
package/app/hono.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { Q, Tenant, sessionCtx } from "../types/";
|
|
2
|
-
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import sharp from "sharp";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import mime from "mime-types";
|
|
3
6
|
import { Hono } from "hono";
|
|
4
7
|
import { getCookie, setCookie } from "hono/cookie";
|
|
5
8
|
import colors from "@colors/colors/safe";
|
|
@@ -302,18 +305,9 @@ function HonoInstance(): typeof app {
|
|
|
302
305
|
|
|
303
306
|
var response;
|
|
304
307
|
var parseBody;
|
|
308
|
+
var body;
|
|
305
309
|
var { action, collection, cleanDeep, useCache, name } =
|
|
306
310
|
c.req.query() as Q;
|
|
307
|
-
const service = getService(name, c.var["tenant-id"]);
|
|
308
|
-
const col = getCollection(collection, c.var["tenant-id"]);
|
|
309
|
-
const body = await c?.req
|
|
310
|
-
?.json()
|
|
311
|
-
.then((e) => e)
|
|
312
|
-
.catch((err) => null);
|
|
313
|
-
|
|
314
|
-
useCache = stringToBoolean(useCache, false);
|
|
315
|
-
if (body?.useCache) useCache = stringToBoolean(body.useCache, false);
|
|
316
|
-
|
|
317
311
|
if (
|
|
318
312
|
c.req.raw?.headers
|
|
319
313
|
?.get("content-type")
|
|
@@ -325,7 +319,17 @@ function HonoInstance(): typeof app {
|
|
|
325
319
|
(await c?.req.parseBody({
|
|
326
320
|
all: true,
|
|
327
321
|
})) || {};
|
|
322
|
+
} else {
|
|
323
|
+
body = await c?.req
|
|
324
|
+
?.json()
|
|
325
|
+
.then((e) => e)
|
|
326
|
+
.catch((err) => null);
|
|
328
327
|
}
|
|
328
|
+
const service = getService(name, c.var["tenant-id"]);
|
|
329
|
+
const col = getCollection(collection, c.var["tenant-id"]);
|
|
330
|
+
|
|
331
|
+
useCache = stringToBoolean(useCache, false);
|
|
332
|
+
if (body?.useCache) useCache = stringToBoolean(body.useCache, false);
|
|
329
333
|
|
|
330
334
|
const rest = new useRest({
|
|
331
335
|
tenant_id: c.var["tenant-id"],
|
|
@@ -550,15 +554,68 @@ function HonoInstance(): typeof app {
|
|
|
550
554
|
}
|
|
551
555
|
});
|
|
552
556
|
|
|
557
|
+
// serve static files
|
|
558
|
+
app.get("/files/:folder/public/:filename", async (c, next) => {
|
|
559
|
+
let { folder, filename } = c.req.param();
|
|
560
|
+
const filePath = path.join(
|
|
561
|
+
cleanPath("uploads/" + folder + "/public/"),
|
|
562
|
+
filename
|
|
563
|
+
);
|
|
564
|
+
const width = parseInt(c.req.query("w")) || null;
|
|
565
|
+
const height = parseInt(c.req.query("h")) || null;
|
|
566
|
+
const quality = parseInt(c.req.query("q")) || 80;
|
|
567
|
+
// Vérifier si le fichier existe
|
|
568
|
+
if (!fs.existsSync(filePath)) {
|
|
569
|
+
return c.text("file not found", 404);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// Obtenir le type MIME du fichier
|
|
573
|
+
const mimeType = mime.lookup(filePath);
|
|
574
|
+
|
|
575
|
+
// Si ce n'est pas une image, retourner le fichier original
|
|
576
|
+
if (!mimeType || !mimeType.startsWith("image/")) {
|
|
577
|
+
const originalFile = fs.readFileSync(filePath);
|
|
578
|
+
return c.body(originalFile, 200, {
|
|
579
|
+
"Content-Type": mimeType || "application/octet-stream",
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
try {
|
|
584
|
+
// Redimensionner l'image avec Sharp
|
|
585
|
+
const buffer = await sharp(filePath)
|
|
586
|
+
.resize(width, height)
|
|
587
|
+
.jpeg({ quality })
|
|
588
|
+
.toBuffer();
|
|
589
|
+
|
|
590
|
+
// Retourner l'image redimensionnée
|
|
591
|
+
return c.body(buffer, 200, {
|
|
592
|
+
"Content-Type": "image/jpeg",
|
|
593
|
+
});
|
|
594
|
+
} catch (error) {
|
|
595
|
+
// Si une erreur se produit avec Sharp, retourner le fichier original
|
|
596
|
+
const file = fs.readFileSync(filePath);
|
|
597
|
+
return c.body(file, 200, {
|
|
598
|
+
"Content-Type": mimeType || "application/octet-stream",
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
|
|
553
603
|
// media endpoints
|
|
554
|
-
Cfg.collections?.map((c) => {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
604
|
+
//Cfg.collections?.map((c) => {
|
|
605
|
+
// if (c?.type == "media" && c.media?.enabled) {
|
|
606
|
+
//let mediaPath = cleanPath(
|
|
607
|
+
// "/files/" + (c?.media?.overwriteFolderName || c?.slug) + "/public/*"
|
|
608
|
+
// );
|
|
609
|
+
|
|
610
|
+
/* app.get(optimizeImage, async (c, next) => {
|
|
611
|
+
let width = parseInt(c.req.query("w")) || null;
|
|
612
|
+
let height = parseInt(c.req.query("h")) || null;
|
|
613
|
+
let quality = parseInt(c.req.query("q")) || 80;
|
|
614
|
+
|
|
615
|
+
}); */
|
|
616
|
+
|
|
617
|
+
//console.log("Media Path :", mediaPath);
|
|
618
|
+
/* app.get(
|
|
562
619
|
mediaPath,
|
|
563
620
|
serveStatic({
|
|
564
621
|
root: cleanPath("uploads"),
|
|
@@ -567,9 +624,9 @@ function HonoInstance(): typeof app {
|
|
|
567
624
|
console.log(`${path} is not found, you access ${c.req.path}`);
|
|
568
625
|
},
|
|
569
626
|
})
|
|
570
|
-
);
|
|
571
|
-
|
|
572
|
-
});
|
|
627
|
+
); */
|
|
628
|
+
//}
|
|
629
|
+
//});
|
|
573
630
|
|
|
574
631
|
// Endpoint
|
|
575
632
|
Cfg?.endpoints?.map((e) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dnax/core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.6",
|
|
4
4
|
"module": "index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"@types/bun": "latest",
|
|
11
|
+
"@types/fs-extra": "^11.0.4",
|
|
12
|
+
"@types/mime-types": "^2.1.4",
|
|
11
13
|
"@types/nodemailer": "^6.4.15",
|
|
12
14
|
"@types/uuid": "^10.0.0"
|
|
13
15
|
},
|
|
@@ -35,11 +37,13 @@
|
|
|
35
37
|
"joi": "^17.13.3",
|
|
36
38
|
"json-joy": "^16.8.0",
|
|
37
39
|
"jsonwebtoken": "^9.0.2",
|
|
40
|
+
"mime-types": "^2.1.35",
|
|
38
41
|
"mingo": "^6.4.15",
|
|
39
42
|
"moment": "^2.30.1",
|
|
40
43
|
"mongodb": "^6.8.0",
|
|
41
44
|
"nodemailer": "^6.9.14",
|
|
42
45
|
"radash": "^12.1.0",
|
|
46
|
+
"sharp": "^0.33.5",
|
|
43
47
|
"signaldb": "^0.18.0",
|
|
44
48
|
"socket.io": "^4.7.5",
|
|
45
49
|
"ufo": "^1.5.3",
|