Delete file

This commit is contained in:
split / May 2023-07-02 23:35:38 -07:00
parent dd0a080ba8
commit e9c68d0280
3 changed files with 67 additions and 1 deletions

View file

@ -60,10 +60,46 @@ adminRoutes.post("/reset", parser, (req,res) => {
}
Accounts.password.set ( targetAccount.id, req.body.password )
auth.AuthTokens.filter(e => e.account == targetAccount?.id).forEach((v) => {
auth.invalidate(v.token)
})
res.send()
})
adminRoutes.post("/delete", parser, (req,res) => {
if (!auth.validate(req.cookies.auth)) {
ServeError(res, 401, "not logged in")
return
}
let acc = Accounts.getFromToken(req.cookies.auth) as Accounts.Account
if (!acc) return
if (!acc.admin) return
if (typeof req.body.target !== "string") {
res.status(404)
res.send()
return
}
let targetFile = files.getFilePointer(req.body.target)
if (!targetFile) {
res.status(404)
res.send()
return
}
files.unlink(req.body.target).then(() => {
res.status(200)
}).catch(() => {
res.status(500)
}).finally(() => res.send())
})
adminRoutes.post("/transfer", parser, (req,res) => {
if (!auth.validate(req.cookies.auth)) {

View file

@ -74,3 +74,33 @@ export function chgOwner(optPicker) {
}
})
}
export function delFile(optPicker) {
optPicker.picker("Delete file",[
{
name: "File ID",
icon: "/static/assets/icons/file.svg",
id: "file",
inputSettings: {}
},
{
name: "Delete",
icon: "/static/assets/icons/admin/delete_file.svg",
description: "This can't be undone",
id: true
}
]).then((exp) => {
if (exp && exp.selected) {
fetch(`/admin/delete`,{method:"POST", body:JSON.stringify({
owner: exp.owner,
target: exp.file
})}).then((response) => {
if (response.status != 200) {
optPicker.picker(`${response.status} ${response.statusText}`,[])
}
})
}
})
}

View file

@ -208,7 +208,7 @@
<p>Change file owner</p>
</button>
<button>
<button on:click={() => admOpts.delFile(optPicker)}>
<img src="/static/assets/icons/admin/delete_file.svg" alt="delete file">
<p>Delete file</p>
</button>