@dnax/core 0.63.6 → 0.63.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/index.ts CHANGED
@@ -7,7 +7,7 @@ import { $ } from "bun";
7
7
  import define from "./define";
8
8
  import * as utils from "./utils";
9
9
  import { dataCache } from "./lib/bento";
10
- import { FilesystemSftpAdapter } from "./lib/media";
10
+ import { FilesystemSftpAdapter, MinioAdapter } from "./lib/media";
11
11
  import { crypt } from "./lib/crypto";
12
12
  import { contextStorage } from "./lib/asyncLocalStorage";
13
13
  import { Cron as Task } from "croner";
@@ -16,6 +16,7 @@ import { Cron as Task } from "croner";
16
16
 
17
17
  const Adapter = {
18
18
  FilesystemSftpAdapter,
19
+ MinioAdapter,
19
20
  };
20
21
 
21
22
  /**
@@ -0,0 +1,71 @@
1
+ import * as Minio from "minio";
2
+ import { consola } from "consola";
3
+ import path from "path";
4
+ import chokidar from "chokidar";
5
+ import fs from "fs-extra";
6
+ import type { Collection } from "../../types";
7
+ const BASE_DIR = "/uploads/";
8
+ type AdapterConfig = {
9
+ endPoint: string;
10
+ port?: number;
11
+ useSSL?: boolean;
12
+ accessKey: string;
13
+ secretKey: string;
14
+ bucket: string;
15
+ ignorePatterns: Array<string>;
16
+ };
17
+
18
+ class MinioAdapter {
19
+ type: "minio";
20
+ config: AdapterConfig;
21
+ client: InstanceType<(typeof Minio)["Client"]>;
22
+ constructor(config: AdapterConfig) {
23
+ this.type = "minio";
24
+ this.config = {
25
+ port: 9000,
26
+ useSSL: false,
27
+ ...config,
28
+ };
29
+ this.client = new Minio.Client(this.config);
30
+ this.init();
31
+ }
32
+
33
+ async init() {
34
+ try {
35
+ const exists = await this.client.bucketExists(this.config.bucket);
36
+ if (exists) {
37
+ //console.log("Bucket " + this.config.bucket + " exists.");
38
+ } else {
39
+ await this.client.makeBucket(this.config.bucket);
40
+ consola.success("✅ Bucket created " + this.config.bucket);
41
+ }
42
+ } catch (err: any) {
43
+ console.error(err?.message);
44
+ }
45
+ }
46
+
47
+ async syncCollectionMedia(col: Collection) {
48
+ let visibility = col?.media?.visibility || "public";
49
+
50
+ let dirToWatch = path.join(process.cwd(), BASE_DIR, col?.slug, visibility);
51
+ dirToWatch = path.resolve(dirToWatch);
52
+ const watcher = chokidar.watch(dirToWatch, {
53
+ persistent: true,
54
+ ignoreInitial: true,
55
+ ignored: this.config?.ignorePatterns || [],
56
+ });
57
+
58
+ watcher.on("all", (event, filePath) => {
59
+ if (event == "change" || event == "add") {
60
+ let baseName = path.basename(filePath);
61
+ this.client
62
+ .fPutObject(this.config.bucket, baseName, filePath)
63
+ .catch((err) => {
64
+ consola.error(err?.message);
65
+ });
66
+ }
67
+ });
68
+ }
69
+ }
70
+
71
+ export { MinioAdapter };
@@ -8,7 +8,15 @@ async function syncAdapterFileSystem() {
8
8
 
9
9
  mediaCollections?.map((col) => {
10
10
  if (col?.media?.filesystemAdapter) {
11
- let currentAdapter = col?.media?.filesystemAdapter;
11
+ let currentAdapter = col?.media?.filesystemAdapter as {
12
+ type: "sftp" | "minio";
13
+ syncCollectionMedia: Function;
14
+ };
15
+
16
+ // Minio
17
+ if (currentAdapter?.type == "minio") {
18
+ currentAdapter.syncCollectionMedia(col);
19
+ }
12
20
 
13
21
  // for sftp
14
22
  if (currentAdapter?.type == "sftp") {
@@ -1,6 +1,7 @@
1
1
  import { cleanDoubleSlashes } from "ufo";
2
2
  import { FilesystemSftpAdapter } from "./sftp";
3
3
  import { syncAdapterFileSystem } from "./SyncAdapter";
4
+ import { MinioAdapter } from "./MinioAdapter";
4
5
  import fs from "fs";
5
6
  import { v4 } from "uuid";
6
7
  type driverOptions = {
@@ -73,4 +74,9 @@ class MediaDrive {
73
74
  }
74
75
  }
75
76
 
76
- export { MediaDrive, FilesystemSftpAdapter, syncAdapterFileSystem };
77
+ export {
78
+ MediaDrive,
79
+ FilesystemSftpAdapter,
80
+ syncAdapterFileSystem,
81
+ MinioAdapter,
82
+ };
package/lib/secret.ts ADDED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.63.6",
3
+ "version": "0.63.7",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
@@ -12,6 +12,7 @@
12
12
  "@types/fs-extra": "^11.0.4",
13
13
  "@types/jsonwebtoken": "9.0.9",
14
14
  "@types/mime-types": "^2.1.4",
15
+ "@types/minio": "^7.1.1",
15
16
  "@types/nodemailer": "^6.4.15",
16
17
  "@types/pidusage": "^2.0.5",
17
18
  "@types/ssh2-sftp-client": "^9.0.4",
@@ -24,6 +25,7 @@
24
25
  "@clack/prompts": "^0.10.0",
25
26
  "@colors/colors": "^1.6.0",
26
27
  "@lukeed/ms": "^2.0.2",
28
+ "aws-sdk": "^2.1692.0",
27
29
  "bentocache": "^1.2.1",
28
30
  "boxen": "^7.1.1",
29
31
  "chokidar": "3.6.0",
@@ -44,6 +46,7 @@
44
46
  "meilisearch": "^0.50.0",
45
47
  "mime-types": "^2.1.35",
46
48
  "mingo": "^6.5.0",
49
+ "minio": "^8.0.5",
47
50
  "moment": "^2.30.1",
48
51
  "mongodb": "6.15.0",
49
52
  "nodemailer": "^6.9.14",