diff --git a/public/s/css/f0ck.css b/public/s/css/f0ck.css index f2ac346..7d530b9 100644 --- a/public/s/css/f0ck.css +++ b/public/s/css/f0ck.css @@ -803,6 +803,10 @@ html[theme="f0ck95"] .badge-danger { border-radius: 0; } +html[theme="f0ck95"] img.avatar { + border-top-left-radius: 0; +} + html[theme="f0ck95"] ._204863 { content: " "; background: -webkit-linear-gradient(left,#08216b,#a5cef7); diff --git a/src/inc/routes/admin.mjs b/src/inc/routes/admin.mjs index 139504b..490f8f0 100644 --- a/src/inc/routes/admin.mjs +++ b/src/inc/routes/admin.mjs @@ -1,6 +1,7 @@ import db from "../sql.mjs"; import lib from "../lib.mjs"; import { exec } from "child_process"; +import { promises as fs } from "fs"; const auth = async (req, res, next) => { if(!req.session) { @@ -130,5 +131,61 @@ export default (router, tpl) => { }); }); + router.get(/^\/admin\/recover\/?/, auth, async (req, res) => { + if(req.url.qs?.id) { + const id = +req.url.qs.id; + const f0ck = await db` + select dest, mime + from "items" + where + id = ${id} and + active = 'false' + limit 1 + `; + if(f0ck.length === 0) { + return res.reply({ + body: `f0ck ${id}: f0ck not found` + }); + } + + await db`update "items" set active = 'true' where id = ${id}`; + + await fs.copyFile(`./deleted/b/${f0ck[0].dest}`, `./public/b/${f0ck[0].dest}`).catch(_=>{}); + await fs.copyFile(`./deleted/t/${id}.webp`, `./public/t/${id}.webp`).catch(_=>{}); + await fs.unlink(`./deleted/b/${f0ck[0].dest}`).catch(_=>{}); + await fs.unlink(`./deleted/t/${id}.webp`).catch(_=>{}); + + if(f0ck[0].mime.startsWith('audio')) { + await fs.copyFile(`./deleted/ca/${id}.webp`, `./public/ca/${id}.webp`).catch(_=>{}); + await fs.unlink(`./deleted/ca/${id}.webp`).catch(_=>{}); + } + + return res.reply({ + body: `f0ck ${id} recovered. back` + }); + } + + const _posts = await db` + select id, mime, username + from "items" + where + active = 'false' + `; + + if(_posts.length === 0) { + return res.reply({ + body: 'blah' + }); + } + + const posts = await Promise.all(_posts.map(async p => ({ ...p, thumbnail: (await fs.readFile(`./deleted/t/${p.id}.webp`)).toString('base64') }))); + + res.reply({ + body: tpl.render('admin/recover', { + posts + }, req) + }); + }); + return router; }; diff --git a/src/inc/trigger/parser.mjs b/src/inc/trigger/parser.mjs index 84fab3b..4d15d82 100644 --- a/src/inc/trigger/parser.mjs +++ b/src/inc/trigger/parser.mjs @@ -137,7 +137,7 @@ export default async bot => { userchannel: e.channel, usernetwork: e.network, stamp: ~~(new Date() / 1000), - active: 'true' + active: true }, 'src', 'dest', 'mime', 'size', 'checksum', 'username', 'userchannel', 'usernetwork', 'stamp', 'active') } `; diff --git a/views/admin/recover.html b/views/admin/recover.html new file mode 100644 index 0000000..6ef1f0b --- /dev/null +++ b/views/admin/recover.html @@ -0,0 +1,24 @@ +@include(snippets/header_admin) + + + + + + + + + + + +@each(posts as post) + + + + + + + +@endeach + +
IDf0ckermime
{{ post.id }}{{ post.username }}{{ post.mime }}recover
+@include(snippets/footer) \ No newline at end of file diff --git a/views/snippets/navbar.html b/views/snippets/navbar.html index 7f60d5c..c56bab0 100644 --- a/views/snippets/navbar.html +++ b/views/snippets/navbar.html @@ -25,7 +25,7 @@ @endif