dpu-cloud-sdk 1.0.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.
Files changed (51) hide show
  1. package/.env.development +1 -0
  2. package/.env.production +1 -0
  3. package/dist/DPUClient.d.ts +83 -0
  4. package/dist/DPUClient.js +1043 -0
  5. package/dist/ServiceIntegration.d.ts +20 -0
  6. package/dist/ServiceIntegration.js +506 -0
  7. package/dist/api/auth.d.ts +3 -0
  8. package/dist/api/auth.js +10 -0
  9. package/dist/api/compress.d.ts +4 -0
  10. package/dist/api/compress.js +16 -0
  11. package/dist/api/translate.d.ts +8 -0
  12. package/dist/api/translate.js +38 -0
  13. package/dist/index.d.ts +4 -0
  14. package/dist/index.js +4 -0
  15. package/dist/models/RequestModel.d.ts +33 -0
  16. package/dist/models/RequestModel.js +2 -0
  17. package/dist/models/ResponseModel.d.ts +99 -0
  18. package/dist/models/ResponseModel.js +1 -0
  19. package/dist/utils/Config.d.ts +32 -0
  20. package/dist/utils/Config.js +44 -0
  21. package/dist/utils/Constants.d.ts +48 -0
  22. package/dist/utils/Constants.js +55 -0
  23. package/dist/utils/Enum.d.ts +27 -0
  24. package/dist/utils/Enum.js +30 -0
  25. package/dist/utils/Helper.d.ts +4 -0
  26. package/dist/utils/Helper.js +47 -0
  27. package/dist/workerDownloadSingleFile.d.ts +1 -0
  28. package/dist/workerDownloadSingleFile.js +35 -0
  29. package/dist/workerUploadChildFile.d.ts +1 -0
  30. package/dist/workerUploadChildFile.js +82 -0
  31. package/dist/workerUploadSingleFile.d.ts +1 -0
  32. package/dist/workerUploadSingleFile.js +93 -0
  33. package/dpubim-service-1.1.28.tgz +0 -0
  34. package/package.json +33 -0
  35. package/src/DPUClient.ts +1505 -0
  36. package/src/ServiceIntegration.ts +710 -0
  37. package/src/api/auth.ts +18 -0
  38. package/src/api/compress.ts +36 -0
  39. package/src/api/translate.ts +94 -0
  40. package/src/index.ts +4 -0
  41. package/src/models/RequestModel.ts +44 -0
  42. package/src/models/ResponseModel.ts +110 -0
  43. package/src/utils/Config.ts +59 -0
  44. package/src/utils/Constants.ts +61 -0
  45. package/src/utils/Enum.ts +29 -0
  46. package/src/utils/Helper.ts +57 -0
  47. package/src/workerDownloadSingleFile.ts +34 -0
  48. package/src/workerUploadChildFile.ts +85 -0
  49. package/src/workerUploadSingleFile.ts +123 -0
  50. package/tsconfig.json +108 -0
  51. package/webpack.config.js +43 -0
@@ -0,0 +1,99 @@
1
+ import { StatusTranslate } from "../utils/Enum";
2
+ export type BaseReponseModel<T> = {
3
+ statusCode: number;
4
+ message: string;
5
+ data: T;
6
+ };
7
+ export interface PresignURLResponse {
8
+ url: string;
9
+ headers: {
10
+ [key: string]: string;
11
+ };
12
+ }
13
+ export interface MultiPresignURLResponse {
14
+ urls: {
15
+ [key: string]: string;
16
+ };
17
+ headers: {
18
+ [key: string]: string;
19
+ };
20
+ }
21
+ export interface InitUploadResponse {
22
+ uploadId: string;
23
+ headers: {
24
+ [key: string]: string;
25
+ };
26
+ }
27
+ export type CompressionResponse = {
28
+ bucketName: string;
29
+ rootFolder: string;
30
+ requestId: string;
31
+ };
32
+ export interface CompressStatus {
33
+ compressData: CompressResponse;
34
+ compressInfo: FileCompressInfo;
35
+ }
36
+ export interface FileCompressInfo {
37
+ bucketName: string;
38
+ rootFolder: string;
39
+ requestId: string;
40
+ }
41
+ export interface CompressResponse {
42
+ status: CompressStatus;
43
+ percent: number;
44
+ fileCompressed: number;
45
+ totalFile: number;
46
+ urlsDownload: string[] | null;
47
+ expireTime: Date | null;
48
+ compressTime: Date;
49
+ message: string[];
50
+ }
51
+ export interface ObjectDetail {
52
+ bucketKey: string;
53
+ lastModified: string;
54
+ versionId: string;
55
+ objectKey: string;
56
+ contentLength: number | null;
57
+ }
58
+ export interface CompleteMultipartUploadResponse {
59
+ key: string;
60
+ eTag: string;
61
+ versionId: string;
62
+ }
63
+ export interface TranslateStatusInfo {
64
+ translateId: string;
65
+ modelType: string;
66
+ translateType: string;
67
+ extensionSaveFile: string;
68
+ ePSGCode: string;
69
+ translatePos: number[] | null;
70
+ translateStatus: TranslateStatus;
71
+ objectTranslateInfo: ObjectTranslateInfo;
72
+ }
73
+ export interface ObjectTranslateInfo {
74
+ }
75
+ export interface FileTranslateInfo extends ObjectTranslateInfo {
76
+ fileName: string;
77
+ bucketName: string;
78
+ versionId: string;
79
+ }
80
+ export interface URNTranslateInfo extends ObjectTranslateInfo {
81
+ urn: string;
82
+ clientID: string;
83
+ }
84
+ export interface TranslateStatus {
85
+ status: StatusTranslate;
86
+ percentTranslateGeometry: number | null;
87
+ percentTranslateMetadata: number | null;
88
+ }
89
+ export interface Token {
90
+ accessToken: string;
91
+ expiresIn: number;
92
+ }
93
+ export interface Dictionary<T> {
94
+ [key: string]: T;
95
+ }
96
+ export interface TranslateInfo {
97
+ listError: Dictionary<string>;
98
+ translateStatusInfo: TranslateStatusInfo[];
99
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Global configuration for DPU Storage
3
+ * This allows external packages to customize the BaseURL for their domains
4
+ */
5
+ interface IConfig {
6
+ baseURL: string;
7
+ }
8
+ declare class DPUConfig {
9
+ private static instance;
10
+ private config;
11
+ private constructor();
12
+ static getInstance(): DPUConfig;
13
+ /**
14
+ * Set the base URL for API requests
15
+ * @param baseURL The base URL for all API calls
16
+ */
17
+ setBaseURL(baseURL: string): void;
18
+ /**
19
+ * Get the current base URL
20
+ */
21
+ getBaseURL(): string;
22
+ /**
23
+ * Set multiple configuration values at once
24
+ */
25
+ setConfig(config: Partial<IConfig>): void;
26
+ /**
27
+ * Get the entire configuration object
28
+ */
29
+ getConfig(): IConfig;
30
+ }
31
+ export declare const dpuConfig: DPUConfig;
32
+ export {};
@@ -0,0 +1,44 @@
1
+ class DPUConfig {
2
+ static instance;
3
+ config = {
4
+ baseURL: 'https://translateservicedev.corebim.com', // Default URL
5
+ };
6
+ constructor() { }
7
+ static getInstance() {
8
+ if (!DPUConfig.instance) {
9
+ DPUConfig.instance = new DPUConfig();
10
+ }
11
+ return DPUConfig.instance;
12
+ }
13
+ /**
14
+ * Set the base URL for API requests
15
+ * @param baseURL The base URL for all API calls
16
+ */
17
+ setBaseURL(baseURL) {
18
+ if (!baseURL || typeof baseURL !== 'string') {
19
+ throw new Error('Invalid baseURL. Must be a non-empty string.');
20
+ }
21
+ this.config.baseURL = baseURL.trim();
22
+ }
23
+ /**
24
+ * Get the current base URL
25
+ */
26
+ getBaseURL() {
27
+ return this.config.baseURL;
28
+ }
29
+ /**
30
+ * Set multiple configuration values at once
31
+ */
32
+ setConfig(config) {
33
+ if (config.baseURL) {
34
+ this.setBaseURL(config.baseURL);
35
+ }
36
+ }
37
+ /**
38
+ * Get the entire configuration object
39
+ */
40
+ getConfig() {
41
+ return { ...this.config };
42
+ }
43
+ }
44
+ export const dpuConfig = DPUConfig.getInstance();
@@ -0,0 +1,48 @@
1
+ export declare const Path: {
2
+ readonly BaseURL: string;
3
+ InitiateMultipartUpload: string;
4
+ GeneratePresignedUrls: string;
5
+ GeneratePresignedUrl: string;
6
+ GenerateMultiPresignedURL: string;
7
+ CompleteMultipartUpload: string;
8
+ AbortMultipartUpload: string;
9
+ GetObjectDetail: string;
10
+ GetObjects: string;
11
+ GetUrlDownload: string;
12
+ ApplyPermissionToObjects: string;
13
+ };
14
+ export declare const PathManagement: {
15
+ CompressFolder: string;
16
+ GetStatusCompress: string;
17
+ CancelDownload: string;
18
+ TranslateFile: string;
19
+ GetStatusTranslate: string;
20
+ GetStatusTranslateFile: string;
21
+ GetEPSGRegionCode: string;
22
+ GetFileTileSet: string;
23
+ };
24
+ export declare const PathAuth: {
25
+ GetToken: string;
26
+ };
27
+ export declare const ApiStatus: {
28
+ Success: number;
29
+ BadRequest: number;
30
+ Unauthorized: number;
31
+ Forbidden: number;
32
+ NotFound: number;
33
+ InternalServerError: number;
34
+ };
35
+ export declare const ConfigFileRules: {
36
+ ChunkSize: number;
37
+ MaxChunkCountAllowed: number;
38
+ MaxRetryOnUrlExpiry: number;
39
+ MaxRetry: number;
40
+ MaxRetryOnTokenExpiry: number;
41
+ MaxWebWorker: number;
42
+ LimitFile: number;
43
+ TaskCurrently: number;
44
+ MaxFileInChunk: number;
45
+ };
46
+ export declare const ConfigBase: {
47
+ PageSize: number;
48
+ };
@@ -0,0 +1,55 @@
1
+ import { dpuConfig } from './Config';
2
+ export const Path = {
3
+ get BaseURL() {
4
+ return dpuConfig.getBaseURL();
5
+ },
6
+ InitiateMultipartUpload: '/fileApi/Object/InitiateMultipartUpload',
7
+ GeneratePresignedUrls: '/fileApi/Object/GeneratePresignedUrls',
8
+ GeneratePresignedUrl: '/fileApi/Object/GeneratePresignedUrl',
9
+ GenerateMultiPresignedURL: '/fileApi/Object/GenerateMultiPresignedURL',
10
+ CompleteMultipartUpload: '/fileApi/Object/CompleteMultipartUpload',
11
+ AbortMultipartUpload: '/fileApi/Object/AbortMultipartUpload',
12
+ GetObjectDetail: '/fileApi/Object/GetObjectDetail',
13
+ GetObjects: '/fileApi/Object/GetObjects',
14
+ GetUrlDownload: '/fileApi/Object/GetUrlDownload',
15
+ ApplyPermissionToObjects: '/fileApi/Object/ApplyPermissionToObjects',
16
+ };
17
+ export const PathManagement = {
18
+ //#region Compress
19
+ CompressFolder: "/manageTranslateApi/Compress/CompressFolder",
20
+ GetStatusCompress: "/manageTranslateApi/Compress/GetStatusCompress",
21
+ CancelDownload: "/manageTranslateApi/Compress/CancelDownload",
22
+ //#endregion
23
+ //#region Translate
24
+ TranslateFile: "/manageTranslateApi/Translate/TranslateFile",
25
+ GetStatusTranslate: "/manageTranslateApi/Translate/GetStatusTranslate",
26
+ GetStatusTranslateFile: "/manageTranslateApi/Translate/GetStatusTranslateFile",
27
+ GetEPSGRegionCode: "/manageTranslateApi/Translate/GetEPSGRegionCode",
28
+ GetFileTileSet: "/manageTranslateApi/Translate/GetFileTileSet",
29
+ //#endregion
30
+ };
31
+ export const PathAuth = {
32
+ GetToken: '/authApi/user/GetToken',
33
+ };
34
+ export const ApiStatus = {
35
+ Success: 200,
36
+ BadRequest: 400,
37
+ Unauthorized: 401,
38
+ Forbidden: 403,
39
+ NotFound: 404,
40
+ InternalServerError: 500
41
+ };
42
+ export const ConfigFileRules = {
43
+ ChunkSize: 5 * 1024 * 1024, // 5MB
44
+ MaxChunkCountAllowed: 10000,
45
+ MaxRetryOnUrlExpiry: 2,
46
+ MaxRetry: 3,
47
+ MaxRetryOnTokenExpiry: 2,
48
+ MaxWebWorker: 20,
49
+ LimitFile: 200,
50
+ TaskCurrently: 10,
51
+ MaxFileInChunk: 2000,
52
+ };
53
+ export const ConfigBase = {
54
+ PageSize: 1000
55
+ };
@@ -0,0 +1,27 @@
1
+ export declare enum StatusWorker {
2
+ Success = "Success",
3
+ Error = "Error"
4
+ }
5
+ export declare enum StatusTranslate {
6
+ InQueue = 0,
7
+ Translating = 1,
8
+ Translated = 2,
9
+ TranslateError = 3,
10
+ Canceled = 4,
11
+ NotFound = 5
12
+ }
13
+ export declare enum Scope {
14
+ DataRead = 0,
15
+ DataWrite = 1,
16
+ DataCreate = 2,
17
+ DataSearch = 3,
18
+ BucketCreate = 4,
19
+ BucketRead = 5,
20
+ BucketUpdate = 6,
21
+ BucketDelete = 7,
22
+ CodeAll = 8,
23
+ AccountRead = 9,
24
+ AccountWrite = 10,
25
+ UserProfileRead = 11,
26
+ ViewablesRead = 12
27
+ }
@@ -0,0 +1,30 @@
1
+ export var StatusWorker;
2
+ (function (StatusWorker) {
3
+ StatusWorker["Success"] = "Success";
4
+ StatusWorker["Error"] = "Error";
5
+ })(StatusWorker || (StatusWorker = {}));
6
+ export var StatusTranslate;
7
+ (function (StatusTranslate) {
8
+ StatusTranslate[StatusTranslate["InQueue"] = 0] = "InQueue";
9
+ StatusTranslate[StatusTranslate["Translating"] = 1] = "Translating";
10
+ StatusTranslate[StatusTranslate["Translated"] = 2] = "Translated";
11
+ StatusTranslate[StatusTranslate["TranslateError"] = 3] = "TranslateError";
12
+ StatusTranslate[StatusTranslate["Canceled"] = 4] = "Canceled";
13
+ StatusTranslate[StatusTranslate["NotFound"] = 5] = "NotFound";
14
+ })(StatusTranslate || (StatusTranslate = {}));
15
+ export var Scope;
16
+ (function (Scope) {
17
+ Scope[Scope["DataRead"] = 0] = "DataRead";
18
+ Scope[Scope["DataWrite"] = 1] = "DataWrite";
19
+ Scope[Scope["DataCreate"] = 2] = "DataCreate";
20
+ Scope[Scope["DataSearch"] = 3] = "DataSearch";
21
+ Scope[Scope["BucketCreate"] = 4] = "BucketCreate";
22
+ Scope[Scope["BucketRead"] = 5] = "BucketRead";
23
+ Scope[Scope["BucketUpdate"] = 6] = "BucketUpdate";
24
+ Scope[Scope["BucketDelete"] = 7] = "BucketDelete";
25
+ Scope[Scope["CodeAll"] = 8] = "CodeAll";
26
+ Scope[Scope["AccountRead"] = 9] = "AccountRead";
27
+ Scope[Scope["AccountWrite"] = 10] = "AccountWrite";
28
+ Scope[Scope["UserProfileRead"] = 11] = "UserProfileRead";
29
+ Scope[Scope["ViewablesRead"] = 12] = "ViewablesRead";
30
+ })(Scope || (Scope = {}));
@@ -0,0 +1,4 @@
1
+ import { Buffer } from "buffer";
2
+ export declare const validString: (value?: string) => boolean;
3
+ export declare const readFileDataAsBase64: (file: File) => Promise<Buffer>;
4
+ export declare const chunkArray: <T>(array: T[], max: number) => T[][];
@@ -0,0 +1,47 @@
1
+ import { Buffer } from "buffer";
2
+ export const validString = (value) => {
3
+ if (value === null || value === undefined || value === "") {
4
+ return false;
5
+ }
6
+ return true;
7
+ };
8
+ // large file is not supported (> 2GB)
9
+ // export const readFileDataAsBase64 = async (file: File): Promise<Buffer> => {
10
+ // const chunkSize = 1024 * 1024 * 10; // 10 MB chunks
11
+ // const totalSize = file.size;
12
+ // let bytesRead = 0;
13
+ // const reader = file.stream().getReader(); // Create a ReadableStream reader
14
+ // // Create a buffer to store the file data incrementally
15
+ // const arrayBuffer = new Uint8Array(totalSize);
16
+ // while (true) {
17
+ // const { done, value } = await reader.read(); // Read a chunk
18
+ // if (done) break;
19
+ // // Copy the chunk into the ArrayBuffer
20
+ // arrayBuffer.set(value, bytesRead);
21
+ // bytesRead += value.byteLength;
22
+ // }
23
+ // return Buffer.from(arrayBuffer);
24
+ // };
25
+ export const readFileDataAsBase64 = (file) => {
26
+ return new Promise((resolve, reject) => {
27
+ const reader = new FileReader();
28
+ reader.onload = (event) => {
29
+ const buffer = Buffer.from(event.target.result);
30
+ resolve(buffer);
31
+ };
32
+ reader.onerror = (err) => {
33
+ console.error("error when read file", err);
34
+ reject(err);
35
+ };
36
+ reader.readAsArrayBuffer(file);
37
+ });
38
+ };
39
+ export const chunkArray = (array, max) => {
40
+ if (max <= 0)
41
+ throw new Error("max must be a positive number");
42
+ const result = [];
43
+ for (let i = 0; i < array.length; i += max) {
44
+ result.push(array.slice(i, i + max));
45
+ }
46
+ return result;
47
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ import { ServiceIntegration } from "./ServiceIntegration";
2
+ import { StatusWorker } from "./utils/Enum";
3
+ // tạm thời chưa làm phần token
4
+ self.onmessage = async (message) => {
5
+ const { data } = message;
6
+ try {
7
+ const chunk = await downloadSingleFile(data);
8
+ const result = {
9
+ status: StatusWorker.Success,
10
+ chunk: chunk,
11
+ requestId: data.requestId,
12
+ index: data.index,
13
+ };
14
+ self.postMessage(result, [chunk]); // Send the result back to the main thread
15
+ }
16
+ catch (error) {
17
+ const result = {
18
+ status: StatusWorker.Error,
19
+ requestId: data.requestId,
20
+ };
21
+ self.postMessage(result);
22
+ }
23
+ };
24
+ async function downloadSingleFile(data) {
25
+ const { url, start, end } = data;
26
+ try {
27
+ const service = new ServiceIntegration();
28
+ const response = await service.fetchChunkFile(url, start, end);
29
+ return response;
30
+ }
31
+ catch (error) {
32
+ console.error(`Error when download single file: ${error}`);
33
+ throw error;
34
+ }
35
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,82 @@
1
+ import { ApiStatus } from "./utils/Constants";
2
+ import { Buffer } from "buffer";
3
+ import { StatusWorker } from "./utils/Enum";
4
+ let abortController = null;
5
+ let workerPortRoot = null;
6
+ self.onmessage = async (message) => {
7
+ const { data } = message;
8
+ if (data.port) {
9
+ workerPortRoot = data.port;
10
+ }
11
+ else {
12
+ // Handle abort message
13
+ if (data.type === "abort") {
14
+ if (abortController) {
15
+ abortController.abort();
16
+ abortController = null;
17
+ }
18
+ return;
19
+ }
20
+ try {
21
+ const responseUpload = await uploadChildFile(data);
22
+ const result = {
23
+ status: StatusWorker.Success,
24
+ responseUpload,
25
+ requestId: data.requestId,
26
+ contentLength: data.arrayBuffer.byteLength,
27
+ };
28
+ self.postMessage(result); // Send the result back to the main thread
29
+ if (workerPortRoot) {
30
+ workerPortRoot.postMessage({
31
+ type: "progressUpload",
32
+ progress: {
33
+ dataUploadId: data.dataUploadId,
34
+ percentCompleted: 0,
35
+ fileKey: data.fileName,
36
+ contentLength: data.arrayBuffer.byteLength,
37
+ },
38
+ });
39
+ }
40
+ }
41
+ catch (error) {
42
+ const result = {
43
+ status: StatusWorker.Error,
44
+ requestId: data.requestId,
45
+ error: error instanceof Error ? error.message : String(error),
46
+ };
47
+ self.postMessage(result);
48
+ }
49
+ }
50
+ };
51
+ async function uploadChildFile(data) {
52
+ const { currentPresignUrl, arrayBuffer, partNumber } = data;
53
+ const buffer = Buffer.from(arrayBuffer);
54
+ // Create new AbortController for this request
55
+ abortController = new AbortController();
56
+ try {
57
+ const response = await fetch(currentPresignUrl.url, {
58
+ method: "PUT",
59
+ headers: currentPresignUrl.headers,
60
+ body: buffer,
61
+ signal: abortController.signal,
62
+ });
63
+ if (response.status === ApiStatus.Success) {
64
+ var eTag = response.headers.get("ETag");
65
+ if (eTag) {
66
+ const result = {
67
+ eTag: eTag.replace(/^"|"$/g, ""),
68
+ partNumber: partNumber,
69
+ };
70
+ return result;
71
+ }
72
+ }
73
+ throw new Error(`Error when upload child file: ${response.statusText}`);
74
+ }
75
+ catch (error) {
76
+ if (error instanceof Error && error.name === "AbortError") {
77
+ throw new Error("Upload cancelled");
78
+ }
79
+ console.error(`Error when upload child file: ${error}`);
80
+ throw new Error(`Error when upload child file: ${error}`);
81
+ }
82
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,93 @@
1
+ import { ConfigFileRules } from "./utils/Constants";
2
+ import { Buffer } from "buffer";
3
+ import { StatusWorker } from "./utils/Enum";
4
+ import { ServiceIntegration } from "./ServiceIntegration";
5
+ let abortController = null;
6
+ let workerPortRoot = null;
7
+ // tạm thời chưa làm phần token
8
+ self.onmessage = async (message) => {
9
+ const { data } = message;
10
+ if (data.port) {
11
+ workerPortRoot = data.port;
12
+ }
13
+ else {
14
+ // Handle abort message
15
+ if (data.type === "abort") {
16
+ if (abortController) {
17
+ abortController.abort();
18
+ abortController = null;
19
+ }
20
+ const result = {
21
+ status: StatusWorker.Error,
22
+ requestId: data.requestId,
23
+ error: "Upload cancelled",
24
+ };
25
+ self.postMessage(result);
26
+ return;
27
+ }
28
+ try {
29
+ // Create new AbortController for this request
30
+ abortController = new AbortController();
31
+ const responseUpload = await uploadSingleFile(data);
32
+ const result = {
33
+ status: StatusWorker.Success,
34
+ responseUpload,
35
+ requestId: data.requestId,
36
+ workerId: data.workerId,
37
+ fileName: data.fullName,
38
+ fileKey: data.fileKey,
39
+ };
40
+ // Clear arrayBuffer after successful upload
41
+ data.arrayBuffer = null;
42
+ self.postMessage(result); // Send the result back to the main thread
43
+ if (workerPortRoot) {
44
+ workerPortRoot.postMessage({
45
+ type: "progressUpload",
46
+ progress: {
47
+ dataUploadId: data.dataUploadId,
48
+ percentCompleted: 0,
49
+ fileKey: data.fileKey,
50
+ versionFile: responseUpload.versionFile,
51
+ contentLength: responseUpload.contentLength,
52
+ },
53
+ });
54
+ }
55
+ }
56
+ catch (error) {
57
+ const result = {
58
+ status: StatusWorker.Error,
59
+ requestId: data.requestId,
60
+ workerId: data.workerId,
61
+ fileName: data.fullName,
62
+ fileKey: data.fileKey,
63
+ error: error instanceof Error ? error.message : String(error),
64
+ };
65
+ self.postMessage(result);
66
+ }
67
+ finally {
68
+ abortController = null;
69
+ }
70
+ }
71
+ };
72
+ async function uploadSingleFile(data) {
73
+ const { bucketName, file, fullName, accessToken, initUpload, isGetInfo, preSignUrl, arrayBuffer, } = data;
74
+ const buffer = Buffer.from(arrayBuffer);
75
+ try {
76
+ const service = new ServiceIntegration();
77
+ if (buffer.length > ConfigFileRules.ChunkSize) {
78
+ const response = await service.uploadLargeFile(bucketName, fullName, buffer, accessToken, abortController ?? new AbortController(), undefined, undefined, initUpload, isGetInfo);
79
+ return response;
80
+ }
81
+ else {
82
+ const response = await service.uploadSmallFile(bucketName, fullName, buffer, accessToken, abortController ?? new AbortController(), undefined, undefined, isGetInfo, preSignUrl);
83
+ return response;
84
+ }
85
+ }
86
+ catch (error) {
87
+ if (error instanceof Error && error.name === "AbortError") {
88
+ throw new Error("Upload cancelled");
89
+ }
90
+ console.error(`Error when upload single file: ${error}`);
91
+ throw error;
92
+ }
93
+ }
Binary file
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "dpu-cloud-sdk",
3
+ "version": "1.0.0",
4
+ "main": "dist/index",
5
+ "types": "dist/index",
6
+ "scripts": {
7
+ "version-patch": "npm version patch",
8
+ "build": "tsc",
9
+ "bump-build": "npm run version-patch && npm run build",
10
+ "bump-build-pack": "npm run bump-build && npm pack",
11
+ "bump-build-publish": "npm run bump-build && npm publish",
12
+ "dev": "webpack --mode development --watch",
13
+ "clean": "rimraf dist/*",
14
+ "webpack": "npx webpack --config webpack.config.js --mode=production ",
15
+ "test": "echo \"Error: no test specified\" && exit 1"
16
+ },
17
+ "keywords": [],
18
+ "author": "",
19
+ "license": "ISC",
20
+ "description": "",
21
+ "dependencies": {
22
+ "@types/node": "^22.5.0",
23
+ "buffer": "^6.0.3",
24
+ "cross-env": "^7.0.3",
25
+ "dotenv": "^16.4.5",
26
+ "p-limit": "^6.1.0",
27
+ "rimraf": "^6.0.1",
28
+ "typescript": "^5.5.4"
29
+ },
30
+ "devDependencies": {
31
+ "webpack-cli": "^5.1.4"
32
+ }
33
+ }