@cocreate/url-uploader 1.0.1 → 1.1.1
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/CHANGELOG.md +19 -0
- package/package.json +1 -1
- package/prettier.config.js +16 -0
- package/src/index.js +49 -54
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
## [1.1.1](https://github.com/CoCreate-app/CoCreate-url-uploader/compare/v1.1.0...v1.1.1) (2024-12-09)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* formating ([ee217a5](https://github.com/CoCreate-app/CoCreate-url-uploader/commit/ee217a53c372a2c85e084d4d100142b12ab90ea1))
|
|
7
|
+
|
|
8
|
+
# [1.1.0](https://github.com/CoCreate-app/CoCreate-url-uploader/compare/v1.0.1...v1.1.0) (2024-11-04)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* prettier.config options ([9d09104](https://github.com/CoCreate-app/CoCreate-url-uploader/commit/9d09104e1ab6b116adba53f83aaf55992c20c58e))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* add prettier.config.js and format files ([81d1f3c](https://github.com/CoCreate-app/CoCreate-url-uploader/commit/81d1f3cff02d5d5ee1b060e62b0ae12d1f5faa90))
|
|
19
|
+
|
|
1
20
|
## [1.0.1](https://github.com/CoCreate-app/CoCreate-url-uploader/compare/v1.0.0...v1.0.1) (2024-06-30)
|
|
2
21
|
|
|
3
22
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -20,70 +20,65 @@
|
|
|
20
20
|
// you must obtain a commercial license from CoCreate LLC.
|
|
21
21
|
// For details, visit <https://cocreate.app/licenses/> or contact us at sales@cocreate.app.
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
const { URL } = require('url');
|
|
23
|
+
const { URL } = require("url");
|
|
25
24
|
|
|
26
25
|
class CoCreateUrlUploader {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
constructor(crud) {
|
|
27
|
+
this.crud = crud;
|
|
28
|
+
crud.wsManager.on("importUrl", async (data) => {
|
|
29
|
+
this.fetchFileFromURL(data);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
async fetchFileFromURL(data) {
|
|
34
|
+
try {
|
|
35
|
+
const file = data.file;
|
|
36
|
+
const fetch = await import("node-fetch").then(
|
|
37
|
+
(module) => module.default
|
|
38
|
+
);
|
|
39
|
+
const response = await fetch(file.src);
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
data.error = "Failed to fetch file: " + response.statusText;
|
|
43
|
+
if (data.socket) return this.crud.wsManager.send(data);
|
|
44
|
+
}
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
47
|
+
file.src = this.arrayBufferToBase64(arrayBuffer);
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
file.size = arrayBuffer.byteLength;
|
|
50
|
+
file["content-type"] = response.headers.get("content-type");
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
if (!file.name) {
|
|
53
|
+
const parsedUrl = new URL(file.src);
|
|
54
|
+
file.name = parsedUrl.pathname.split("/").pop();
|
|
55
|
+
}
|
|
57
56
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
file.pathname = file.path + '/' + file.name
|
|
67
|
-
}
|
|
68
|
-
if (data.socket)
|
|
69
|
-
this.crud.wsManager.send(data)
|
|
57
|
+
if (!file.directory) file.directory = "/";
|
|
58
|
+
if (!file.path) file.path = file.directory;
|
|
59
|
+
if (!file.pathname) {
|
|
60
|
+
if (file.path.endsWith("/"))
|
|
61
|
+
file.pathname = file.path + file.name;
|
|
62
|
+
else file.pathname = file.path + "/" + file.name;
|
|
63
|
+
}
|
|
64
|
+
if (data.socket) this.crud.wsManager.send(data);
|
|
70
65
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
// return data;
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error("Error fetching file:", error);
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
77
72
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
73
|
+
arrayBufferToBase64(buffer) {
|
|
74
|
+
let binary = "";
|
|
75
|
+
const bytes = new Uint8Array(buffer);
|
|
76
|
+
const len = bytes.byteLength;
|
|
77
|
+
for (let i = 0; i < len; i++) {
|
|
78
|
+
binary += String.fromCharCode(bytes[i]);
|
|
79
|
+
}
|
|
80
|
+
return Buffer.from(binary, "binary").toString("base64");
|
|
81
|
+
}
|
|
87
82
|
}
|
|
88
83
|
|
|
89
84
|
module.exports = CoCreateUrlUploader;
|