Spaces:
Running
Running
File size: 2,456 Bytes
c6a5297 d3c8566 c6a5297 d3c8566 c6a5297 d3c8566 c6a5297 b037b57 d3c8566 a6c3c6f c6a5297 7631802 c6a5297 d3c8566 7631802 d3c8566 c6a5297 |
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 |
import axios from "axios";
import fetch from "node-fetch";
import FormData from "form-data";
import {fileTypeFromBuffer} from 'file-type';
async function Uploader(input) {
try {
if(typeof input == "string") {
// data
const resp = await fetch(input);
const images = await resp.arrayBuffer();
const types = await fileTypeFromBuffer(images);
const filenames = "images_" + Math.floor(1000 + Math.random() * 9000) + "." types.ext;
// memasukan data ke formdata
const form = new FormData();
form.append("image", Buffer.from(images, "binary"), {
filename: filenames,
contentType: types.mime
});
form.append("pageTitle", "Tạo ảnh Anime AI theo ảnh của bạn");
form.append("pageURL", "https://taoanhdep.com/tao-anh-anime-ai-theo-anh-cua-ban/");
const res = await axios({
method: "POST",
url: "https://phimtat.vn/up/upload.php",
data: form,
headers: {
...form.getHeaders(),
"User-Agent": "okhttp/4.9.0",
"Content-Type": "multipart/form-data; boundary=----WebKitFormBoundary9xpHSK9nPN4BEVJa",
"Origin": "https://taoanhdep.com"
}
});
return res.data;
} else if(typeof input == "object") {
// data
const types = await fileTypeFromBuffer(input);
const filenames = "images_" + Math.floor(1000 + Math.random() * 9000) + "." + types.ext;
// memasukan data ke formdata
const form = new FormData();
form.append("image", Buffer.from(input, "binary"), {
filename: filenames,
contentType: types.mime
});
form.append("pageTitle", "Tạo ảnh Anime AI theo ảnh của bạn");
form.append("pageURL", "https://taoanhdep.com/tao-anh-anime-ai-theo-anh-cua-ban/");
const res = await axios({
method: "POST",
url: "https://phimtat.vn/up/upload.php",
data: form,
headers: {
...form.getHeaders(),
"User-Agent": "okhttp/4.9.0",
"Content-Type": "multipart/form-data; boundary=----WebKitFormBoundary9xpHSK9nPN4BEVJa",
"Origin": "https://taoanhdep.com"
}
});
return res.data;
}
} catch(e) {
return e.message;
}
}
export { Uploader } |