aktueller Stand
This commit is contained in:
@ -3,22 +3,22 @@ import sql from "../sql.mjs";
|
||||
import { parse } from "url";
|
||||
import cfg from "../../../config.json";
|
||||
|
||||
import { mimes, queries } from "./inc/api.mjs";
|
||||
import { mimes, queries } from "./inc/apiv1.mjs";
|
||||
|
||||
router.get("/api", (req, res) => {
|
||||
router.get("/api/v1", (req, res) => {
|
||||
res.end("api lol");
|
||||
});
|
||||
|
||||
router.get(/^\/api\/random(\/user\/.+|\/image|\/video|\/audio)?$/, async (req, res) => {
|
||||
router.get(/^\/api\/v1\/random(\/user\/.+|\/image|\/video|\/audio)?$/, async (req, res) => {
|
||||
const args = [];
|
||||
let q = queries.random.main;
|
||||
|
||||
if(req.url.split[2] === "user") {
|
||||
if(req.url.split[3] === "user") {
|
||||
q += queries.random.where("username like ?");
|
||||
args.push(req.url.split[3] || "flummi");
|
||||
args.push(req.url.split[4] || "flummi");
|
||||
}
|
||||
else
|
||||
q += queries.random.where(mimes[req.url.split[2]] ? mimes[req.url.split[2]].map(mime => `mime = "${mime}"`).join(" or ") : null);
|
||||
q += queries.random.where(mimes[req.url.split[3]] ? mimes[req.url.split[3]].map(mime => `mime = "${mime}"`).join(" or ") : null);
|
||||
|
||||
try {
|
||||
const rows = await sql.query(q, args);
|
||||
@ -32,7 +32,7 @@ router.get(/^\/api\/random(\/user\/.+|\/image|\/video|\/audio)?$/, async (req, r
|
||||
}
|
||||
});
|
||||
|
||||
router.get("/api/p", async (req, res) => {
|
||||
router.get("/api/v1/p", async (req, res) => {
|
||||
let id = parseInt(req.url.qs.id) || 99999999;
|
||||
const eps = Math.min(parseInt(req.url.qs.eps) || 100, 200);
|
||||
let [ order, trend ] = req.url.qs.order === "asc" ? [ "asc", ">" ] : [ "desc", "<" ];
|
||||
@ -67,9 +67,9 @@ router.get("/api/p", async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.get(/^\/api\/p\/([0-9]+)/, async (req, res) => { // legacy
|
||||
router.get(/^\/api\/v1\/p\/([0-9]+)/, async (req, res) => { // legacy
|
||||
let eps = 100;
|
||||
let id = +req.url.split[2];
|
||||
let id = +req.url.split[3];
|
||||
|
||||
const query = await sql.query("select * from items where id < ? order by id desc limit ?", [ id, eps ]);
|
||||
const items = {
|
||||
@ -81,9 +81,9 @@ router.get(/^\/api\/p\/([0-9]+)/, async (req, res) => { // legacy
|
||||
res.end(JSON.stringify(items), "utf-8");
|
||||
});
|
||||
|
||||
router.get(/^\/api\/item\/[0-9]+$/, async (req, res) => {
|
||||
router.get(/^\/api\/v1\/item\/[0-9]+$/, async (req, res) => {
|
||||
try {
|
||||
const rows = await sql.query(queries.item, Array(3).fill(req.url.split[2]));
|
||||
const rows = await sql.query(queries.item, Array(3).fill(req.url.split[3]));
|
||||
res.reply({
|
||||
type: "application/json",
|
||||
body: JSON.stringify(rows?.shift() || [])
|
||||
@ -96,9 +96,9 @@ router.get(/^\/api\/item\/[0-9]+$/, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.get(/^\/api\/user\/.*(\/[0-9]+)?$/, async (req, res) => { // auf qs umstellen
|
||||
const user = req.url.split[2];
|
||||
const eps = Math.min(req.url.split[3] || 50, 50);
|
||||
router.get(/^\/api\/v1\/user\/.*(\/[0-9]+)?$/, async (req, res) => { // auf qs umstellen
|
||||
const user = req.url.split[3];
|
||||
const eps = Math.min(req.url.split[4] || 50, 50);
|
||||
try {
|
||||
const rows = await sql.query(queries.user, [ user, eps ]);
|
||||
res.reply({
|
@ -1,6 +1,7 @@
|
||||
import router from "../router.mjs";
|
||||
import cfg from "../../../config.json";
|
||||
import url from "url";
|
||||
import fs from "fs";
|
||||
import { queries } from "./inc/index.mjs";
|
||||
import sql from "../sql.mjs";
|
||||
import lib from "../lib.mjs";
|
||||
@ -8,22 +9,55 @@ import tpl from "../tpl.mjs";
|
||||
|
||||
tpl.readdir("views");
|
||||
|
||||
router.get("/", async (req, res) => {
|
||||
const query = await sql.query("select id, mime from items order by id desc limit 300");
|
||||
const data = {
|
||||
items: query,
|
||||
last: query[query.length - 1].id
|
||||
};
|
||||
router.get(/\/(p\/\d+)?$/, async (req, res) => {
|
||||
try {
|
||||
const total = (await sql.query("select count(*) as total from items"))[0].total;
|
||||
const limit = 299;
|
||||
const pages = +Math.ceil(total / limit);
|
||||
const page = Math.min(pages, +req.url.split[1] || 1);
|
||||
const offset = (page - 1) * limit;
|
||||
|
||||
res.reply({ body: tpl.render("views/index", data) });
|
||||
const query = await sql.query("select id, mime from items order by id desc limit ?, ?", [ offset, limit ]);
|
||||
|
||||
let cheat = [];
|
||||
for(let i = Math.max(1, page - 3); i <= Math.min(page + 3, pages); i++)
|
||||
cheat.push(i);
|
||||
|
||||
query.forEach(e => {
|
||||
if(!fs.existsSync(`public/t/${e.id}.png`))
|
||||
fs.copyFileSync("public/s/img/broken.png", `public/t/${e.id}.png`);
|
||||
});
|
||||
|
||||
const data = {
|
||||
items: query,
|
||||
pagination: {
|
||||
end: pages,
|
||||
prev: (page > 1) ? page - 1 : null,
|
||||
next: (page < pages) ? page + 1 : null,
|
||||
page: page,
|
||||
cheat: cheat,
|
||||
link: "/p/"
|
||||
},
|
||||
last: query[query.length - 1].id
|
||||
};
|
||||
|
||||
res.reply({ body: tpl.render("views/index", data) });
|
||||
} catch(err) {
|
||||
res.reply({ body: "error :(" });
|
||||
}
|
||||
});
|
||||
|
||||
router.get(/^\/([0-9]+)$/, async (req, res) => {
|
||||
const query = (await sql.query(queries.item, Array(3).fill(req.url.split[0])))?.shift();
|
||||
const qmax = (await sql.query("select id from items order by id desc limit 1"))[0].id;
|
||||
|
||||
if(!query?.id)
|
||||
return res.redirect("/404");
|
||||
|
||||
let cheat = [];
|
||||
for(let i = Math.min(query.id + 3, qmax); i >= Math.max(1, query.id - 3); i--)
|
||||
cheat.push(i);
|
||||
|
||||
const data = {
|
||||
user: {
|
||||
name: query.username,
|
||||
@ -44,7 +78,15 @@ router.get(/^\/([0-9]+)$/, async (req, res) => {
|
||||
},
|
||||
next: query.next ? query.next : null,
|
||||
prev: query.prev ? query.prev : null,
|
||||
title: `${query.id} - f0ck.me`
|
||||
title: `${query.id} - f0ck.me`,
|
||||
pagination: {
|
||||
end: 1,
|
||||
prev: query.id + 1,
|
||||
next: Math.max(query.id - 1, 1),
|
||||
page: query.id,
|
||||
cheat: cheat,
|
||||
link: "/"
|
||||
}
|
||||
};
|
||||
res.reply({ body: tpl.render("views/item", data) });
|
||||
});
|
||||
|
@ -3,7 +3,7 @@ import sql from "../sql.mjs";
|
||||
import lib from "../lib.mjs";
|
||||
|
||||
const _query = "select id, mime, size, username, userchannel, usernetwork, stamp from items where ";
|
||||
const regex = /https\:\/\/f0ck\.me\/(\d+|(?:b\/)(\w{8})\.(jpg|webm|gif|mp4|png|mov|mp3|ogg|flac))/gi;
|
||||
const regex = /(https\:\/\/f0ck\.me|http\:\/\/fockmoonsb24iczs7odozzy5uktlzbcgp337nabrgffzxv5ihabgpvyd\.onion)\/(\d+|(?:b\/)(\w{8})\.(jpg|webm|gif|mp4|png|mov|mp3|ogg|flac))/gi;
|
||||
|
||||
export default async bot => {
|
||||
|
||||
|
@ -132,9 +132,9 @@ export default async bot => {
|
||||
speed = !Number.isFinite(speed) ? "yes" : `${speed.toFixed(2)} Mbit/s`;
|
||||
|
||||
e.reply([
|
||||
`title: ${meta.fulltitle}`,
|
||||
`size: ${lib.formatSize(size)} speed: ${speed}`,
|
||||
`link: ${cfg.main.url}/${insertq.insertId}`
|
||||
//`title: ${meta.fulltitle}`,
|
||||
`link: ${cfg.main.url}/${insertq.insertId} | size: ${lib.formatSize(size)} | speed: ${speed}`
|
||||
//`link: ${cfg.main.url}/${insertq.insertId}`
|
||||
]);
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user