-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotif.js
60 lines (58 loc) · 2.08 KB
/
notif.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
const axios = require('axios').default;
const config = require('./config');
module.exports.sendNotif = (name, id, hostname, ip, size, private) => {
return new Promise((resolve, reject) => {
if (config.discord.on) {
axios.post(`${config.discord.webhook}`, {
username: "Feck Files Upload Notification",
avatar_url: `https://${hostname}/site/files/icon.png`,
embeds: [{
title: "New Upload",
description: 'New File Uploaded to the Feck Files Drive',
color: "3066993",
fields: [{
name: "File Name",
value: `${name}`,
inline: true
}, {
name: "File ID",
value: `${id}`,
inline: true
}, {
name: "Access URL",
value: `[Click me](https://${hostname}/${private ? 'download' : 'uploads/'}?fileid=${id})`,
inline: true
}, {
name: "File Size",
value: `${formatSize(parseInt(size))}`,
inline: true
}, {
name: "Uploader IP",
value: `${ip}`,
inline: true
}, {
name: "Timestamp",
value: `${new Date().toUTCString()}`,
inline: true
}]
}],
}).then(() => resolve()).catch(e => { reject(e) });
}
else {
resolve();
}
})
}
function formatSize(number) {
if (number >= 1024 * 1024) {
let mbSize = number / (1024 * 1024);
return `${mbSize.toFixed(1)}`.replace(/\B(?=(\d{3})+(?!\d))/g, ",") + "MB";
}
else if (number >= 1024) {
let kbSize = number / (1024);
return `${kbSize.toFixed(1)}KB`;
}
else {
return `${number}B`;
}
}