Skip to content

Commit ee217a5

Browse files
committed
fix: formating
1 parent 40884b4 commit ee217a5

File tree

1 file changed

+49
-54
lines changed

1 file changed

+49
-54
lines changed

src/index.js

+49-54
Original file line numberDiff line numberDiff line change
@@ -20,70 +20,65 @@
2020
// you must obtain a commercial license from CoCreate LLC.
2121
// For details, visit <https://cocreate.app/licenses/> or contact us at [email protected].
2222

23-
24-
const { URL } = require('url');
23+
const { URL } = require("url");
2524

2625
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+
}
3432

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);
4040

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+
}
4645

47-
const arrayBuffer = await response.arrayBuffer();
48-
file.src = this.arrayBufferToBase64(arrayBuffer)
46+
const arrayBuffer = await response.arrayBuffer();
47+
file.src = this.arrayBufferToBase64(arrayBuffer);
4948

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");
5251

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+
}
5756

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);
7065

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+
}
7772

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+
}
8782
}
8883

8984
module.exports = CoCreateUrlUploader;

0 commit comments

Comments
 (0)