From 0741db09e2e1e94f4a7427f1b348abc9ff415429 Mon Sep 17 00:00:00 2001 From: coomdev Date: Sun, 16 Jan 2022 17:12:57 +0100 Subject: [PATCH] Actually implement uploads for lolisafe-based hosts --- main.meta.js | 2 +- main.user.js | 51 ++++++++++++++++++++++++------------------------ src/filehosts.ts | 37 +++++++++++++++++++++++------------ src/main.ts | 15 +++++++------- src/utils.ts | 10 ++++++++-- 5 files changed, 66 insertions(+), 49 deletions(-) diff --git a/main.meta.js b/main.meta.js index 66f6481..3aaf646 100644 --- a/main.meta.js +++ b/main.meta.js @@ -1,7 +1,7 @@ // ==UserScript== // @name PNGExtraEmbed // @namespace https://coom.tech/ -// @version 0.143 +// @version 0.144 // @description uhh // @author You // @match https://boards.4channel.org/* diff --git a/main.user.js b/main.user.js index 107082b..a049c90 100644 --- a/main.user.js +++ b/main.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name PNGExtraEmbed // @namespace https://coom.tech/ -// @version 0.143 +// @version 0.144 // @description uhh // @author You // @match https://boards.4channel.org/* @@ -11465,19 +11465,32 @@ // src/filehosts.ts init_esbuild_inject(); - var lolisafe = (domain) => ({ - domain, - async uploadFile(f) { - return ""; - } - }); function parseForm(data) { const form = new FormData(); Object.entries(data).filter(([key, value]) => value !== null).map(([key, value]) => form.append(key, value)); return form; } - var catbox = (domain) => ({ + var lolisafe = (domain, serving = domain) => ({ + domain, + serving, + async uploadFile(f) { + const resp = await GM_fetch(`https://${domain}/api/upload`, { + headers: { + accept: "application/json" + }, + "body": parseForm({ + reqtype: "fileupload", + "files[]": new File([f], "f.pee") + }), + "method": "POST" + }); + const res = await resp.json(); + return res.files.map((e) => e.url)[0]; + } + }); + var catbox = (domain, serving) => ({ domain, + serving, async uploadFile(inj) { const resp = await GM_fetch(`https://${domain}/user/api.php`, { method: "POST", @@ -11490,13 +11503,10 @@ } }); var filehosts = [ - catbox("catbox.moe"), - lolisafe("zz.ht"), + catbox("catbox.moe", "files.catbox.moe"), + lolisafe("zz.ht", "z.zz.fo"), lolisafe("imouto.kawaii.su"), - lolisafe("take-me-to.space"), - lolisafe("loli.solutions"), - lolisafe("loli.graphics"), - lolisafe("sucks-to-b.eu") + lolisafe("take-me-to.space") ]; // src/utils.ts @@ -11566,7 +11576,7 @@ return new Blob([ret]); }; var decodeCoom3Payload = async (buff) => { - const allowed_domains = filehosts.map((e) => e.domain); + const allowed_domains = filehosts.map((e) => e.serving.replaceAll(".", "\\.")); const pees = buff.toString().split(" ").slice(0, csettings2.maxe).filter((e) => allowed_domains.some((v) => e.match(`https://(.*\\.)?${v}/`))); return (await Promise.all(pees.map(async (pee) => { try { @@ -18765,17 +18775,6 @@ } post.setAttribute("data-processed", "true"); } - if (window["pagemode"]) { - onload = () => { - document.body.innerHTML = ""; - new App_default({ - target: document.body - }); - setTimeout(() => { - document.dispatchEvent(new CustomEvent("penis")); - }, 30); - }; - } })(); /*! * The buffer module from node.js, for the browser. diff --git a/src/filehosts.ts b/src/filehosts.ts index 50b289d..67de395 100644 --- a/src/filehosts.ts +++ b/src/filehosts.ts @@ -1,12 +1,5 @@ import { GM_fetch } from "./requests"; -const lolisafe = (domain: string) => ({ - domain, - async uploadFile(f: Blob) { - return ''; - } -}); - function parseForm(data: object) { const form = new FormData(); @@ -17,8 +10,28 @@ function parseForm(data: object) { return form; } -const catbox = (domain: string) => ({ +export const lolisafe = (domain: string, serving = domain) => ({ + domain, + serving, + async uploadFile(f: Blob) { + const resp = await GM_fetch(`https://${domain}/api/upload`, { + headers: { + accept: "application/json", + }, + "body": parseForm({ + reqtype: 'fileupload', + 'files[]': new File([f], 'f.pee') + }), + "method": "POST", + }); + const res = (await resp.json()) as { success: boolean, files: { url: string, name: string, size: number }[] }; + return res.files.map(e => e.url)[0]; + } +}); + +export const catbox = (domain: string, serving: string) => ({ domain, + serving, async uploadFile(inj: Blob) { const resp = await GM_fetch(`https://${domain}/user/api.php`, { method: 'POST', @@ -33,15 +46,13 @@ const catbox = (domain: string) => ({ export type API = { domain: string; + serving: string; uploadFile(f: Blob): Promise; } export const filehosts: API[] = [ - catbox('catbox.moe'), - lolisafe('zz.ht'), + catbox('catbox.moe', 'files.catbox.moe'), + lolisafe('zz.ht', 'z.zz.fo'), lolisafe('imouto.kawaii.su'), lolisafe('take-me-to.space'), - lolisafe('loli.solutions'), - lolisafe('loli.graphics'), - lolisafe('sucks-to-b.eu') ]; \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 7f45858..ead6236 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,6 +22,7 @@ import NotificationsHandler from './Components/NotificationsHandler.svelte'; import { buildPeeFile, fireNotification } from "./utils"; import { fileTypeFromBuffer } from "file-type"; import { getQueryProcessor, QueryProcessor } from "./websites"; +import { lolisafe } from "./filehosts"; export interface ImageProcessor { skip?: true; @@ -484,16 +485,16 @@ function processAttachments(post: HTMLDivElement, ress: [EmbeddedFile, boolean][ // const resbuf = async (s: EmbeddedFile['data']) => typeof s != "string" && (Buffer.isBuffer(s) ? s : await s()); // const container = document.getElementById("container") as HTMLInputElement; // container.onchange = async () => { -// const result = document.getElementById("result") as HTMLImageElement; -// const output = await convertToPng(container.files![0]); -// if (!output) -// return; -// result.src = URL.createObjectURL(output); +// const api = lolisafe('zz.ht', 'z.zz.fo'); +// const file = container.files![0]; +// const blo = new Blob([file], {type: 'application/octet-stream'}); +// const link = await api.uploadFile(blo); +// console.log(link); // }; // }; //} - -//if ((window as any)['pagemode']) { +// +////if ((window as any)['pagemode']) { // onload = () => { // const extraction = document.getElementById("extraction") as HTMLInputElement; // extraction.onchange = async () => { diff --git a/src/utils.ts b/src/utils.ts index 17e106d..61b1789 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -96,8 +96,14 @@ rest: [X bytes of thumbnail data])[file bytes] &4 => has thumbnail */ export const decodeCoom3Payload = async (buff: Buffer) => { - const allowed_domains = filehosts.map(e => e.domain); - const pees = buff.toString().split(' ').slice(0, csettings.maxe).filter(e => allowed_domains.some(v => e.match(`https://(.*\\.)?${v}/`))); + const allowed_domains = filehosts.map(e => e.serving.replaceAll('.', '\\.')); + const pees = buff + .toString() + .split(' ') + .slice(0, csettings.maxe) + .filter(e => allowed_domains + .some(v => e.match(`https://(.*\\.)?${v}/`))); + return (await Promise.all(pees.map(async pee => { try { const headers = headerStringToObject(await GM_head(pee));