@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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/url-uploader",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "description": "A simple url-uploader component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "url-uploader",
@@ -0,0 +1,16 @@
1
+ module.exports = {
2
+ tabWidth: 4,
3
+ semi: true,
4
+ trailingComma: "none",
5
+ bracketSameLine: true,
6
+ useTabs: true,
7
+ overrides: [
8
+ {
9
+ files: ["*.json", "*.yml", "*.yaml"],
10
+ options: {
11
+ tabWidth: 2,
12
+ useTabs: false
13
+ },
14
+ }
15
+ ],
16
+ };
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
- constructor(crud) {
28
- this.crud = crud
29
- crud.wsManager.on('importUrl', async (data) => {
30
- this.fetchFileFromURL(data)
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
- async fetchFileFromURL(data) {
36
- try {
37
- const file = data.file
38
- const fetch = await import('node-fetch').then(module => module.default);
39
- const response = await fetch(file.src);
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
- if (!response.ok) {
42
- data.error = 'Failed to fetch file: ' + response.statusText
43
- if (data.socket)
44
- return this.crud.wsManager.send(data)
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
- const arrayBuffer = await response.arrayBuffer();
48
- file.src = this.arrayBufferToBase64(arrayBuffer)
46
+ const arrayBuffer = await response.arrayBuffer();
47
+ file.src = this.arrayBufferToBase64(arrayBuffer);
49
48
 
50
- file.size = arrayBuffer.byteLength
51
- file['content-type'] = response.headers.get('content-type')
49
+ file.size = arrayBuffer.byteLength;
50
+ file["content-type"] = response.headers.get("content-type");
52
51
 
53
- if (!file.name) {
54
- const parsedUrl = new URL(file.src);
55
- file.name = parsedUrl.pathname.split('/').pop();
56
- }
52
+ if (!file.name) {
53
+ const parsedUrl = new URL(file.src);
54
+ file.name = parsedUrl.pathname.split("/").pop();
55
+ }
57
56
 
58
- if (!file.directory)
59
- file.directory = '/'
60
- if (!file.path)
61
- file.path = file.directory
62
- if (!file.pathname) {
63
- if (file.path.endsWith('/'))
64
- file.pathname = file.path + file.name
65
- else
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
- // return data;
72
- } catch (error) {
73
- console.error('Error fetching file:', error);
74
- throw error;
75
- }
76
- }
66
+ // return data;
67
+ } catch (error) {
68
+ console.error("Error fetching file:", error);
69
+ throw error;
70
+ }
71
+ }
77
72
 
78
- arrayBufferToBase64(buffer) {
79
- let binary = '';
80
- const bytes = new Uint8Array(buffer);
81
- const len = bytes.byteLength;
82
- for (let i = 0; i < len; i++) {
83
- binary += String.fromCharCode(bytes[i]);
84
- }
85
- return Buffer.from(binary, 'binary').toString('base64');
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;