@dnax/core 0.9.5 → 0.9.7
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 +71 -12
- 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";
|
|
@@ -551,15 +554,71 @@ function HonoInstance(): typeof app {
|
|
|
551
554
|
}
|
|
552
555
|
});
|
|
553
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
|
+
const crop = c.req.query("fit") || "contain";
|
|
568
|
+
// Vérifier si le fichier existe
|
|
569
|
+
if (!fs.existsSync(filePath)) {
|
|
570
|
+
return c.text("file not found", 404);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// Obtenir le type MIME du fichier
|
|
574
|
+
const mimeType = mime.lookup(filePath);
|
|
575
|
+
|
|
576
|
+
// Si ce n'est pas une image, retourner le fichier original
|
|
577
|
+
if (!mimeType || !mimeType.startsWith("image/")) {
|
|
578
|
+
const originalFile = fs.readFileSync(filePath);
|
|
579
|
+
return c.body(originalFile, 200, {
|
|
580
|
+
"Content-Type": mimeType || "application/octet-stream",
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
try {
|
|
585
|
+
// Redimensionner l'image avec Sharp
|
|
586
|
+
const buffer = await sharp(filePath)
|
|
587
|
+
.resize(width, height, {
|
|
588
|
+
fit: crop || "contain",
|
|
589
|
+
})
|
|
590
|
+
.jpeg({ quality })
|
|
591
|
+
.toBuffer();
|
|
592
|
+
|
|
593
|
+
// Retourner l'image redimensionnée
|
|
594
|
+
return c.body(buffer, 200, {
|
|
595
|
+
"Content-Type": "image/jpeg",
|
|
596
|
+
});
|
|
597
|
+
} catch (error) {
|
|
598
|
+
// Si une erreur se produit avec Sharp, retourner le fichier original
|
|
599
|
+
const file = fs.readFileSync(filePath);
|
|
600
|
+
return c.body(file, 200, {
|
|
601
|
+
"Content-Type": mimeType || "application/octet-stream",
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
|
|
554
606
|
// media endpoints
|
|
555
|
-
Cfg.collections?.map((c) => {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
607
|
+
//Cfg.collections?.map((c) => {
|
|
608
|
+
// if (c?.type == "media" && c.media?.enabled) {
|
|
609
|
+
//let mediaPath = cleanPath(
|
|
610
|
+
// "/files/" + (c?.media?.overwriteFolderName || c?.slug) + "/public/*"
|
|
611
|
+
// );
|
|
612
|
+
|
|
613
|
+
/* app.get(optimizeImage, async (c, next) => {
|
|
614
|
+
let width = parseInt(c.req.query("w")) || null;
|
|
615
|
+
let height = parseInt(c.req.query("h")) || null;
|
|
616
|
+
let quality = parseInt(c.req.query("q")) || 80;
|
|
617
|
+
|
|
618
|
+
}); */
|
|
619
|
+
|
|
620
|
+
//console.log("Media Path :", mediaPath);
|
|
621
|
+
/* app.get(
|
|
563
622
|
mediaPath,
|
|
564
623
|
serveStatic({
|
|
565
624
|
root: cleanPath("uploads"),
|
|
@@ -568,9 +627,9 @@ function HonoInstance(): typeof app {
|
|
|
568
627
|
console.log(`${path} is not found, you access ${c.req.path}`);
|
|
569
628
|
},
|
|
570
629
|
})
|
|
571
|
-
);
|
|
572
|
-
|
|
573
|
-
});
|
|
630
|
+
); */
|
|
631
|
+
//}
|
|
632
|
+
//});
|
|
574
633
|
|
|
575
634
|
// Endpoint
|
|
576
635
|
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.7",
|
|
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",
|