Spaces:
Paused
Paused
Update lib/uploader.js
Browse files- lib/uploader.js +33 -2
lib/uploader.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
| 1 |
import axios from "axios";
|
|
|
|
| 2 |
import FormData from "form-data";
|
| 3 |
import {fileTypeFromBuffer} from 'file-type';
|
| 4 |
|
| 5 |
-
async function Uploader(
|
| 6 |
try {
|
|
|
|
| 7 |
// data
|
| 8 |
-
const
|
|
|
|
|
|
|
| 9 |
const filenames = "images_" + Math.floor(1000 + Math.random() * 9000) + "." + types.ext;
|
| 10 |
// memasukan data ke formdata
|
| 11 |
const form = new FormData();
|
|
@@ -29,6 +33,33 @@ async function Uploader(imgBuffer) {
|
|
| 29 |
});
|
| 30 |
|
| 31 |
return res.data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
} catch(e) {
|
| 33 |
return e.message;
|
| 34 |
}
|
|
|
|
| 1 |
import axios from "axios";
|
| 2 |
+
import fetch from "node-fetch";
|
| 3 |
import FormData from "form-data";
|
| 4 |
import {fileTypeFromBuffer} from 'file-type';
|
| 5 |
|
| 6 |
+
async function Uploader(input) {
|
| 7 |
try {
|
| 8 |
+
if(typeof input == "string") {
|
| 9 |
// data
|
| 10 |
+
const res = await fetch(input);
|
| 11 |
+
const images = await res.arrayBuffer();
|
| 12 |
+
const types = await fileTypeFromBuffer(images);
|
| 13 |
const filenames = "images_" + Math.floor(1000 + Math.random() * 9000) + "." + types.ext;
|
| 14 |
// memasukan data ke formdata
|
| 15 |
const form = new FormData();
|
|
|
|
| 33 |
});
|
| 34 |
|
| 35 |
return res.data;
|
| 36 |
+
} else if(typeof input == "object") {
|
| 37 |
+
// data
|
| 38 |
+
const types = await fileTypeFromBuffer(imgBuffer);
|
| 39 |
+
const filenames = "images_" + Math.floor(1000 + Math.random() * 9000) + "." + types.ext;
|
| 40 |
+
// memasukan data ke formdata
|
| 41 |
+
const form = new FormData();
|
| 42 |
+
form.append("image", Buffer.from(input, "binary"), {
|
| 43 |
+
filename: filenames,
|
| 44 |
+
contentType: types.mime
|
| 45 |
+
});
|
| 46 |
+
form.append("pageTitle", "Tạo ảnh Anime AI theo ảnh của bạn");
|
| 47 |
+
form.append("pageURL", "https://taoanhdep.com/tao-anh-anime-ai-theo-anh-cua-ban/");
|
| 48 |
+
|
| 49 |
+
const res = await axios({
|
| 50 |
+
method: "POST",
|
| 51 |
+
url: "https://phimtat.vn/up/upload.php",
|
| 52 |
+
data: form,
|
| 53 |
+
headers: {
|
| 54 |
+
...form.getHeaders(),
|
| 55 |
+
"User-Agent": "okhttp/4.9.0",
|
| 56 |
+
"Content-Type": "multipart/form-data; boundary=----WebKitFormBoundary9xpHSK9nPN4BEVJa",
|
| 57 |
+
"Origin": "https://taoanhdep.com"
|
| 58 |
+
}
|
| 59 |
+
});
|
| 60 |
+
|
| 61 |
+
return res.data;
|
| 62 |
+
}
|
| 63 |
} catch(e) {
|
| 64 |
return e.message;
|
| 65 |
}
|