0.0.1 - test
This commit is contained in:
70
controller/modules/type.post.js
Normal file
70
controller/modules/type.post.js
Normal file
@@ -0,0 +1,70 @@
|
||||
import Config from "../../config/config.js";
|
||||
import { sendFileWithPayload } from "../helper/uploadWithPayload.js";
|
||||
|
||||
import fetch from "node-fetch"
|
||||
|
||||
export default class Post {
|
||||
|
||||
static operationSelect(body) {
|
||||
switch (body.operation) {
|
||||
case "created":
|
||||
Post.created(body);
|
||||
break;
|
||||
case "modified":
|
||||
Post.modified(body);
|
||||
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static async created(body) {
|
||||
let x = await fetch(`${Config.booru_url}/api/post/${body.id}`, {
|
||||
"headers": {
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json",
|
||||
"Accept-Encoding": "multipart/form-data",
|
||||
"Authorization": `Token ${Config.booru_token}`
|
||||
//"cookie": "auth={%22user%22:%22Test%22%2C%22token%22:%229b0bd51b-61cd-4ce5-a6b7-5fe215edc46f%22}",
|
||||
},
|
||||
"body": null,
|
||||
"method": "GET"
|
||||
});
|
||||
let api_resp = await x.json();
|
||||
console.log(api_resp)
|
||||
console.log(`${Config.booru_url}/${api_resp.thumbnailUrl}`)
|
||||
let imgData = null;
|
||||
let type = "";
|
||||
switch(api_resp.mimeType){
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
case "image/png":
|
||||
case "image/gif":
|
||||
if(api_resp.fileSize>13107200){
|
||||
imgData = await fetch(`${Config.booru_url}/${api_resp.thumbnailUrl}`);
|
||||
let tmp = api_resp.thumbnailUrl.split(".")
|
||||
type = tmp[tmp.length-1]
|
||||
}else{
|
||||
imgData = await fetch(`${Config.booru_url}/${api_resp.contentUrl}`);
|
||||
let tmp = api_resp.contentUrl.split(".")
|
||||
type = tmp[tmp.length-1]
|
||||
}
|
||||
break;
|
||||
default:
|
||||
imgData = await fetch(`${Config.booru_url}/${api_resp.thumbnailUrl}`);
|
||||
let tmp = api_resp.thumbnailUrl.split(".")
|
||||
type = tmp[tmp.length-1]
|
||||
break;
|
||||
}
|
||||
console.log(imgData)
|
||||
let imgD = await imgData.arrayBuffer();
|
||||
let filename = `${api_resp.id}.${type}`;
|
||||
sendFileWithPayload(Config.webhook_url, imgD,filename,api_resp)
|
||||
}
|
||||
static modified(body) {
|
||||
Post.created(body);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user