Merge pull request #8 from nbitzz/1.3.3

This commit is contained in:
split / May 2023-08-28 22:06:16 -07:00 committed by GitHub
commit ec42d61bf7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 88 additions and 7 deletions

View file

@ -0,0 +1 @@
<svg width="24" height="24" fill="none" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="m11.256 13 .238-1.5h1.481l-.237 1.5h-1.482Z" fill="#8aadf4"/><path d="M17.75 2.001a2.25 2.25 0 0 1 2.245 2.096L20 4.25v15.498a2.25 2.25 0 0 1-2.096 2.245l-.154.005H6.25a2.25 2.25 0 0 1-2.245-2.096L4 19.75V4.251a2.25 2.25 0 0 1 2.096-2.245l.154-.005h11.5Zm-5.355 13.16a.75.75 0 1 0 1.482.234l.142-.895h.731a.75.75 0 0 0 0-1.5h-.494l.238-1.5h.756a.75.75 0 0 0 0-1.5h-.519l.162-1.025a.75.75 0 1 0-1.481-.234l-.2 1.259h-1.48l.161-1.025a.75.75 0 1 0-1.481-.234l-.2 1.259H9.25a.75.75 0 1 0 0 1.5h.725L9.738 13H8.75a.75.75 0 1 0 0 1.5h.75l-.105.66a.75.75 0 0 0 1.482.235l.142-.895H12.5l-.105.66Z" fill="#DDDDDD"/></svg>

After

Width:  |  Height:  |  Size: 716 B

View file

@ -1,6 +1,6 @@
{ {
"name": "monofile", "name": "monofile",
"version": "1.3.2", "version": "1.3.3",
"description": "Discord-based file sharing", "description": "Discord-based file sharing",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
@ -11,7 +11,7 @@
"author": "nbitzz", "author": "nbitzz",
"license": "Unlicense", "license": "Unlicense",
"engines": { "engines": {
"node": ">=v18" "node": ">=v16.11"
}, },
"dependencies": { "dependencies": {
"@types/body-parser": "^1.19.2", "@types/body-parser": "^1.19.2",

View file

@ -6,7 +6,7 @@ import { files } from "./accounts";
import * as Accounts from "./accounts"; import * as Accounts from "./accounts";
export let id_check_regex = /[A-Za-z0-9_\-\.\!]+/ export let id_check_regex = /[A-Za-z0-9_\-\.\!\=\:]+/
export let alphanum = Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890") export let alphanum = Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
// bad solution but whatever // bad solution but whatever

View file

@ -85,8 +85,6 @@ adminRoutes.post("/elevate", parser, (req,res) => {
adminRoutes.post("/delete", parser, (req,res) => { adminRoutes.post("/delete", parser, (req,res) => {
let acc = res.locals.acc as Accounts.Account
if (typeof req.body.target !== "string") { if (typeof req.body.target !== "string") {
res.status(404) res.status(404)
res.send() res.send()
@ -154,8 +152,6 @@ adminRoutes.post("/delete_account", parser, async (req,res) => {
adminRoutes.post("/transfer", parser, (req,res) => { adminRoutes.post("/transfer", parser, (req,res) => {
let acc = res.locals.acc as Accounts.Account
if (typeof req.body.target !== "string" || typeof req.body.owner !== "string") { if (typeof req.body.target !== "string" || typeof req.body.owner !== "string") {
res.status(404) res.status(404)
res.send() res.send()
@ -193,3 +189,46 @@ adminRoutes.post("/transfer", parser, (req,res) => {
}) // wasting a reassignment but whatee }) // wasting a reassignment but whatee
}) })
adminRoutes.post("/idchange", parser, (req,res) => {
if (typeof req.body.target !== "string" || typeof req.body.new !== "string") {
res.status(404)
res.send()
return
}
let targetFile = files.getFilePointer(req.body.target)
if (!targetFile) {
res.status(404)
res.send()
return
}
if (files.getFilePointer(req.body.new)) {
res.status(400)
res.send()
return
}
if (targetFile.owner) {
Accounts.files.deindex(targetFile.owner, req.body.target)
Accounts.files.index(targetFile.owner, req.body.new)
}
delete files.files[req.body.target]
files.writeFile(req.body.new, targetFile).then(() => {
res.send()
}).catch(() => {
files.files[req.body.target] = req.body.new
if (targetFile.owner) {
Accounts.files.deindex(targetFile.owner, req.body.new)
Accounts.files.index(targetFile.owner, req.body.target)
}
res.status(500)
res.send()
})
})

View file

@ -75,6 +75,42 @@ export function chgOwner(optPicker) {
}) })
} }
export function chgId(optPicker) {
optPicker.picker("Change file ID",[
{
name: "Target file",
icon: "/static/assets/icons/file.svg",
id: "file",
inputSettings: {}
},
{
name: "New ID",
icon: "/static/assets/icons/admin/change_file_id.svg",
id: "new",
inputSettings: {}
},
{
name: "Update",
icon: "/static/assets/icons/update.svg",
description: "File will not be available at its old ID",
id: true
}
]).then((exp) => {
if (exp && exp.selected) {
fetch(`/admin/idchange`,{method:"POST", body:JSON.stringify({
target: exp.file,
new: exp.new
})}).then((response) => {
if (response.status != 200) {
optPicker.picker(`${response.status} ${response.headers.get("x-backup-status-message") || response.statusText || ""}`,[])
}
})
}
})
}
export function delFile(optPicker) { export function delFile(optPicker) {
optPicker.picker("Delete file",[ optPicker.picker("Delete file",[
{ {

View file

@ -228,6 +228,11 @@
<p>Change file owner</p> <p>Change file owner</p>
</button> </button>
<button on:click={() => admOpts.chgId(optPicker)}>
<img src="/static/assets/icons/admin/change_file_id.svg" alt="change file id">
<p>Change file ID<span><br />Potentially buggy, usage not recommended</span></p>
</button>
<button on:click={() => admOpts.delFile(optPicker)}> <button on:click={() => admOpts.delFile(optPicker)}>
<img src="/static/assets/icons/admin/delete_file.svg" alt="delete file"> <img src="/static/assets/icons/admin/delete_file.svg" alt="delete file">
<p>Delete file</p> <p>Delete file</p>