backfarm 1.0.0 → 1.0.2
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/chunk-3AP6JARL.js +12 -0
- package/dist/chunk-3AP6JARL.js.map +1 -0
- package/dist/chunk-5A3RVJNT.js +19 -0
- package/dist/chunk-5A3RVJNT.js.map +1 -0
- package/dist/chunk-LFRKRR7G.js +18 -0
- package/dist/chunk-LFRKRR7G.js.map +1 -0
- package/dist/{chunk-NDJVYPUT.js → chunk-PRKZ33FU.js} +4 -4
- package/dist/chunk-TCG3UB2T.js +23 -0
- package/dist/chunk-TCG3UB2T.js.map +1 -0
- package/dist/{chunk-I6VD2JKM.js → chunk-UPVDNR2J.js} +8 -8
- package/dist/engine/cloudBucket/r2Storage.js +1 -3
- package/dist/engine/script/run-all.d.ts +3 -0
- package/dist/engine/script/run-all.js +8 -0
- package/dist/engine/script/run-all.js.map +1 -0
- package/dist/engine/script/run-bucket.d.ts +3 -0
- package/dist/engine/script/run-bucket.js +8 -0
- package/dist/engine/script/run-bucket.js.map +1 -0
- package/dist/engine/script/run-node-server.d.ts +3 -0
- package/dist/engine/script/run-node-server.js +8 -0
- package/dist/engine/script/run-node-server.js.map +1 -0
- package/dist/engine/server/server.js +2 -2
- package/dist/utility/script/run-all.d.ts +2 -0
- package/dist/utility/script/run-all.js +8 -0
- package/dist/utility/script/run-all.js.map +1 -0
- package/dist/utility/script/run-bucket.d.ts +2 -0
- package/dist/utility/script/run-bucket.js +8 -0
- package/dist/utility/script/run-bucket.js.map +1 -0
- package/dist/utility/script/run-node-server.d.ts +2 -0
- package/dist/utility/script/run-node-server.js +8 -0
- package/dist/utility/script/run-node-server.js.map +1 -0
- package/dist/utility/utilis/cloud_storage/deleteFile.js +4 -5
- package/dist/utility/utilis/cloud_storage/deleteFile.js.map +1 -1
- package/dist/utility/utilis/cloud_storage/deleteFiles.js +4 -5
- package/dist/utility/utilis/cloud_storage/deleteFiles.js.map +1 -1
- package/dist/utility/utilis/cloud_storage/downloadFile.js +5 -6
- package/dist/utility/utilis/cloud_storage/downloadFile.js.map +1 -1
- package/dist/utility/utilis/cloud_storage/downloadFiles.js +5 -6
- package/dist/utility/utilis/cloud_storage/downloadFiles.js.map +1 -1
- package/dist/utility/utilis/cloud_storage/s3Client.js +1 -3
- package/dist/utility/utilis/cloud_storage/s3Client.js.map +1 -1
- package/dist/utility/utilis/cloud_storage/uploadFile.js +3 -4
- package/dist/utility/utilis/cloud_storage/uploadFiles.js +3 -4
- package/dist/utility/utilis/cloud_storage/uploadFiles.js.map +1 -1
- package/dist/utility/utilis/server/server.js +2 -2
- package/package.json +5 -4
- package/dist/chunk-GBXVVI2R.js +0 -528
- package/dist/chunk-GBXVVI2R.js.map +0 -1
- package/dist/chunk-IN3YY526.js +0 -165
- package/dist/chunk-IN3YY526.js.map +0 -1
- package/dist/event-streams-PM4LQKAH.js +0 -993
- package/dist/event-streams-PM4LQKAH.js.map +0 -1
- /package/dist/{chunk-NDJVYPUT.js.map → chunk-PRKZ33FU.js.map} +0 -0
- /package/dist/{chunk-I6VD2JKM.js.map → chunk-UPVDNR2J.js.map} +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/engine/cloudBucket/r2Storage.ts
|
|
2
|
+
import { S3Client } from "@aws-sdk/client-s3";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { pathToFileURL } from "url";
|
|
5
|
+
var s3ConfigFilePath = path.join(process.cwd(), "src", "config", "s3bucket.config.ts");
|
|
6
|
+
var { S3_BUCKET_CONFIG } = await import(pathToFileURL(s3ConfigFilePath).href);
|
|
7
|
+
var s3Client = new S3Client(S3_BUCKET_CONFIG);
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
s3Client
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=chunk-3AP6JARL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/engine/cloudBucket/r2Storage.ts"],"sourcesContent":["import { S3Client } from '@aws-sdk/client-s3';\r\nimport path from \"node:path\";\r\nimport {pathToFileURL} from \"node:url\";\r\n\r\n\r\n\r\nconst s3ConfigFilePath = path.join(process.cwd(), 'src', 'config', 's3bucket.config.ts');\r\nconst {S3_BUCKET_CONFIG} = await import(pathToFileURL(s3ConfigFilePath).href)\r\n\r\n\r\n\r\n\r\n\r\n\r\nexport const s3Client: S3Client = new S3Client(S3_BUCKET_CONFIG);\r\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,OAAO,UAAU;AACjB,SAAQ,qBAAoB;AAI5B,IAAM,mBAAmB,KAAK,KAAK,QAAQ,IAAI,GAAG,OAAO,UAAU,oBAAoB;AACvF,IAAM,EAAC,iBAAgB,IAAI,MAAM,OAAO,cAAc,gBAAgB,EAAE;AAOjE,IAAM,WAAqB,IAAI,SAAS,gBAAgB;","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-7QVYU63E.js";
|
|
4
|
+
|
|
5
|
+
// src/engine/script/run-node-server.ts
|
|
6
|
+
import { execSync } from "child_process";
|
|
7
|
+
import path from "path";
|
|
8
|
+
function runNodeServer() {
|
|
9
|
+
execSync("tsx " + path.join(process.cwd(), "node_modules/backfarm/dist/utility/utilis/server/server.js"), {
|
|
10
|
+
cwd: process.cwd(),
|
|
11
|
+
stdio: "inherit"
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
__name(runNodeServer, "runNodeServer");
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
runNodeServer
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=chunk-5A3RVJNT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/engine/script/run-node-server.ts"],"sourcesContent":["import {execSync} from \"node:child_process\";\r\nimport path from \"node:path\";\r\n\r\nexport function runNodeServer () {\r\n execSync(\"tsx \" + path.join(process.cwd() , \"node_modules/backfarm/dist/utility/utilis/server/server.js\"), {\r\n cwd: process.cwd(),\r\n stdio: \"inherit\",\r\n })\r\n}\r\n\r\n"],"mappings":";;;;;AAAA,SAAQ,gBAAe;AACvB,OAAO,UAAU;AAEV,SAAS,gBAAmB;AAC/B,WAAS,SAAS,KAAK,KAAK,QAAQ,IAAI,GAAI,4DAA4D,GAAG;AAAA,IACvG,KAAK,QAAQ,IAAI;AAAA,IACjB,OAAO;AAAA,EACX,CAAC;AACL;AALgB;","names":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-7QVYU63E.js";
|
|
4
|
+
|
|
5
|
+
// src/engine/script/run-bucket.ts
|
|
6
|
+
import { execSync } from "child_process";
|
|
7
|
+
function runBucket() {
|
|
8
|
+
execSync("docker-compose -f ./bucketConfigs/docker-compose.yml up", {
|
|
9
|
+
cwd: process.cwd(),
|
|
10
|
+
stdio: "inherit"
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
__name(runBucket, "runBucket");
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
runBucket
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=chunk-LFRKRR7G.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/engine/script/run-bucket.ts"],"sourcesContent":["import {execSync} from \"node:child_process\";\r\n\r\nexport function runBucket() {\r\n\r\n execSync('docker-compose -f ./bucketConfigs/docker-compose.yml up', {\r\n cwd: process.cwd(),\r\n stdio: \"inherit\",\r\n })\r\n\r\n}\r\n\r\n\r\n"],"mappings":";;;;;AAAA,SAAQ,gBAAe;AAEhB,SAAS,YAAY;AAExB,WAAS,2DAA2D;AAAA,IAChE,KAAK,QAAQ,IAAI;AAAA,IACjB,OAAO;AAAA,EACX,CAAC;AAEL;AAPgB;","names":[]}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
app_default
|
|
3
|
-
} from "./chunk-W2745SOE.js";
|
|
4
1
|
import {
|
|
5
2
|
handleError
|
|
6
3
|
} from "./chunk-P5XJG7OG.js";
|
|
@@ -20,6 +17,9 @@ import {
|
|
|
20
17
|
import {
|
|
21
18
|
ENV
|
|
22
19
|
} from "./chunk-EWQYVPOL.js";
|
|
20
|
+
import {
|
|
21
|
+
app_default
|
|
22
|
+
} from "./chunk-W2745SOE.js";
|
|
23
23
|
import {
|
|
24
24
|
__name
|
|
25
25
|
} from "./chunk-7QVYU63E.js";
|
|
@@ -58,4 +58,4 @@ export {
|
|
|
58
58
|
HTTP_SERVER,
|
|
59
59
|
startServer
|
|
60
60
|
};
|
|
61
|
-
//# sourceMappingURL=chunk-
|
|
61
|
+
//# sourceMappingURL=chunk-PRKZ33FU.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-7QVYU63E.js";
|
|
4
|
+
|
|
5
|
+
// src/engine/script/run-all.ts
|
|
6
|
+
import { execSync } from "child_process";
|
|
7
|
+
import path from "path";
|
|
8
|
+
function runAll() {
|
|
9
|
+
execSync("docker-compose -f ./bucketConfigs/docker-compose.yml up -d", {
|
|
10
|
+
cwd: process.cwd(),
|
|
11
|
+
stdio: "inherit"
|
|
12
|
+
});
|
|
13
|
+
execSync("tsx " + path.join(process.cwd(), "node_modules/backfarm/dist/utility/utilis/server/server.js"), {
|
|
14
|
+
cwd: process.cwd(),
|
|
15
|
+
stdio: "inherit"
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
__name(runAll, "runAll");
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
runAll
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=chunk-TCG3UB2T.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/engine/script/run-all.ts"],"sourcesContent":["import {execSync} from \"node:child_process\";\nimport path from \"node:path\";\n\n\n\nexport function runAll() {\n execSync('docker-compose -f ./bucketConfigs/docker-compose.yml up -d', {\n cwd: process.cwd(),\n stdio: \"inherit\",\n })\n\n execSync(\"tsx \" + path.join(process.cwd() , \"node_modules/backfarm/dist/utility/utilis/server/server.js\"), {\n cwd: process.cwd(),\n stdio: \"inherit\",\n })\n\n}\n\n"],"mappings":";;;;;AAAA,SAAQ,gBAAe;AACvB,OAAO,UAAU;AAIV,SAAS,SAAS;AACrB,WAAS,8DAA8D;AAAA,IACnE,KAAK,QAAQ,IAAI;AAAA,IACjB,OAAO;AAAA,EACX,CAAC;AAED,WAAS,SAAS,KAAK,KAAK,QAAQ,IAAI,GAAI,4DAA4D,GAAG;AAAA,IACvG,KAAK,QAAQ,IAAI;AAAA,IACjB,OAAO;AAAA,EACX,CAAC;AAEL;AAXgB;","names":[]}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildPath,
|
|
3
|
-
getFileContentType,
|
|
4
|
-
getFileExtension,
|
|
5
|
-
toUint8Array
|
|
6
|
-
} from "./chunk-FMCW72HO.js";
|
|
7
1
|
import {
|
|
8
2
|
generateUniqueValue
|
|
9
3
|
} from "./chunk-X3R3RLXY.js";
|
|
10
4
|
import {
|
|
11
5
|
buildURL
|
|
12
6
|
} from "./chunk-SSFPGDA3.js";
|
|
7
|
+
import {
|
|
8
|
+
buildPath,
|
|
9
|
+
getFileContentType,
|
|
10
|
+
getFileExtension,
|
|
11
|
+
toUint8Array
|
|
12
|
+
} from "./chunk-FMCW72HO.js";
|
|
13
13
|
import {
|
|
14
14
|
s3Client
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-3AP6JARL.js";
|
|
16
16
|
import {
|
|
17
17
|
ENV
|
|
18
18
|
} from "./chunk-EWQYVPOL.js";
|
|
@@ -69,4 +69,4 @@ var upload_file = /* @__PURE__ */ __name(async ({ file, path }) => {
|
|
|
69
69
|
export {
|
|
70
70
|
upload_file
|
|
71
71
|
};
|
|
72
|
-
//# sourceMappingURL=chunk-
|
|
72
|
+
//# sourceMappingURL=chunk-UPVDNR2J.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
HTTP_SERVER,
|
|
3
3
|
startServer
|
|
4
|
-
} from "../../chunk-
|
|
5
|
-
import "../../chunk-W2745SOE.js";
|
|
4
|
+
} from "../../chunk-PRKZ33FU.js";
|
|
6
5
|
import "../../chunk-P5XJG7OG.js";
|
|
7
6
|
import "../../chunk-MNSQSU7T.js";
|
|
8
7
|
import "../../chunk-HZ4GLSOO.js";
|
|
9
8
|
import "../../chunk-NMNAPTVV.js";
|
|
10
9
|
import "../../chunk-EB35KLDE.js";
|
|
11
10
|
import "../../chunk-EWQYVPOL.js";
|
|
11
|
+
import "../../chunk-W2745SOE.js";
|
|
12
12
|
import "../../chunk-7QVYU63E.js";
|
|
13
13
|
export {
|
|
14
14
|
HTTP_SERVER,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utility/script/run-all.ts"],"sourcesContent":["import {runAll} from \"../../engine/script/run-all.js\";\r\n\r\n\r\nrunAll()\r\n"],"mappings":";;;;;;AAGA,OAAO;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utility/script/run-bucket.ts"],"sourcesContent":["import {runBucket} from \"../../engine/script/run-bucket.js\";\r\n\r\nrunBucket()\r\n\r\n"],"mappings":";;;;;;AAEA,UAAU;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utility/script/run-node-server.ts"],"sourcesContent":["import {runNodeServer} from \"../../engine/script/run-node-server.js\";\r\n\r\nrunNodeServer()\r\n"],"mappings":";;;;;;AAEA,cAAc;","names":[]}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
url_or_path
|
|
3
|
-
} from "../../../chunk-FMCW72HO.js";
|
|
4
1
|
import {
|
|
5
2
|
getKeyFromUrl
|
|
6
3
|
} from "../../../chunk-SSFPGDA3.js";
|
|
4
|
+
import {
|
|
5
|
+
url_or_path
|
|
6
|
+
} from "../../../chunk-FMCW72HO.js";
|
|
7
7
|
import {
|
|
8
8
|
s3Client
|
|
9
|
-
} from "../../../chunk-
|
|
10
|
-
import "../../../chunk-IN3YY526.js";
|
|
9
|
+
} from "../../../chunk-3AP6JARL.js";
|
|
11
10
|
import {
|
|
12
11
|
ENV
|
|
13
12
|
} from "../../../chunk-EWQYVPOL.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utility/utilis/cloud_storage/deleteFile.ts"],"sourcesContent":["import {ENV} from \"../../libs/env.js\";\r\nimport {url_or_path} from \"../general/file-operations.js\";\r\nimport {getKeyFromUrl} from \"../general/web.js\";\r\nimport {DeleteObjectCommand} from \"@aws-sdk/client-s3\";\r\nimport * as fs from \"node:fs\";\r\nimport type {DeleteFile} from \"../../libs/interface.js\";\r\nimport {s3Client} from \"../../../engine/cloudBucket/r2Storage.js\";\r\n\r\nexport const deleteFile = async (item_file: string): Promise<DeleteFile> => {\r\n try {\r\n const fileType = url_or_path(item_file);\r\n\r\n if (fileType === ENV.URL) {\r\n // Extract the MinIO object key from the full public URL\r\n const key = getKeyFromUrl(item_file);\r\n\r\n const command = new DeleteObjectCommand({\r\n Bucket: ENV.BUCKET_NAME,\r\n Key: key,\r\n });\r\n\r\n await s3Client.send(command);\r\n return {\r\n status: true,\r\n url_or_path: item_file,\r\n }\r\n }\r\n\r\n if (fileType === ENV.PATH) {\r\n // Check if file exists locally before unlinking\r\n if (fs.existsSync(item_file)) {\r\n await fs.promises.unlink(item_file);\r\n }\r\n return {\r\n status: true,\r\n url_or_path: item_file,\r\n }\r\n }\r\n\r\n return {\r\n url_or_path: item_file,\r\n status: false,\r\n }\r\n } catch (error) {\r\n return {\r\n status: false,\r\n url_or_path: item_file,\r\n error: error,\r\n }\r\n }\r\n};\r\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/utility/utilis/cloud_storage/deleteFile.ts"],"sourcesContent":["import {ENV} from \"../../libs/env.js\";\r\nimport {url_or_path} from \"../general/file-operations.js\";\r\nimport {getKeyFromUrl} from \"../general/web.js\";\r\nimport {DeleteObjectCommand} from \"@aws-sdk/client-s3\";\r\nimport * as fs from \"node:fs\";\r\nimport type {DeleteFile} from \"../../libs/interface.js\";\r\nimport {s3Client} from \"../../../engine/cloudBucket/r2Storage.js\";\r\n\r\nexport const deleteFile = async (item_file: string): Promise<DeleteFile> => {\r\n try {\r\n const fileType = url_or_path(item_file);\r\n\r\n if (fileType === ENV.URL) {\r\n // Extract the MinIO object key from the full public URL\r\n const key = getKeyFromUrl(item_file);\r\n\r\n const command = new DeleteObjectCommand({\r\n Bucket: ENV.BUCKET_NAME,\r\n Key: key,\r\n });\r\n\r\n await s3Client.send(command);\r\n return {\r\n status: true,\r\n url_or_path: item_file,\r\n }\r\n }\r\n\r\n if (fileType === ENV.PATH) {\r\n // Check if file exists locally before unlinking\r\n if (fs.existsSync(item_file)) {\r\n await fs.promises.unlink(item_file);\r\n }\r\n return {\r\n status: true,\r\n url_or_path: item_file,\r\n }\r\n }\r\n\r\n return {\r\n url_or_path: item_file,\r\n status: false,\r\n }\r\n } catch (error) {\r\n return {\r\n status: false,\r\n url_or_path: item_file,\r\n error: error,\r\n }\r\n }\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;AAGA,SAAQ,2BAA0B;AAClC,YAAY,QAAQ;AAIb,IAAM,aAAa,8BAAO,cAA2C;AACxE,MAAI;AACA,UAAM,WAAW,YAAY,SAAS;AAEtC,QAAI,aAAa,IAAI,KAAK;AAEtB,YAAM,MAAM,cAAc,SAAS;AAEnC,YAAM,UAAU,IAAI,oBAAoB;AAAA,QACpC,QAAQ,IAAI;AAAA,QACZ,KAAK;AAAA,MACT,CAAC;AAED,YAAM,SAAS,KAAK,OAAO;AAC3B,aAAO;AAAA,QACH,QAAQ;AAAA,QACR,aAAa;AAAA,MACjB;AAAA,IACJ;AAEA,QAAI,aAAa,IAAI,MAAM;AAEvB,UAAO,cAAW,SAAS,GAAG;AAC1B,cAAS,YAAS,OAAO,SAAS;AAAA,MACtC;AACA,aAAO;AAAA,QACH,QAAQ;AAAA,QACR,aAAa;AAAA,MACjB;AAAA,IACJ;AAEA,WAAO;AAAA,MACH,aAAa;AAAA,MACb,QAAQ;AAAA,IACZ;AAAA,EACJ,SAAS,OAAO;AACZ,WAAO;AAAA,MACH,QAAQ;AAAA,MACR,aAAa;AAAA,MACb;AAAA,IACJ;AAAA,EACJ;AACJ,GA1C0B;","names":[]}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
url_or_path
|
|
3
|
-
} from "../../../chunk-FMCW72HO.js";
|
|
4
1
|
import {
|
|
5
2
|
getKeyFromUrl
|
|
6
3
|
} from "../../../chunk-SSFPGDA3.js";
|
|
4
|
+
import {
|
|
5
|
+
url_or_path
|
|
6
|
+
} from "../../../chunk-FMCW72HO.js";
|
|
7
7
|
import {
|
|
8
8
|
s3Client
|
|
9
|
-
} from "../../../chunk-
|
|
10
|
-
import "../../../chunk-IN3YY526.js";
|
|
9
|
+
} from "../../../chunk-3AP6JARL.js";
|
|
11
10
|
import {
|
|
12
11
|
ENV
|
|
13
12
|
} from "../../../chunk-EWQYVPOL.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utility/utilis/cloud_storage/deleteFiles.ts"],"sourcesContent":["import {ENV} from \"../../libs/env.js\";\r\nimport {url_or_path} from \"../general/file-operations.js\";\r\nimport {getKeyFromUrl} from \"../general/web.js\";\r\nimport {DeleteObjectCommand} from \"@aws-sdk/client-s3\";\r\nimport * as fs from \"node:fs\";\r\nimport type {DeleteFiles} from \"../../libs/interface.js\";\r\nimport {s3Client} from \"../../../engine/cloudBucket/r2Storage.js\";\r\n\r\nexport const deleteFiles = async (item_files: string[]): Promise<DeleteFiles> => {\r\n // Early return for empty array\r\n if (!item_files || item_files.length === 0) {\r\n return { items: [] };\r\n }\r\n\r\n // Optional: Deduplicate files to avoid redundant operations\r\n const uniqueFiles = [...new Set(item_files)];\r\n\r\n // Optional: Limit concurrency to avoid overwhelming the system\r\n const BATCH_SIZE = 50; // Adjust based on your needs\r\n const results: DeleteFiles['items'] = [];\r\n\r\n const deleteSingleFile = async (item_file: string): Promise<DeleteFiles['items'][0]> => {\r\n try {\r\n const fileType = url_or_path(item_file);\r\n\r\n if (fileType === ENV.URL) {\r\n const key = getKeyFromUrl(item_file);\r\n const command = new DeleteObjectCommand({\r\n Bucket: ENV.BUCKET_NAME,\r\n Key: key,\r\n });\r\n await s3Client.send(command);\r\n return {\r\n url_or_path: item_file,\r\n status: true,\r\n };\r\n }\r\n\r\n if (fileType === ENV.PATH) {\r\n try {\r\n await fs.promises.access(item_file);\r\n await fs.promises.unlink(item_file);\r\n } catch (accessError) {\r\n // File doesn't exist - consider this a success (idempotent)\r\n }\r\n return {\r\n url_or_path: item_file,\r\n status: true,\r\n };\r\n }\r\n\r\n return {\r\n url_or_path: item_file,\r\n status: false,\r\n };\r\n } catch (error) {\r\n return {\r\n url_or_path: item_file,\r\n status: false,\r\n error: error,\r\n };\r\n }\r\n };\r\n\r\n // Process in batches to control memory/connection usage\r\n for (let i = 0; i < uniqueFiles.length; i += BATCH_SIZE) {\r\n const batch = uniqueFiles.slice(i, i + BATCH_SIZE);\r\n const batchResults = await Promise.allSettled(\r\n batch.map(file => deleteSingleFile(file))\r\n );\r\n\r\n batchResults.forEach((result, index) => {\r\n if (result.status === 'fulfilled') {\r\n results.push(result.value);\r\n } else {\r\n // result.reason should never happen with allSettled, but handle it anyway\r\n results.push({\r\n url_or_path: batch[index] || 'unknown', // Provide fallback\r\n status: false,\r\n error: result.reason,\r\n });\r\n }\r\n });\r\n }\r\n\r\n return { items: results };\r\n};\r\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/utility/utilis/cloud_storage/deleteFiles.ts"],"sourcesContent":["import {ENV} from \"../../libs/env.js\";\r\nimport {url_or_path} from \"../general/file-operations.js\";\r\nimport {getKeyFromUrl} from \"../general/web.js\";\r\nimport {DeleteObjectCommand} from \"@aws-sdk/client-s3\";\r\nimport * as fs from \"node:fs\";\r\nimport type {DeleteFiles} from \"../../libs/interface.js\";\r\nimport {s3Client} from \"../../../engine/cloudBucket/r2Storage.js\";\r\n\r\nexport const deleteFiles = async (item_files: string[]): Promise<DeleteFiles> => {\r\n // Early return for empty array\r\n if (!item_files || item_files.length === 0) {\r\n return { items: [] };\r\n }\r\n\r\n // Optional: Deduplicate files to avoid redundant operations\r\n const uniqueFiles = [...new Set(item_files)];\r\n\r\n // Optional: Limit concurrency to avoid overwhelming the system\r\n const BATCH_SIZE = 50; // Adjust based on your needs\r\n const results: DeleteFiles['items'] = [];\r\n\r\n const deleteSingleFile = async (item_file: string): Promise<DeleteFiles['items'][0]> => {\r\n try {\r\n const fileType = url_or_path(item_file);\r\n\r\n if (fileType === ENV.URL) {\r\n const key = getKeyFromUrl(item_file);\r\n const command = new DeleteObjectCommand({\r\n Bucket: ENV.BUCKET_NAME,\r\n Key: key,\r\n });\r\n await s3Client.send(command);\r\n return {\r\n url_or_path: item_file,\r\n status: true,\r\n };\r\n }\r\n\r\n if (fileType === ENV.PATH) {\r\n try {\r\n await fs.promises.access(item_file);\r\n await fs.promises.unlink(item_file);\r\n } catch (accessError) {\r\n // File doesn't exist - consider this a success (idempotent)\r\n }\r\n return {\r\n url_or_path: item_file,\r\n status: true,\r\n };\r\n }\r\n\r\n return {\r\n url_or_path: item_file,\r\n status: false,\r\n };\r\n } catch (error) {\r\n return {\r\n url_or_path: item_file,\r\n status: false,\r\n error: error,\r\n };\r\n }\r\n };\r\n\r\n // Process in batches to control memory/connection usage\r\n for (let i = 0; i < uniqueFiles.length; i += BATCH_SIZE) {\r\n const batch = uniqueFiles.slice(i, i + BATCH_SIZE);\r\n const batchResults = await Promise.allSettled(\r\n batch.map(file => deleteSingleFile(file))\r\n );\r\n\r\n batchResults.forEach((result, index) => {\r\n if (result.status === 'fulfilled') {\r\n results.push(result.value);\r\n } else {\r\n // result.reason should never happen with allSettled, but handle it anyway\r\n results.push({\r\n url_or_path: batch[index] || 'unknown', // Provide fallback\r\n status: false,\r\n error: result.reason,\r\n });\r\n }\r\n });\r\n }\r\n\r\n return { items: results };\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;AAGA,SAAQ,2BAA0B;AAClC,YAAY,QAAQ;AAIb,IAAM,cAAc,8BAAO,eAA+C;AAE7E,MAAI,CAAC,cAAc,WAAW,WAAW,GAAG;AACxC,WAAO,EAAE,OAAO,CAAC,EAAE;AAAA,EACvB;AAGA,QAAM,cAAc,CAAC,GAAG,IAAI,IAAI,UAAU,CAAC;AAG3C,QAAM,aAAa;AACnB,QAAM,UAAgC,CAAC;AAEvC,QAAM,mBAAmB,8BAAO,cAAwD;AACpF,QAAI;AACA,YAAM,WAAW,YAAY,SAAS;AAEtC,UAAI,aAAa,IAAI,KAAK;AACtB,cAAM,MAAM,cAAc,SAAS;AACnC,cAAM,UAAU,IAAI,oBAAoB;AAAA,UACpC,QAAQ,IAAI;AAAA,UACZ,KAAK;AAAA,QACT,CAAC;AACD,cAAM,SAAS,KAAK,OAAO;AAC3B,eAAO;AAAA,UACH,aAAa;AAAA,UACb,QAAQ;AAAA,QACZ;AAAA,MACJ;AAEA,UAAI,aAAa,IAAI,MAAM;AACvB,YAAI;AACA,gBAAS,YAAS,OAAO,SAAS;AAClC,gBAAS,YAAS,OAAO,SAAS;AAAA,QACtC,SAAS,aAAa;AAAA,QAEtB;AACA,eAAO;AAAA,UACH,aAAa;AAAA,UACb,QAAQ;AAAA,QACZ;AAAA,MACJ;AAEA,aAAO;AAAA,QACH,aAAa;AAAA,QACb,QAAQ;AAAA,MACZ;AAAA,IACJ,SAAS,OAAO;AACZ,aAAO;AAAA,QACH,aAAa;AAAA,QACb,QAAQ;AAAA,QACR;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ,GAzCyB;AA4CzB,WAAS,IAAI,GAAG,IAAI,YAAY,QAAQ,KAAK,YAAY;AACrD,UAAM,QAAQ,YAAY,MAAM,GAAG,IAAI,UAAU;AACjD,UAAM,eAAe,MAAM,QAAQ;AAAA,MAC/B,MAAM,IAAI,UAAQ,iBAAiB,IAAI,CAAC;AAAA,IAC5C;AAEA,iBAAa,QAAQ,CAAC,QAAQ,UAAU;AACpC,UAAI,OAAO,WAAW,aAAa;AAC/B,gBAAQ,KAAK,OAAO,KAAK;AAAA,MAC7B,OAAO;AAEH,gBAAQ,KAAK;AAAA,UACT,aAAa,MAAM,KAAK,KAAK;AAAA;AAAA,UAC7B,QAAQ;AAAA,UACR,OAAO,OAAO;AAAA,QAClB,CAAC;AAAA,MACL;AAAA,IACJ,CAAC;AAAA,EACL;AAEA,SAAO,EAAE,OAAO,QAAQ;AAC5B,GA9E2B;","names":[]}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
downloadedFilePath,
|
|
3
|
-
getFileExtension
|
|
4
|
-
} from "../../../chunk-FMCW72HO.js";
|
|
5
1
|
import {
|
|
6
2
|
generateUniqueValue
|
|
7
3
|
} from "../../../chunk-X3R3RLXY.js";
|
|
8
4
|
import {
|
|
9
5
|
getKeyFromUrl
|
|
10
6
|
} from "../../../chunk-SSFPGDA3.js";
|
|
7
|
+
import {
|
|
8
|
+
downloadedFilePath,
|
|
9
|
+
getFileExtension
|
|
10
|
+
} from "../../../chunk-FMCW72HO.js";
|
|
11
11
|
import {
|
|
12
12
|
s3Client
|
|
13
|
-
} from "../../../chunk-
|
|
14
|
-
import "../../../chunk-IN3YY526.js";
|
|
13
|
+
} from "../../../chunk-3AP6JARL.js";
|
|
15
14
|
import {
|
|
16
15
|
ENV
|
|
17
16
|
} from "../../../chunk-EWQYVPOL.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utility/utilis/cloud_storage/downloadFile.ts"],"sourcesContent":["import {GetObjectCommand} from \"@aws-sdk/client-s3\";\r\nimport {getKeyFromUrl} from \"../general/web.js\";\r\nimport { pipeline } from \"stream/promises\";\r\nimport path from 'node:path'\r\nimport fsPromises from 'fs/promises';\r\nimport * as fs from \"node:fs\";\r\nimport type {DownloadedFile, DownloadFileParams} from \"../../libs/interface.js\";\r\nimport {ENV} from \"../../libs/env.js\";\r\nimport {downloadedFilePath, getFileExtension} from \"../general/file-operations.js\";\r\nimport {generateUniqueValue} from \"../general/uuids.js\";\r\nimport {s3Client} from \"../../../engine/cloudBucket/r2Storage.js\";\r\n\r\n\r\n\r\nexport const downloadFile = async ({\r\n url,\r\n outputPath,\r\n }: DownloadFileParams): Promise<DownloadedFile> => {\r\n try {\r\n const key = getKeyFromUrl(url);\r\n\r\n const command = new GetObjectCommand({\r\n Bucket: ENV.BUCKET_NAME,\r\n Key: key,\r\n });\r\n\r\n const response = await s3Client.send(command);\r\n\r\n if (!response.Body) {\r\n console.log(response);\r\n return {\r\n status: true,\r\n url: url,\r\n error: new Error(`Empty response body received for key: ${key}`),\r\n };\r\n }\r\n\r\n const fileExtension = getFileExtension(url);\r\n const fileName = generateUniqueValue(16);\r\n const finalFileName = `${fileName}.${fileExtension}`;\r\n const targetPath = downloadedFilePath({ path: outputPath || [], fileName: finalFileName });\r\n\r\n // Ensure directory structure exists for targetPath\r\n const dir = path.dirname(targetPath);\r\n if (!fs.existsSync(dir)) {\r\n await fsPromises.mkdir(dir, { recursive: true });\r\n }\r\n\r\n // Cast stream to NodeJS.ReadableStream for pipeline overload\r\n const stream = response.Body as NodeJS.ReadableStream;\r\n await pipeline(stream, fs.createWriteStream(targetPath));\r\n\r\n return {\r\n status: true,\r\n url: url,\r\n path: targetPath,\r\n };\r\n\r\n } catch (error) {\r\n console.error(error);\r\n return {\r\n status: false,\r\n url: url,\r\n error: error instanceof Error ? error : new Error(String(error)),\r\n };\r\n }\r\n};\r\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/utility/utilis/cloud_storage/downloadFile.ts"],"sourcesContent":["import {GetObjectCommand} from \"@aws-sdk/client-s3\";\r\nimport {getKeyFromUrl} from \"../general/web.js\";\r\nimport { pipeline } from \"stream/promises\";\r\nimport path from 'node:path'\r\nimport fsPromises from 'fs/promises';\r\nimport * as fs from \"node:fs\";\r\nimport type {DownloadedFile, DownloadFileParams} from \"../../libs/interface.js\";\r\nimport {ENV} from \"../../libs/env.js\";\r\nimport {downloadedFilePath, getFileExtension} from \"../general/file-operations.js\";\r\nimport {generateUniqueValue} from \"../general/uuids.js\";\r\nimport {s3Client} from \"../../../engine/cloudBucket/r2Storage.js\";\r\n\r\n\r\n\r\nexport const downloadFile = async ({\r\n url,\r\n outputPath,\r\n }: DownloadFileParams): Promise<DownloadedFile> => {\r\n try {\r\n const key = getKeyFromUrl(url);\r\n\r\n const command = new GetObjectCommand({\r\n Bucket: ENV.BUCKET_NAME,\r\n Key: key,\r\n });\r\n\r\n const response = await s3Client.send(command);\r\n\r\n if (!response.Body) {\r\n console.log(response);\r\n return {\r\n status: true,\r\n url: url,\r\n error: new Error(`Empty response body received for key: ${key}`),\r\n };\r\n }\r\n\r\n const fileExtension = getFileExtension(url);\r\n const fileName = generateUniqueValue(16);\r\n const finalFileName = `${fileName}.${fileExtension}`;\r\n const targetPath = downloadedFilePath({ path: outputPath || [], fileName: finalFileName });\r\n\r\n // Ensure directory structure exists for targetPath\r\n const dir = path.dirname(targetPath);\r\n if (!fs.existsSync(dir)) {\r\n await fsPromises.mkdir(dir, { recursive: true });\r\n }\r\n\r\n // Cast stream to NodeJS.ReadableStream for pipeline overload\r\n const stream = response.Body as NodeJS.ReadableStream;\r\n await pipeline(stream, fs.createWriteStream(targetPath));\r\n\r\n return {\r\n status: true,\r\n url: url,\r\n path: targetPath,\r\n };\r\n\r\n } catch (error) {\r\n console.error(error);\r\n return {\r\n status: false,\r\n url: url,\r\n error: error instanceof Error ? error : new Error(String(error)),\r\n };\r\n }\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,SAAQ,wBAAuB;AAE/B,SAAS,gBAAgB;AACzB,OAAO,UAAU;AACjB,OAAO,gBAAgB;AACvB,YAAY,QAAQ;AASb,IAAM,eAAe,8BAAO;AAAA,EACI;AAAA,EACA;AACJ,MAAmD;AAClF,MAAI;AACA,UAAM,MAAM,cAAc,GAAG;AAE7B,UAAM,UAAU,IAAI,iBAAiB;AAAA,MACjC,QAAQ,IAAI;AAAA,MACZ,KAAK;AAAA,IACT,CAAC;AAED,UAAM,WAAW,MAAM,SAAS,KAAK,OAAO;AAE5C,QAAI,CAAC,SAAS,MAAM;AAChB,cAAQ,IAAI,QAAQ;AACpB,aAAO;AAAA,QACH,QAAQ;AAAA,QACR;AAAA,QACA,OAAO,IAAI,MAAM,yCAAyC,GAAG,EAAE;AAAA,MACnE;AAAA,IACJ;AAEA,UAAM,gBAAgB,iBAAiB,GAAG;AAC1C,UAAM,WAAW,oBAAoB,EAAE;AACvC,UAAM,gBAAgB,GAAG,QAAQ,IAAI,aAAa;AAClD,UAAM,aAAa,mBAAmB,EAAE,MAAM,cAAc,CAAC,GAAG,UAAU,cAAc,CAAC;AAGzF,UAAM,MAAM,KAAK,QAAQ,UAAU;AACnC,QAAI,CAAI,cAAW,GAAG,GAAG;AACrB,YAAM,WAAW,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,IACnD;AAGA,UAAM,SAAS,SAAS;AACxB,UAAM,SAAS,QAAW,qBAAkB,UAAU,CAAC;AAEvD,WAAO;AAAA,MACH,QAAQ;AAAA,MACR;AAAA,MACA,MAAM;AAAA,IACV;AAAA,EAEJ,SAAS,OAAO;AACZ,YAAQ,MAAM,KAAK;AACnB,WAAO;AAAA,MACH,QAAQ;AAAA,MACR;AAAA,MACA,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AAAA,IACnE;AAAA,EACJ;AACJ,GApD4B;","names":[]}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
downloadedFilePath,
|
|
3
|
-
getFileExtension
|
|
4
|
-
} from "../../../chunk-FMCW72HO.js";
|
|
5
1
|
import {
|
|
6
2
|
generateUniqueValue
|
|
7
3
|
} from "../../../chunk-X3R3RLXY.js";
|
|
8
4
|
import {
|
|
9
5
|
getKeyFromUrl
|
|
10
6
|
} from "../../../chunk-SSFPGDA3.js";
|
|
7
|
+
import {
|
|
8
|
+
downloadedFilePath,
|
|
9
|
+
getFileExtension
|
|
10
|
+
} from "../../../chunk-FMCW72HO.js";
|
|
11
11
|
import {
|
|
12
12
|
s3Client
|
|
13
|
-
} from "../../../chunk-
|
|
14
|
-
import "../../../chunk-IN3YY526.js";
|
|
13
|
+
} from "../../../chunk-3AP6JARL.js";
|
|
15
14
|
import {
|
|
16
15
|
ENV
|
|
17
16
|
} from "../../../chunk-EWQYVPOL.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utility/utilis/cloud_storage/downloadFiles.ts"],"sourcesContent":["import type {DownloadedFile, DownloadFilesParams} from \"../../libs/interface.js\";\r\nimport {getKeyFromUrl} from \"../general/web.js\";\r\nimport {GetObjectCommand} from \"@aws-sdk/client-s3\";\r\nimport {ENV} from \"../../libs/env.js\";\r\nimport {downloadedFilePath, getFileExtension} from \"../general/file-operations.js\";\r\nimport path from \"node:path\";\r\nimport fsPromises from \"fs/promises\";\r\nimport * as fs from \"node:fs\";\r\nimport {pipeline} from \"stream/promises\";\r\nimport {generateUniqueValue} from \"../general/uuids.js\";\r\nimport {s3Client} from \"../../../engine/cloudBucket/r2Storage.js\";\r\n\r\nexport const downloadFiles = async ({\r\n files,\r\n globalPath,\r\n }: DownloadFilesParams): Promise<DownloadedFile[]> => {\r\n // 1. Validate path conflict rule upfront\r\n const hasIndividualOutputPath = files.some(\r\n (file) => file.outputPath && file.outputPath.length > 0\r\n );\r\n\r\n if (globalPath && hasIndividualOutputPath) {\r\n throw new Error(\r\n \"Conflict: Cannot specify both 'globalPath' and individual 'outputPath' on files.\"\r\n );\r\n }\r\n\r\n // 2. Process all files independently in parallel\r\n const downloadPromises = files.map(async (file): Promise<DownloadedFile> => {\r\n const { url, outputPath } = file;\r\n\r\n try {\r\n const key = getKeyFromUrl(url);\r\n\r\n const command = new GetObjectCommand({\r\n Bucket: ENV.BUCKET_NAME,\r\n Key: key,\r\n });\r\n\r\n const response = await s3Client.send(command);\r\n\r\n if (!response.Body) {\r\n return {\r\n status: false,\r\n url: url,\r\n error: new Error(`Empty response body received for key: ${key}`),\r\n };\r\n }\r\n\r\n const fileExtension = getFileExtension(url);\r\n const fileName = generateUniqueValue(16);\r\n const finalFileName = `${fileName}.${fileExtension}`;\r\n\r\n // Resolve target path using either file's outputPath or globalPath\r\n const resolvedPathSegments = outputPath || (globalPath ? [globalPath] : []);\r\n const targetPath = downloadedFilePath({\r\n path: resolvedPathSegments,\r\n fileName: finalFileName,\r\n });\r\n\r\n // Ensure output folder structure exists\r\n const dir = path.dirname(targetPath);\r\n if (!fs.existsSync(dir)) {\r\n await fsPromises.mkdir(dir, { recursive: true });\r\n }\r\n\r\n // Stream response body directly to file\r\n const stream = response.Body as NodeJS.ReadableStream;\r\n await pipeline(stream, fs.createWriteStream(targetPath));\r\n\r\n return {\r\n status: true,\r\n url: url,\r\n path: targetPath,\r\n };\r\n } catch (error) {\r\n return {\r\n status: false,\r\n url: url,\r\n error: error instanceof Error ? error : new Error(String(error)),\r\n };\r\n }\r\n });\r\n\r\n return Promise.all(downloadPromises);\r\n};\r\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/utility/utilis/cloud_storage/downloadFiles.ts"],"sourcesContent":["import type {DownloadedFile, DownloadFilesParams} from \"../../libs/interface.js\";\r\nimport {getKeyFromUrl} from \"../general/web.js\";\r\nimport {GetObjectCommand} from \"@aws-sdk/client-s3\";\r\nimport {ENV} from \"../../libs/env.js\";\r\nimport {downloadedFilePath, getFileExtension} from \"../general/file-operations.js\";\r\nimport path from \"node:path\";\r\nimport fsPromises from \"fs/promises\";\r\nimport * as fs from \"node:fs\";\r\nimport {pipeline} from \"stream/promises\";\r\nimport {generateUniqueValue} from \"../general/uuids.js\";\r\nimport {s3Client} from \"../../../engine/cloudBucket/r2Storage.js\";\r\n\r\nexport const downloadFiles = async ({\r\n files,\r\n globalPath,\r\n }: DownloadFilesParams): Promise<DownloadedFile[]> => {\r\n // 1. Validate path conflict rule upfront\r\n const hasIndividualOutputPath = files.some(\r\n (file) => file.outputPath && file.outputPath.length > 0\r\n );\r\n\r\n if (globalPath && hasIndividualOutputPath) {\r\n throw new Error(\r\n \"Conflict: Cannot specify both 'globalPath' and individual 'outputPath' on files.\"\r\n );\r\n }\r\n\r\n // 2. Process all files independently in parallel\r\n const downloadPromises = files.map(async (file): Promise<DownloadedFile> => {\r\n const { url, outputPath } = file;\r\n\r\n try {\r\n const key = getKeyFromUrl(url);\r\n\r\n const command = new GetObjectCommand({\r\n Bucket: ENV.BUCKET_NAME,\r\n Key: key,\r\n });\r\n\r\n const response = await s3Client.send(command);\r\n\r\n if (!response.Body) {\r\n return {\r\n status: false,\r\n url: url,\r\n error: new Error(`Empty response body received for key: ${key}`),\r\n };\r\n }\r\n\r\n const fileExtension = getFileExtension(url);\r\n const fileName = generateUniqueValue(16);\r\n const finalFileName = `${fileName}.${fileExtension}`;\r\n\r\n // Resolve target path using either file's outputPath or globalPath\r\n const resolvedPathSegments = outputPath || (globalPath ? [globalPath] : []);\r\n const targetPath = downloadedFilePath({\r\n path: resolvedPathSegments,\r\n fileName: finalFileName,\r\n });\r\n\r\n // Ensure output folder structure exists\r\n const dir = path.dirname(targetPath);\r\n if (!fs.existsSync(dir)) {\r\n await fsPromises.mkdir(dir, { recursive: true });\r\n }\r\n\r\n // Stream response body directly to file\r\n const stream = response.Body as NodeJS.ReadableStream;\r\n await pipeline(stream, fs.createWriteStream(targetPath));\r\n\r\n return {\r\n status: true,\r\n url: url,\r\n path: targetPath,\r\n };\r\n } catch (error) {\r\n return {\r\n status: false,\r\n url: url,\r\n error: error instanceof Error ? error : new Error(String(error)),\r\n };\r\n }\r\n });\r\n\r\n return Promise.all(downloadPromises);\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAEA,SAAQ,wBAAuB;AAG/B,OAAO,UAAU;AACjB,OAAO,gBAAgB;AACvB,YAAY,QAAQ;AACpB,SAAQ,gBAAe;AAIhB,IAAM,gBAAgB,8BAAO;AAAA,EACI;AAAA,EACA;AACJ,MAAsD;AAEtF,QAAM,0BAA0B,MAAM;AAAA,IAClC,CAAC,SAAS,KAAK,cAAc,KAAK,WAAW,SAAS;AAAA,EAC1D;AAEA,MAAI,cAAc,yBAAyB;AACvC,UAAM,IAAI;AAAA,MACN;AAAA,IACJ;AAAA,EACJ;AAGA,QAAM,mBAAmB,MAAM,IAAI,OAAO,SAAkC;AACxE,UAAM,EAAE,KAAK,WAAW,IAAI;AAE5B,QAAI;AACA,YAAM,MAAM,cAAc,GAAG;AAE7B,YAAM,UAAU,IAAI,iBAAiB;AAAA,QACjC,QAAQ,IAAI;AAAA,QACZ,KAAK;AAAA,MACT,CAAC;AAED,YAAM,WAAW,MAAM,SAAS,KAAK,OAAO;AAE5C,UAAI,CAAC,SAAS,MAAM;AAChB,eAAO;AAAA,UACH,QAAQ;AAAA,UACR;AAAA,UACA,OAAO,IAAI,MAAM,yCAAyC,GAAG,EAAE;AAAA,QACnE;AAAA,MACJ;AAEA,YAAM,gBAAgB,iBAAiB,GAAG;AAC1C,YAAM,WAAW,oBAAoB,EAAE;AACvC,YAAM,gBAAgB,GAAG,QAAQ,IAAI,aAAa;AAGlD,YAAM,uBAAuB,eAAe,aAAa,CAAC,UAAU,IAAI,CAAC;AACzE,YAAM,aAAa,mBAAmB;AAAA,QAClC,MAAM;AAAA,QACN,UAAU;AAAA,MACd,CAAC;AAGD,YAAM,MAAM,KAAK,QAAQ,UAAU;AACnC,UAAI,CAAI,cAAW,GAAG,GAAG;AACrB,cAAM,WAAW,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,MACnD;AAGA,YAAM,SAAS,SAAS;AACxB,YAAM,SAAS,QAAW,qBAAkB,UAAU,CAAC;AAEvD,aAAO;AAAA,QACH,QAAQ;AAAA,QACR;AAAA,QACA,MAAM;AAAA,MACV;AAAA,IACJ,SAAS,OAAO;AACZ,aAAO;AAAA,QACH,QAAQ;AAAA,QACR;AAAA,QACA,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AAAA,MACnE;AAAA,IACJ;AAAA,EACJ,CAAC;AAED,SAAO,QAAQ,IAAI,gBAAgB;AACvC,GAzE6B;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utility/utilis/cloud_storage/s3Client.ts"],"sourcesContent":["import {s3Client as sss} from \"../../../engine/cloudBucket/r2Storage.js\";\r\nimport type {S3Client} from \"@aws-sdk/client-s3\";\r\n\r\nexport const getS3Client = async (): Promise<S3Client> => {\r\n return sss;\r\n}\r\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/utility/utilis/cloud_storage/s3Client.ts"],"sourcesContent":["import {s3Client as sss} from \"../../../engine/cloudBucket/r2Storage.js\";\r\nimport type {S3Client} from \"@aws-sdk/client-s3\";\r\n\r\nexport const getS3Client = async (): Promise<S3Client> => {\r\n return sss;\r\n}\r\n"],"mappings":";;;;;;;;AAGO,IAAM,cAAc,mCAA+B;AACtD,SAAO;AACX,GAF2B;","names":[]}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
upload_file
|
|
3
|
-
} from "../../../chunk-
|
|
4
|
-
import "../../../chunk-FMCW72HO.js";
|
|
3
|
+
} from "../../../chunk-UPVDNR2J.js";
|
|
5
4
|
import "../../../chunk-X3R3RLXY.js";
|
|
6
5
|
import "../../../chunk-SSFPGDA3.js";
|
|
7
|
-
import "../../../chunk-
|
|
8
|
-
import "../../../chunk-
|
|
6
|
+
import "../../../chunk-FMCW72HO.js";
|
|
7
|
+
import "../../../chunk-3AP6JARL.js";
|
|
9
8
|
import "../../../chunk-EWQYVPOL.js";
|
|
10
9
|
import "../../../chunk-7QVYU63E.js";
|
|
11
10
|
export {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
upload_file
|
|
3
|
-
} from "../../../chunk-
|
|
4
|
-
import "../../../chunk-FMCW72HO.js";
|
|
3
|
+
} from "../../../chunk-UPVDNR2J.js";
|
|
5
4
|
import "../../../chunk-X3R3RLXY.js";
|
|
6
5
|
import "../../../chunk-SSFPGDA3.js";
|
|
7
|
-
import "../../../chunk-
|
|
8
|
-
import "../../../chunk-
|
|
6
|
+
import "../../../chunk-FMCW72HO.js";
|
|
7
|
+
import "../../../chunk-3AP6JARL.js";
|
|
9
8
|
import "../../../chunk-EWQYVPOL.js";
|
|
10
9
|
import {
|
|
11
10
|
__name
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utility/utilis/cloud_storage/uploadFiles.ts"],"sourcesContent":["import type {FilesUploadedResponseData, UploadFilesInput} from \"../../libs/interface.js\";\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nimport pLimit from 'p-limit';\r\nimport {upload_file} from \"./uploadFile.js\";\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n/**\r\n * Uploads multiple files to the configured S3-compatible storage bucket\r\n * concurrently with a configurable concurrency limit.\r\n *\r\n * Each file is uploaded using the `upload_file` function. A global path can\r\n * be applied to all files, or each file can specify its own individual path,\r\n * but both options cannot be used at the same time.\r\n *\r\n * Failed uploads are collected separately from successful uploads, allowing\r\n * the caller to inspect the result of every individual file without stopping\r\n * the entire batch operation.\r\n *\r\n * @param params - Configuration options for the batch upload.\r\n * @param params.files - The files to upload along with their optional paths.\r\n * @param params.globalPath - An optional path applied to all files that do\r\n * not specify an individual path.\r\n * @param params.concurrency - The maximum number of files uploaded\r\n * concurrently. Defaults to `5`.\r\n * @returns A promise resolving to a `FilesUploadedResponseData` containing\r\n * separate arrays of successfully uploaded and failed files.\r\n * @throws {Error} If both `globalPath` and an individual file `path` are\r\n * provided.\r\n *\r\n * @example\r\n * const result = await upload_files({\r\n * files: [\r\n * { file: file1 },\r\n * { file: file2 },\r\n * { file: file3 },\r\n * ],\r\n * globalPath: ['temporary_files'],\r\n * concurrency: 5,\r\n * });\r\n *\r\n * console.log('Successful uploads:', result.successFiles);\r\n * console.log('Failed uploads:', result.failedFiles);\r\n *\r\n * @example\r\n * const result = await upload_files({\r\n * files: [\r\n * {\r\n * file: file1,\r\n * path: ['documents', 'reports'],\r\n * },\r\n * {\r\n * file: file2,\r\n * path: ['documents', 'images'],\r\n * },\r\n * ],\r\n * concurrency: 10,\r\n * });\r\n *\r\n * @example\r\n * // This throws because globalPath and an individual path cannot be used together.\r\n * const result = await upload_files({\r\n * files: [\r\n * {\r\n * file: file1,\r\n * path: ['documents'],\r\n * },\r\n * ],\r\n * globalPath: ['temporary_files'],\r\n * });\r\n */\r\nexport const upload_files = async ({\r\n files,\r\n globalPath,\r\n concurrency = 5\r\n }: UploadFilesInput): Promise<FilesUploadedResponseData> => {\r\n\r\n // 1. Validate: Throw error immediately if globalPath coexists with any item's individual path\r\n if (globalPath && files.some((item) => item.path && item.path.length > 0)) {\r\n throw new Error(\"Invalid options: 'globalPath' and individual 'path' cannot both exist.\");\r\n }\r\n\r\n const limiter = pLimit(concurrency);\r\n const returnData: FilesUploadedResponseData = {\r\n successFiles: [],\r\n failedFiles: []\r\n };\r\n\r\n // 2. Map and run concurrent uploads inside limiter tasks\r\n const uploadTasks = files.map(({ file, path }) =>\r\n limiter(async () => {\r\n // Resolve target path (use item's path if available, otherwise globalPath array)\r\n const resolvedPath = path ?? (globalPath?.length ? globalPath : undefined);\r\n\r\n // Delegate single file upload logic to upload_file function\r\n const result = await upload_file({\r\n file,\r\n path: resolvedPath\r\n });\r\n\r\n // Aggregate results based on whether an error occurred on the single file upload\r\n if ('error' in result && result.error) {\r\n returnData.failedFiles.push(result);\r\n } else {\r\n returnData.successFiles.push(result);\r\n }\r\n })\r\n );\r\n\r\n // 3. Wait for all concurrent uploads to settle\r\n await Promise.all(uploadTasks);\r\n\r\n return returnData;\r\n};\r\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/utility/utilis/cloud_storage/uploadFiles.ts"],"sourcesContent":["import type {FilesUploadedResponseData, UploadFilesInput} from \"../../libs/interface.js\";\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nimport pLimit from 'p-limit';\r\nimport {upload_file} from \"./uploadFile.js\";\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n/**\r\n * Uploads multiple files to the configured S3-compatible storage bucket\r\n * concurrently with a configurable concurrency limit.\r\n *\r\n * Each file is uploaded using the `upload_file` function. A global path can\r\n * be applied to all files, or each file can specify its own individual path,\r\n * but both options cannot be used at the same time.\r\n *\r\n * Failed uploads are collected separately from successful uploads, allowing\r\n * the caller to inspect the result of every individual file without stopping\r\n * the entire batch operation.\r\n *\r\n * @param params - Configuration options for the batch upload.\r\n * @param params.files - The files to upload along with their optional paths.\r\n * @param params.globalPath - An optional path applied to all files that do\r\n * not specify an individual path.\r\n * @param params.concurrency - The maximum number of files uploaded\r\n * concurrently. Defaults to `5`.\r\n * @returns A promise resolving to a `FilesUploadedResponseData` containing\r\n * separate arrays of successfully uploaded and failed files.\r\n * @throws {Error} If both `globalPath` and an individual file `path` are\r\n * provided.\r\n *\r\n * @example\r\n * const result = await upload_files({\r\n * files: [\r\n * { file: file1 },\r\n * { file: file2 },\r\n * { file: file3 },\r\n * ],\r\n * globalPath: ['temporary_files'],\r\n * concurrency: 5,\r\n * });\r\n *\r\n * console.log('Successful uploads:', result.successFiles);\r\n * console.log('Failed uploads:', result.failedFiles);\r\n *\r\n * @example\r\n * const result = await upload_files({\r\n * files: [\r\n * {\r\n * file: file1,\r\n * path: ['documents', 'reports'],\r\n * },\r\n * {\r\n * file: file2,\r\n * path: ['documents', 'images'],\r\n * },\r\n * ],\r\n * concurrency: 10,\r\n * });\r\n *\r\n * @example\r\n * // This throws because globalPath and an individual path cannot be used together.\r\n * const result = await upload_files({\r\n * files: [\r\n * {\r\n * file: file1,\r\n * path: ['documents'],\r\n * },\r\n * ],\r\n * globalPath: ['temporary_files'],\r\n * });\r\n */\r\nexport const upload_files = async ({\r\n files,\r\n globalPath,\r\n concurrency = 5\r\n }: UploadFilesInput): Promise<FilesUploadedResponseData> => {\r\n\r\n // 1. Validate: Throw error immediately if globalPath coexists with any item's individual path\r\n if (globalPath && files.some((item) => item.path && item.path.length > 0)) {\r\n throw new Error(\"Invalid options: 'globalPath' and individual 'path' cannot both exist.\");\r\n }\r\n\r\n const limiter = pLimit(concurrency);\r\n const returnData: FilesUploadedResponseData = {\r\n successFiles: [],\r\n failedFiles: []\r\n };\r\n\r\n // 2. Map and run concurrent uploads inside limiter tasks\r\n const uploadTasks = files.map(({ file, path }) =>\r\n limiter(async () => {\r\n // Resolve target path (use item's path if available, otherwise globalPath array)\r\n const resolvedPath = path ?? (globalPath?.length ? globalPath : undefined);\r\n\r\n // Delegate single file upload logic to upload_file function\r\n const result = await upload_file({\r\n file,\r\n path: resolvedPath\r\n });\r\n\r\n // Aggregate results based on whether an error occurred on the single file upload\r\n if ('error' in result && result.error) {\r\n returnData.failedFiles.push(result);\r\n } else {\r\n returnData.successFiles.push(result);\r\n }\r\n })\r\n );\r\n\r\n // 3. Wait for all concurrent uploads to settle\r\n await Promise.all(uploadTasks);\r\n\r\n return returnData;\r\n};\r\n"],"mappings":";;;;;;;;;;;;;AAQA,OAAO,YAAY;AAyEZ,IAAM,eAAe,8BAAO;AAAA,EACI;AAAA,EACA;AAAA,EACA,cAAc;AAClB,MAA4D;AAG3F,MAAI,cAAc,MAAM,KAAK,CAAC,SAAS,KAAK,QAAQ,KAAK,KAAK,SAAS,CAAC,GAAG;AACvE,UAAM,IAAI,MAAM,wEAAwE;AAAA,EAC5F;AAEA,QAAM,UAAU,OAAO,WAAW;AAClC,QAAM,aAAwC;AAAA,IAC1C,cAAc,CAAC;AAAA,IACf,aAAa,CAAC;AAAA,EAClB;AAGA,QAAM,cAAc,MAAM;AAAA,IAAI,CAAC,EAAE,MAAM,KAAK,MACxC,QAAQ,YAAY;AAEhB,YAAM,eAAe,SAAS,YAAY,SAAS,aAAa;AAGhE,YAAM,SAAS,MAAM,YAAY;AAAA,QAC7B;AAAA,QACA,MAAM;AAAA,MACV,CAAC;AAGD,UAAI,WAAW,UAAU,OAAO,OAAO;AACnC,mBAAW,YAAY,KAAK,MAAM;AAAA,MACtC,OAAO;AACH,mBAAW,aAAa,KAAK,MAAM;AAAA,MACvC;AAAA,IACJ,CAAC;AAAA,EACL;AAGA,QAAM,QAAQ,IAAI,WAAW;AAE7B,SAAO;AACX,GA1C4B;","names":[]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
HTTP_SERVER,
|
|
3
3
|
startServer
|
|
4
|
-
} from "../../../chunk-
|
|
5
|
-
import "../../../chunk-W2745SOE.js";
|
|
4
|
+
} from "../../../chunk-PRKZ33FU.js";
|
|
6
5
|
import "../../../chunk-P5XJG7OG.js";
|
|
7
6
|
import "../../../chunk-MNSQSU7T.js";
|
|
8
7
|
import "../../../chunk-HZ4GLSOO.js";
|
|
9
8
|
import "../../../chunk-NMNAPTVV.js";
|
|
10
9
|
import "../../../chunk-EB35KLDE.js";
|
|
11
10
|
import "../../../chunk-EWQYVPOL.js";
|
|
11
|
+
import "../../../chunk-W2745SOE.js";
|
|
12
12
|
import {
|
|
13
13
|
__name
|
|
14
14
|
} from "../../../chunk-7QVYU63E.js";
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "backfarm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Divyanshu Jha",
|
|
7
7
|
"license": "ISC",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"all": "tsx src/utility/script/run-all.ts",
|
|
11
|
+
"bucket": "tsx src/utility/script/run-bucket.ts",
|
|
12
|
+
"node": "tsx src/utility/script/run-node-server.ts",
|
|
12
13
|
"build": "tsup",
|
|
13
14
|
"prepublishOnly": "npm run build",
|
|
14
15
|
"start": "node dist/server.js",
|
|
@@ -24,9 +25,9 @@
|
|
|
24
25
|
"require": "./dist/utility/*.js"
|
|
25
26
|
}
|
|
26
27
|
},
|
|
27
|
-
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@aws-sdk/client-s3": "^3.1080.0",
|
|
30
|
+
"backfarm": "^1.0.1",
|
|
30
31
|
"dotenv": "^17.4.2",
|
|
31
32
|
"express": "^5.2.1",
|
|
32
33
|
"mongodb": "^7.4.0",
|