-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
103 lines (89 loc) · 2.68 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const axios = require('axios');
const FormData = require('form-data');
const { execSync } = require('child_process');
const notifier = require('node-notifier');
const ConsoleWindow = require("node-hide-console-window");
ConsoleWindow.hideConsole();
const AUTHORIZATION_TOKEN = 'W8sh6pYR3DLob2IuF7SFA1ZB0BrEDzM9';
async function getServer() {
try {
const res = await axios({
url: 'https://api.gofile.io/servers',
method: 'GET',
headers: {
accept: '*/*',
},
});
console.log('Gofile Api Check', res.data);
if (res.data.status !== 'ok') {
throw new Error('Gofile Server error');
}
const server = res.data.data.servers[0]?.name;
if (!server) {
throw new Error('no server as been op');
}
return server;
} catch (error) {
console.error('error link', error.message);
process.exit(1);
}
}
async function uploadFile(filePath, server) {
const formData = new FormData();
formData.append('file', require('fs').createReadStream(filePath));
try {
notifier.notify({
title: 'Gofile Uploader',
message: 'Upload as been started',
sound: true,
});
const res = await axios({
url: `https://${server}.gofile.io/contents/uploadfile`,
method: 'POST',
headers: {
...formData.getHeaders(),
Authorization: AUTHORIZATION_TOKEN,
},
data: formData,
maxContentLength: Infinity,
maxBodyLength: Infinity,
});
if (res.data.status !== 'ok') {
throw new Error(`Echec de l'upload : ${res.data.message}`);
}
notifier.notify({
title: 'Gofile Uploader',
message: 'Upload succesfull link in your clipboard',
sound: true,
});
return res.data.data.downloadPage;
} catch (error) {
console.error('Error Upload', error.message);
notifier.notify({
title: 'Gofile Uploader',
message: 'Error in the upload',
sound: true,
});
process.exit(1);
}
}
function copyToClipboard(text) {
try {
execSync(`echo ${text} | clip`, { encoding: 'utf-8', stdio: 'ignore' });
console.log('Link as been copied');
} catch (error) {
console.error('error in your clipboard', error.message);
}
}
(async () => {
const filePath = process.argv[2];
if (!filePath) {
console.error('Veuillez fournir le chemin du fichier à uploader.');
process.exit(1);
}
const server = await getServer();
console.log(`Upload : ${filePath}`);
const downloadLink = await uploadFile(filePath, server);
console.log(`Upload Finish download link : ${downloadLink}`);
copyToClipboard(downloadLink);
})();