Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/lib/uploader.js
1126 views
1
let axios = require('axios')
2
let BodyForm = require('form-data')
3
let { fromBuffer } = require('file-type')
4
let fetch = require('node-fetch')
5
let fs = require('fs')
6
let cheerio = require('cheerio')
7
8
9
10
function TelegraPh (Path) {
11
return new Promise (async (resolve, reject) => {
12
if (!fs.existsSync(Path)) return reject(new Error("File not Found"))
13
try {
14
const form = new BodyForm();
15
form.append("file", fs.createReadStream(Path))
16
const data = await axios({
17
url: "https://telegra.ph/upload",
18
method: "POST",
19
headers: {
20
...form.getHeaders()
21
},
22
data: form
23
})
24
return resolve("https://telegra.ph" + data.data[0].src)
25
} catch (err) {
26
return reject(new Error(String(err)))
27
}
28
})
29
}
30
31
async function UploadFileUgu (input) {
32
return new Promise (async (resolve, reject) => {
33
const form = new BodyForm();
34
form.append("files[]", fs.createReadStream(input))
35
await axios({
36
url: "https://uguu.se/upload.php",
37
method: "POST",
38
headers: {
39
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36",
40
...form.getHeaders()
41
},
42
data: form
43
}).then((data) => {
44
resolve(data.data.files[0])
45
}).catch((err) => reject(err))
46
})
47
}
48
49
function webp2mp4File(path) {
50
return new Promise((resolve, reject) => {
51
const form = new BodyForm()
52
form.append('new-image-url', '')
53
form.append('new-image', fs.createReadStream(path))
54
axios({
55
method: 'post',
56
url: 'https://s6.ezgif.com/webp-to-mp4',
57
data: form,
58
headers: {
59
'Content-Type': `multipart/form-data; boundary=${form._boundary}`
60
}
61
}).then(({ data }) => {
62
const bodyFormThen = new BodyForm()
63
const $ = cheerio.load(data)
64
const file = $('input[name="file"]').attr('value')
65
bodyFormThen.append('file', file)
66
bodyFormThen.append('convert', "Convert WebP to MP4!")
67
axios({
68
method: 'post',
69
url: 'https://ezgif.com/webp-to-mp4/' + file,
70
data: bodyFormThen,
71
headers: {
72
'Content-Type': `multipart/form-data; boundary=${bodyFormThen._boundary}`
73
}
74
}).then(({ data }) => {
75
const $ = cheerio.load(data)
76
const result = 'https:' + $('div#output > p.outfile > video > source').attr('src')
77
resolve({
78
status: true,
79
message: "Created By MRHRTZ",
80
result: result
81
})
82
}).catch(reject)
83
}).catch(reject)
84
})
85
}
86
87
module.exports = { TelegraPh, UploadFileUgu, webp2mp4File }
88
89