master #50

Merged
schrumpel merged 101 commits from master into dev 2022-10-22 23:40:03 +00:00
6 changed files with 108 additions and 25 deletions
Showing only changes of commit 49fb4bfc56 - Show all commits

View File

@ -27,6 +27,7 @@ export default {
left join "user" on "user".id = favorites.user_id
where
${ db.unsafe(modequery) }
and items.active = 'true'
${ tag ? db`and tags.normalized ilike '%' || slugify(${tag}) || '%'` : db`` }
${ o.fav ? db`and "user".user ilike ${'%'+user+'%'}` : db`` }
${ user ? db`and items.username ilike ${'%'+user+'%'}` : db`` }
@ -60,6 +61,7 @@ export default {
left join tags_assign ta on ta.item_id = items.id and (ta.tag_id = 1 or ta.tag_id = 2)
where
${ db.unsafe(modequery) }
and items.active = 'true'
${ tag ? db`and tags.normalized ilike '%' || slugify(${tag}) || '%'` : db`` }
${ o.fav ? db`and "user".user ilike ${'%'+user+'%'}` : db`` }
${ user ? db`and items.username ilike ${'%'+user+'%'}` : db`` }
@ -121,6 +123,7 @@ export default {
left join tags_assign ta on ta.item_id = items.id and (ta.tag_id = 1 or ta.tag_id = 2)
where
${ db.unsafe(modequery) }
and items.active = 'true'
${ tag ? db`and tags.normalized ilike '%' || slugify(${tag}) || '%'` : db`` }
${ o.fav ? db`and "user".user ilike ${'%'+user+'%'}` : db`` }
${ user ? db`and items.username ilike ${'%'+user+'%'}` : db`` }
@ -216,6 +219,7 @@ export default {
left join "user" on "user".id = favorites.user_id
where
${ db.unsafe(modequery) }
and items.active = 'true'
${ tag ? db`and tags.normalized ilike '%' || slugify(${tag}) || '%'` : db`` }
${ o.fav ? db`and "user".user ilike ${'%'+user+'%'}` : db`` }
${ user ? db`and items.username ilike ${'%'+user+'%'}` : db`` }

View File

@ -1,3 +1,4 @@
import { promises as fs } from "fs";
import db from '../../sql.mjs';
import lib from '../../lib.mjs';
import search from '../../routeinc/search.mjs';
@ -16,8 +17,10 @@ export default router => {
const rows = await db`
select *
from "items"
where mime ilike ${mime}
and username ilike ${user}
where
mime ilike ${mime} and
username ilike ${user} and
active = 'true'
order by random()
limit 1
`;
@ -46,7 +49,8 @@ export default router => {
from "items"
left join "tags_assign" on "tags_assign".item_id = "items".id and ("tags_assign".tag_id = 1 or "tags_assign".tag_id = 2)
where
${db.unsafe(modequery)}
${db.unsafe(modequery)} and
active = 'true'
${
opt.older
? db`and id <= ${opt.older}`
@ -76,20 +80,20 @@ export default router => {
const item = await db`
select *
from "items"
where id = ${+id}
where id = ${+id} and active = 'true'
limit 1
`;
const next = await db`
select id
from "items"
where id > ${+id}
where id > ${+id} and active = 'true'
order by id
limit 1
`;
const prev = await db`
select id
from "items"
where id < ${+id}
where id < ${+id} and active = 'true'
order by id desc
limit 1
`;
@ -122,7 +126,7 @@ export default router => {
const rows = db`
select id, mime, size, src, stamp, userchannel, username, usernetwork
from "items"
where username = ${user}
where username = ${user} and active = 'true'
order by stamp desc
limit ${+eps}
`;
@ -222,19 +226,42 @@ export default router => {
msg: 'no postid'
});
}
const postid = +req.post.postid;
const id = +req.post.postid;
if(postid <= 1) {
if(id <= 1) {
return res.json({
success: false
});
}
await db`
delete from "items"
where id = ${+postid}
const f0ck = await db`
select dest, mime
from "items"
where
id = ${id} and
active = 'true'
limit 1
`;
if(f0ck.length === 0) {
return res.json({
success: false,
msg: `f0ck ${id}: f0ck not found`
});
}
await db`update "items" set active = 'false' where id = ${id}`;
await fs.copyFile(`./public/b/${f0ck[0].dest}`, `./deleted/b/${f0ck[0].dest}`).catch(_=>{});
await fs.copyFile(`./public/t/${id}.webp`, `./deleted/t/${id}.webp`).catch(_=>{});
await fs.unlink(`./public/b/${f0ck[0].dest}`).catch(_=>{});
await fs.unlink(`./public/t/${id}.webp`).catch(_=>{});
if(f0ck[0].mime.startsWith('audio')) {
await fs.copyFile(`./public/ca/${id}.webp`, `./deleted/ca/${id}.webp`).catch(_=>{});
await fs.unlink(`./public/ca/${id}.webp`).catch(_=>{});
}
res.json({
success: true
});

View File

@ -16,7 +16,7 @@ export default router => {
const itemid = (await db`
select id
from "items"
where id = ${+avatar}
where id = ${+avatar} and active = 'true'
`)?.[0]?.id;
if(!itemid) {

View File

@ -40,7 +40,9 @@ export default (router, tpl) => {
ret = await db`
select *
from "items"
where src ilike ${'%' + tag.substring(4) + '%'}
where
src ilike ${'%' + tag.substring(4) + '%'} and
active = 1
group by "items".id
order by "items".id desc
offset ${offset}
@ -53,7 +55,7 @@ export default (router, tpl) => {
from "tags"
left join "tags_assign" on "tags_assign".tag_id = "tags".id
left join "items" on "items".id = "tags_assign".item_id
where "tags".tag ilike ${'%' + tag + '%'}
where "tags".tag ilike ${'%' + tag + '%'} and "items".active = 1
group by "items".id, "tags".tag
offset ${offset}
limit ${_eps}

View File

@ -17,9 +17,11 @@ export default async bot => {
continue;
const f0ck = await db`
select dest, username, userchannel, usernetwork
select dest, mime, username, userchannel, usernetwork
from "items"
where id = ${id}
where
id = ${id} and
active = 'true'
limit 1
`;
const level = getLevel(e.user).level;
@ -44,18 +46,66 @@ export default async bot => {
continue;
}
await fs.unlink(`./public/b/${f0ck[0].dest}`).catch(_=>{});
await fs.unlink(`./public/t/${id}`).catch(_=>{});
await db`update "items" set active = 'false' where id = ${id}`;
await db`
delete from "items"
where id = ${+id}
`;
await fs.copyFile(`./public/b/${f0ck[0].dest}`, `./deleted/b/${f0ck[0].dest}`).catch(_=>{});
await fs.copyFile(`./public/t/${id}.webp`, `./deleted/t/${id}.webp`).catch(_=>{});
await fs.unlink(`./public/b/${f0ck[0].dest}`).catch(_=>{});
await fs.unlink(`./public/t/${id}.webp`).catch(_=>{});
if(f0ck[0].mime.startsWith('audio')) {
await fs.copyFile(`./public/ca/${id}.webp`, `./deleted/ca/${id}.webp`).catch(_=>{});
await fs.unlink(`./public/ca/${id}.webp`).catch(_=>{});
}
deleted.push(id);
}
e.reply(`deleted ${deleted.length}/${e.args.length} f0cks (${deleted.join(",")})`);
}
}, {
name: "recover",
call: /^\!(recover) .*/i,
active: true,
level: 100,
f: async e => {
let recovered = [];
for(let id of e.args) {
id = +id;
if(id <= 1)
continue;
const f0ck = await db`
select dest, mime
from "items"
where
id = ${id} and
active = 'false'
limit 1
`;
if(f0ck.length === 0) {
e.reply(`f0ck ${id}: f0ck not found`);
continue;
}
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(_=>{});
}
await db`update "items" set active = 'true' where id = ${id}`;
recovered.push(id);
}
e.reply(`recovered ${recovered.length}/${e.args.length} f0cks (${recovered.join(",")})`);
}
}]
};

View File

@ -137,7 +137,7 @@ export default async bot => {
userchannel: e.channel,
usernetwork: e.network,
stamp: ~~(new Date() / 1000),
active: 1
active: 'true'
}, 'src', 'dest', 'mime', 'size', 'checksum', 'username', 'userchannel', 'usernetwork', 'stamp', 'active')
}
`;