soft delete v1
This commit is contained in:
parent
d2091494a1
commit
c6fbe956a0
|
@ -27,6 +27,7 @@ export default {
|
||||||
left join "user" on "user".id = favorites.user_id
|
left join "user" on "user".id = favorites.user_id
|
||||||
where
|
where
|
||||||
${ db.unsafe(modequery) }
|
${ db.unsafe(modequery) }
|
||||||
|
and items.active = 'true'
|
||||||
${ tag ? db`and tags.normalized ilike '%' || slugify(${tag}) || '%'` : db`` }
|
${ tag ? db`and tags.normalized ilike '%' || slugify(${tag}) || '%'` : db`` }
|
||||||
${ o.fav ? db`and "user".user ilike ${'%'+user+'%'}` : db`` }
|
${ o.fav ? db`and "user".user ilike ${'%'+user+'%'}` : db`` }
|
||||||
${ user ? db`and items.username 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)
|
left join tags_assign ta on ta.item_id = items.id and (ta.tag_id = 1 or ta.tag_id = 2)
|
||||||
where
|
where
|
||||||
${ db.unsafe(modequery) }
|
${ db.unsafe(modequery) }
|
||||||
|
and items.active = 'true'
|
||||||
${ tag ? db`and tags.normalized ilike '%' || slugify(${tag}) || '%'` : db`` }
|
${ tag ? db`and tags.normalized ilike '%' || slugify(${tag}) || '%'` : db`` }
|
||||||
${ o.fav ? db`and "user".user ilike ${'%'+user+'%'}` : db`` }
|
${ o.fav ? db`and "user".user ilike ${'%'+user+'%'}` : db`` }
|
||||||
${ user ? db`and items.username 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)
|
left join tags_assign ta on ta.item_id = items.id and (ta.tag_id = 1 or ta.tag_id = 2)
|
||||||
where
|
where
|
||||||
${ db.unsafe(modequery) }
|
${ db.unsafe(modequery) }
|
||||||
|
and items.active = 'true'
|
||||||
${ tag ? db`and tags.normalized ilike '%' || slugify(${tag}) || '%'` : db`` }
|
${ tag ? db`and tags.normalized ilike '%' || slugify(${tag}) || '%'` : db`` }
|
||||||
${ o.fav ? db`and "user".user ilike ${'%'+user+'%'}` : db`` }
|
${ o.fav ? db`and "user".user ilike ${'%'+user+'%'}` : db`` }
|
||||||
${ user ? db`and items.username 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
|
left join "user" on "user".id = favorites.user_id
|
||||||
where
|
where
|
||||||
${ db.unsafe(modequery) }
|
${ db.unsafe(modequery) }
|
||||||
|
and items.active = 'true'
|
||||||
${ tag ? db`and tags.normalized ilike '%' || slugify(${tag}) || '%'` : db`` }
|
${ tag ? db`and tags.normalized ilike '%' || slugify(${tag}) || '%'` : db`` }
|
||||||
${ o.fav ? db`and "user".user ilike ${'%'+user+'%'}` : db`` }
|
${ o.fav ? db`and "user".user ilike ${'%'+user+'%'}` : db`` }
|
||||||
${ user ? db`and items.username ilike ${'%'+user+'%'}` : db`` }
|
${ user ? db`and items.username ilike ${'%'+user+'%'}` : db`` }
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { promises as fs } from "fs";
|
||||||
import db from '../../sql.mjs';
|
import db from '../../sql.mjs';
|
||||||
import lib from '../../lib.mjs';
|
import lib from '../../lib.mjs';
|
||||||
import search from '../../routeinc/search.mjs';
|
import search from '../../routeinc/search.mjs';
|
||||||
|
@ -16,8 +17,10 @@ export default router => {
|
||||||
const rows = await db`
|
const rows = await db`
|
||||||
select *
|
select *
|
||||||
from "items"
|
from "items"
|
||||||
where mime ilike ${mime}
|
where
|
||||||
and username ilike ${user}
|
mime ilike ${mime} and
|
||||||
|
username ilike ${user} and
|
||||||
|
active = 'true'
|
||||||
order by random()
|
order by random()
|
||||||
limit 1
|
limit 1
|
||||||
`;
|
`;
|
||||||
|
@ -46,7 +49,8 @@ export default router => {
|
||||||
from "items"
|
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)
|
left join "tags_assign" on "tags_assign".item_id = "items".id and ("tags_assign".tag_id = 1 or "tags_assign".tag_id = 2)
|
||||||
where
|
where
|
||||||
${db.unsafe(modequery)}
|
${db.unsafe(modequery)} and
|
||||||
|
active = 'true'
|
||||||
${
|
${
|
||||||
opt.older
|
opt.older
|
||||||
? db`and id <= ${opt.older}`
|
? db`and id <= ${opt.older}`
|
||||||
|
@ -76,20 +80,20 @@ export default router => {
|
||||||
const item = await db`
|
const item = await db`
|
||||||
select *
|
select *
|
||||||
from "items"
|
from "items"
|
||||||
where id = ${+id}
|
where id = ${+id} and active = 'true'
|
||||||
limit 1
|
limit 1
|
||||||
`;
|
`;
|
||||||
const next = await db`
|
const next = await db`
|
||||||
select id
|
select id
|
||||||
from "items"
|
from "items"
|
||||||
where id > ${+id}
|
where id > ${+id} and active = 'true'
|
||||||
order by id
|
order by id
|
||||||
limit 1
|
limit 1
|
||||||
`;
|
`;
|
||||||
const prev = await db`
|
const prev = await db`
|
||||||
select id
|
select id
|
||||||
from "items"
|
from "items"
|
||||||
where id < ${+id}
|
where id < ${+id} and active = 'true'
|
||||||
order by id desc
|
order by id desc
|
||||||
limit 1
|
limit 1
|
||||||
`;
|
`;
|
||||||
|
@ -122,7 +126,7 @@ export default router => {
|
||||||
const rows = db`
|
const rows = db`
|
||||||
select id, mime, size, src, stamp, userchannel, username, usernetwork
|
select id, mime, size, src, stamp, userchannel, username, usernetwork
|
||||||
from "items"
|
from "items"
|
||||||
where username = ${user}
|
where username = ${user} and active = 'true'
|
||||||
order by stamp desc
|
order by stamp desc
|
||||||
limit ${+eps}
|
limit ${+eps}
|
||||||
`;
|
`;
|
||||||
|
@ -222,19 +226,42 @@ export default router => {
|
||||||
msg: 'no postid'
|
msg: 'no postid'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const postid = +req.post.postid;
|
const id = +req.post.postid;
|
||||||
|
|
||||||
if(postid <= 1) {
|
if(id <= 1) {
|
||||||
return res.json({
|
return res.json({
|
||||||
success: false
|
success: false
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await db`
|
const f0ck = await db`
|
||||||
delete from "items"
|
select dest, mime
|
||||||
where id = ${+postid}
|
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({
|
res.json({
|
||||||
success: true
|
success: true
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,7 +16,7 @@ export default router => {
|
||||||
const itemid = (await db`
|
const itemid = (await db`
|
||||||
select id
|
select id
|
||||||
from "items"
|
from "items"
|
||||||
where id = ${+avatar}
|
where id = ${+avatar} and active = 'true'
|
||||||
`)?.[0]?.id;
|
`)?.[0]?.id;
|
||||||
|
|
||||||
if(!itemid) {
|
if(!itemid) {
|
||||||
|
|
|
@ -40,7 +40,9 @@ export default (router, tpl) => {
|
||||||
ret = await db`
|
ret = await db`
|
||||||
select *
|
select *
|
||||||
from "items"
|
from "items"
|
||||||
where src ilike ${'%' + tag.substring(4) + '%'}
|
where
|
||||||
|
src ilike ${'%' + tag.substring(4) + '%'} and
|
||||||
|
active = 1
|
||||||
group by "items".id
|
group by "items".id
|
||||||
order by "items".id desc
|
order by "items".id desc
|
||||||
offset ${offset}
|
offset ${offset}
|
||||||
|
@ -53,7 +55,7 @@ export default (router, tpl) => {
|
||||||
from "tags"
|
from "tags"
|
||||||
left join "tags_assign" on "tags_assign".tag_id = "tags".id
|
left join "tags_assign" on "tags_assign".tag_id = "tags".id
|
||||||
left join "items" on "items".id = "tags_assign".item_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
|
group by "items".id, "tags".tag
|
||||||
offset ${offset}
|
offset ${offset}
|
||||||
limit ${_eps}
|
limit ${_eps}
|
||||||
|
|
|
@ -17,9 +17,11 @@ export default async bot => {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const f0ck = await db`
|
const f0ck = await db`
|
||||||
select dest, username, userchannel, usernetwork
|
select dest, mime, username, userchannel, usernetwork
|
||||||
from "items"
|
from "items"
|
||||||
where id = ${id}
|
where
|
||||||
|
id = ${id} and
|
||||||
|
active = 'true'
|
||||||
limit 1
|
limit 1
|
||||||
`;
|
`;
|
||||||
const level = getLevel(e.user).level;
|
const level = getLevel(e.user).level;
|
||||||
|
@ -44,18 +46,66 @@ export default async bot => {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
await fs.unlink(`./public/b/${f0ck[0].dest}`).catch(_=>{});
|
await db`update "items" set active = 'false' where id = ${id}`;
|
||||||
await fs.unlink(`./public/t/${id}`).catch(_=>{});
|
|
||||||
|
|
||||||
await db`
|
await fs.copyFile(`./public/b/${f0ck[0].dest}`, `./deleted/b/${f0ck[0].dest}`).catch(_=>{});
|
||||||
delete from "items"
|
await fs.copyFile(`./public/t/${id}.webp`, `./deleted/t/${id}.webp`).catch(_=>{});
|
||||||
where id = ${+id}
|
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);
|
deleted.push(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
e.reply(`deleted ${deleted.length}/${e.args.length} f0cks (${deleted.join(",")})`);
|
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(",")})`);
|
||||||
|
}
|
||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
|
|
|
@ -137,7 +137,7 @@ export default async bot => {
|
||||||
userchannel: e.channel,
|
userchannel: e.channel,
|
||||||
usernetwork: e.network,
|
usernetwork: e.network,
|
||||||
stamp: ~~(new Date() / 1000),
|
stamp: ~~(new Date() / 1000),
|
||||||
active: 1
|
active: 'true'
|
||||||
}, 'src', 'dest', 'mime', 'size', 'checksum', 'username', 'userchannel', 'usernetwork', 'stamp', 'active')
|
}, 'src', 'dest', 'mime', 'size', 'checksum', 'username', 'userchannel', 'usernetwork', 'stamp', 'active')
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user