forked from BOTCAHX/RTXZY-MD
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
42 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,27 @@ | ||
const axios = require('axios'); | ||
const FormData = require('form-data'); | ||
const { fromBuffer } = require('file-type'); | ||
const fetch = require('node-fetch') | ||
const FormData = require('form-data') | ||
const { fromBuffer } = require('file-type') | ||
|
||
/** | ||
* Upload image to qu.ax | ||
* Supported mimetype: | ||
* - `image/jpeg` | ||
* - `image/jpg` | ||
* - `image/png` | ||
* @param {Buffer} buffer Image Buffer | ||
*/ | ||
* Upload image to url | ||
* Supported mimetype: | ||
* - `image/jpeg` | ||
* - `image/jpg` | ||
* - `image/png` | ||
* - `video/mp4` | ||
* - `all files` | ||
* @param {Buffer} buffer Image Buffer | ||
*/ | ||
|
||
module.exports = async (buffer) => { | ||
const { ext, mime } = await fromBuffer(buffer); | ||
const form = new FormData(); | ||
form.append('files[]', buffer, { | ||
filename: 'tmp.' + ext, | ||
contentType: mime, | ||
let { ext } = await fromBuffer(buffer); | ||
let bodyForm = new FormData(); | ||
bodyForm.append("file", buffer, "file." + ext); | ||
let res = await fetch("https://i.supa.codes/api/upload", { | ||
method: "post", | ||
body: bodyForm, | ||
}); | ||
|
||
const { data } = await axios.post( | ||
"https://qu.ax/upload.php", | ||
form, | ||
{ | ||
headers: { | ||
...form.getHeaders(), | ||
} | ||
} | ||
); | ||
|
||
return data.files[0].url; | ||
}; | ||
let data = await res.json(); | ||
let resultUrl = data | ||
return resultUrl.link | ||
} |