mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-22 05:46:26 -08:00
SPLIT ACTUALLY WORKS ON MONOFILE 1.3(IMPOSSIBLE)
This commit is contained in:
parent
dfc08f43b7
commit
7621b3ce5d
|
@ -3,6 +3,7 @@ import { Router } from "express";
|
||||||
import * as Accounts from "../lib/accounts";
|
import * as Accounts from "../lib/accounts";
|
||||||
import * as auth from "../lib/auth";
|
import * as auth from "../lib/auth";
|
||||||
import bytes from "bytes"
|
import bytes from "bytes"
|
||||||
|
import {writeFile} from "fs";
|
||||||
|
|
||||||
import ServeError from "../lib/errors";
|
import ServeError from "../lib/errors";
|
||||||
import Files from "../lib/files";
|
import Files from "../lib/files";
|
||||||
|
@ -44,15 +45,35 @@ fileApiRoutes.get("/list", (req,res) => {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
fileApiRoutes.post("/action", (req,res) => {
|
fileApiRoutes.post("/manage", (req,res) => {
|
||||||
|
|
||||||
if (!auth.validate(req.cookies.auth)) {
|
if (!auth.validate(req.cookies.auth)) {
|
||||||
ServeError(res, 401, "not logged in")
|
ServeError(res, 401, "not logged in")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let acc = Accounts.getFromToken(req.cookies.auth)
|
let acc = Accounts.getFromToken(req.cookies.auth) as Accounts.Account
|
||||||
|
|
||||||
if (!acc) return
|
if (!acc) return
|
||||||
|
if (!req.body.target || req.body.target.length < 1) return
|
||||||
|
|
||||||
|
req.body.target.forEach((e:string) => {
|
||||||
|
if (!acc.files.includes(e)) return
|
||||||
|
|
||||||
|
switch( req.body.action ) {
|
||||||
|
case "delete":
|
||||||
|
files.unlink(e)
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "changeFileVisibility":
|
||||||
|
if (!["public","anonymous","private"].includes(req.body.value)) return;
|
||||||
|
files.files[e].visibility = req.body.visibility;
|
||||||
|
|
||||||
|
writeFile(process.cwd()+"/.data/files.json",JSON.stringify(files.files), (err) => {
|
||||||
|
if (err) console.log(err)
|
||||||
|
})
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
|
@ -1,8 +1,8 @@
|
||||||
import { fetchAccountData, account } from "../stores.mjs"
|
import { fetchAccountData, account } from "../stores.mjs"
|
||||||
import { get } from "svelte/store";
|
import { get } from "svelte/store";
|
||||||
|
|
||||||
export function dfv(optPicker) {
|
export let options = {
|
||||||
optPicker.picker("Default file visibility",[
|
FV: [
|
||||||
{
|
{
|
||||||
name: "Public",
|
name: "Public",
|
||||||
icon: "/static/assets/icons/public.svg",
|
icon: "/static/assets/icons/public.svg",
|
||||||
|
@ -21,7 +21,18 @@ export function dfv(optPicker) {
|
||||||
description: "Nobody but you can view your uploads",
|
description: "Nobody but you can view your uploads",
|
||||||
id: "private"
|
id: "private"
|
||||||
}
|
}
|
||||||
]).then((exp) => {
|
],
|
||||||
|
AYS: [
|
||||||
|
{
|
||||||
|
name: "Yes",
|
||||||
|
icon: "/static/assets/icons/update.svg",
|
||||||
|
id: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
export function dfv(optPicker) {
|
||||||
|
optPicker.picker("Default file visibility",options.FV).then((exp) => {
|
||||||
if (exp && exp.selected) {
|
if (exp && exp.selected) {
|
||||||
fetch(`/auth/dfv`,{method:"POST", body:JSON.stringify({
|
fetch(`/auth/dfv`,{method:"POST", body:JSON.stringify({
|
||||||
defaultFileVisibility: exp.selected
|
defaultFileVisibility: exp.selected
|
||||||
|
@ -47,11 +58,11 @@ export function update_all_files(optPicker) {
|
||||||
}
|
}
|
||||||
]).then((exp) => {
|
]).then((exp) => {
|
||||||
if (exp && exp.selected) {
|
if (exp && exp.selected) {
|
||||||
fetch(`/files/action`,{method:"POST", body:JSON.stringify({
|
fetch(`/files/manage`,{method:"POST", body:JSON.stringify({
|
||||||
target:get(account).files,
|
target:get(account).files,
|
||||||
action: {
|
action: "changeFileVisibility",
|
||||||
visibility: get(account).defaultFileVisibility
|
|
||||||
}
|
value: get(account).defaultFileVisibility
|
||||||
})}).then((response) => {
|
})}).then((response) => {
|
||||||
|
|
||||||
if (response.status != 200) {
|
if (response.status != 200) {
|
||||||
|
@ -85,8 +96,52 @@ export function fileOptions(optPicker,file) {
|
||||||
id: "delete"
|
id: "delete"
|
||||||
}
|
}
|
||||||
]).then((exp) => {
|
]).then((exp) => {
|
||||||
|
|
||||||
if (exp && exp.selected) {
|
if (exp && exp.selected) {
|
||||||
|
|
||||||
|
switch( exp.selected ) {
|
||||||
|
|
||||||
|
case "delete":
|
||||||
|
|
||||||
|
fetch(`/files/manage`,{method:"POST", body:JSON.stringify({
|
||||||
|
target: [ file ],
|
||||||
|
action: "delete",
|
||||||
|
})}).then((response) => {
|
||||||
|
|
||||||
|
if (response.status != 200) {
|
||||||
|
optPicker.picker(`${response.status} ${response.statusText}`,[])
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchFilePointers()
|
||||||
|
})
|
||||||
|
|
||||||
|
case "changeFileVisibility":
|
||||||
|
|
||||||
|
optPicker.picker("Set file visibility", options.FV).then((exp) => {
|
||||||
|
|
||||||
|
if (exp && exp.selected) {
|
||||||
|
|
||||||
|
fetch(`/files/manage`, {method: "POST", body: JSON.stringify({
|
||||||
|
target: [ file ],
|
||||||
|
action: "changeFileVisibility",
|
||||||
|
|
||||||
|
value: exp.selected
|
||||||
|
})}).then((response) => {
|
||||||
|
|
||||||
|
if (response.status != 200) {
|
||||||
|
optPicker.picker(`${response.status} ${response.statusText}`,[])
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchFilePointers()
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
|
@ -187,7 +187,7 @@
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button>
|
<button>
|
||||||
<img src="/static/assets/icons/link.svg" alt="delete file">
|
<img src="/static/assets/icons/link.svg" alt="change file owner">
|
||||||
<p>Change file owner</p>
|
<p>Change file owner</p>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
@ -196,6 +196,11 @@
|
||||||
<p>Delete file</p>
|
<p>Delete file</p>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<button>
|
||||||
|
<img src="/static/assets/icons/update.svg" alt="update">
|
||||||
|
<p>Update files from before monofile 1.3<span><br />This may take a while</span></p>
|
||||||
|
</button>
|
||||||
|
|
||||||
{/if}
|
{/if}
|
||||||
<p style="font-size:12px;color:#AAAAAA;text-align:center;" class="monospace"><br />{$account.id}</p>
|
<p style="font-size:12px;color:#AAAAAA;text-align:center;" class="monospace"><br />{$account.id}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue