mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-24 14:46:27 -08:00
custom css...hopefully
This commit is contained in:
parent
2c5984d628
commit
78de4764bc
1
assets/icons/paint.svg
Normal file
1
assets/icons/paint.svg
Normal 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="M12 2.25a.75.75 0 0 0-1.5 0V3.5a2.24 2.24 0 0 0-.841.53L2.78 10.91a2.25 2.25 0 0 0 0 3.182L7.66 18.97a2.25 2.25 0 0 0 3.182 0l6.879-6.879a2.25 2.25 0 0 0 0-3.182L12.84 4.03A2.24 2.24 0 0 0 12 3.5V2.25Zm-1.5 3.06v1.44a.75.75 0 0 0 1.5 0V5.31l4.659 4.66a.75.75 0 0 1 0 1.06l-.97.97H3.812l.029-.03L10.5 5.31ZM19.521 13.602a.874.874 0 0 0-1.542 0l-2.008 3.766C14.85 19.466 16.372 22 18.75 22s3.898-2.534 2.78-4.632l-2.009-3.766Z" fill="#DDDDDD"/></svg>
|
After Width: | Height: | Size: 552 B |
|
@ -17,6 +17,11 @@
|
|||
href="/static/style/downloads.css"
|
||||
>
|
||||
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="/auth/customCSS"
|
||||
>
|
||||
|
||||
<link
|
||||
rel="icon"
|
||||
type="image/svg"
|
||||
|
|
|
@ -14,6 +14,11 @@
|
|||
type="image/svg"
|
||||
href="/static/assets/icons/error.svg"
|
||||
>
|
||||
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="/auth/customCSS"
|
||||
>
|
||||
|
||||
<meta
|
||||
name="viewport"
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
type="image/svg"
|
||||
href="/static/assets/icons/icon_temp.svg"
|
||||
>
|
||||
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="/auth/customCSS"
|
||||
>
|
||||
|
||||
<meta
|
||||
name="viewport"
|
||||
|
|
|
@ -199,6 +199,8 @@ let fgRQH = async (req:express.Request,res:express.Response) => {
|
|||
ServeError(res,err.status,err.message)
|
||||
})
|
||||
|
||||
} else {
|
||||
ServeError(res, 404, "file not found")
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ export interface Account {
|
|||
files : string[]
|
||||
admin : boolean
|
||||
defaultFileVisibility : FileVisibility
|
||||
customCSS? : string
|
||||
}
|
||||
|
||||
export function create(username:string,pwd:string,admin:boolean=false):Promise<string> {
|
||||
|
|
|
@ -119,6 +119,11 @@ export default class Files {
|
|||
return
|
||||
}
|
||||
|
||||
if (this.files[uploadId] && this.files[uploadId].reserved) {
|
||||
reject({status:400,message:"already uploading this file. if your file is stuck in this state, contact an administrator"});
|
||||
return
|
||||
}
|
||||
|
||||
if (settings.name.length > 128) {
|
||||
reject({status:400,message:"name too long"});
|
||||
return
|
||||
|
|
|
@ -4,7 +4,7 @@ import * as Accounts from "../lib/accounts";
|
|||
import * as auth from "../lib/auth";
|
||||
|
||||
import ServeError from "../lib/errors";
|
||||
import Files, { FileVisibility } from "../lib/files";
|
||||
import Files, { FileVisibility, id_check_regex } from "../lib/files";
|
||||
|
||||
let parser = bodyParser.json({
|
||||
type: ["text/plain","application/json"]
|
||||
|
@ -124,7 +124,7 @@ authRoutes.post("/dfv", parser, (req,res) => {
|
|||
return
|
||||
}
|
||||
|
||||
if (['public','private','anonymous'].find(e => e == req.body.defaultFileVisibility)) {
|
||||
if (['public','private','anonymous'].includes(req.body.defaultFileVisibility)) {
|
||||
acc.defaultFileVisibility = req.body.defaultFileVisibility
|
||||
Accounts.save()
|
||||
res.send(`dfv has been set to ${acc.defaultFileVisibility}`)
|
||||
|
@ -134,6 +134,26 @@ authRoutes.post("/dfv", parser, (req,res) => {
|
|||
}
|
||||
})
|
||||
|
||||
authRoutes.post("/customcss", parser, (req,res) => {
|
||||
let acc = Accounts.getFromToken(req.cookies.auth)
|
||||
if (!acc) {
|
||||
ServeError(res, 401, "not logged in")
|
||||
return
|
||||
}
|
||||
|
||||
if (typeof req.body.fileId != "string") return
|
||||
|
||||
if (id_check_regex.test(req.body.fileId) && req.body.fileId.length <= config.maxUploadIdLength) {
|
||||
acc.customCSS = req.body.fileId
|
||||
if (!req.body.fileId) delete acc.customCSS
|
||||
Accounts.save()
|
||||
res.send(`custom css saved`)
|
||||
} else {
|
||||
res.status(400)
|
||||
res.send("invalid fileid")
|
||||
}
|
||||
})
|
||||
|
||||
authRoutes.post("/delete_account", parser, (req,res) => {
|
||||
let acc = Accounts.getFromToken(req.cookies.auth)
|
||||
if (!acc) {
|
||||
|
@ -243,4 +263,22 @@ authRoutes.get("/me", (req,res) => {
|
|||
sessionExpires: auth.AuthTokens.find(e => e.token == req.cookies.auth)?.expire
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
authRoutes.get("/customCSS", (req,res) => {
|
||||
if (!auth.validate(req.cookies.auth)) {
|
||||
ServeError(res, 401, "not logged in")
|
||||
return
|
||||
}
|
||||
|
||||
// lazy rn so
|
||||
|
||||
let acc = Accounts.getFromToken(req.cookies.auth)
|
||||
if (acc) {
|
||||
if (acc.customCSS) {
|
||||
res.redirect(`/file/${acc.customCSS}`)
|
||||
} else {
|
||||
res.send("")
|
||||
}
|
||||
} else res.send("")
|
||||
})
|
|
@ -65,9 +65,6 @@ fileApiRoutes.post("/manage", parser, (req,res) => {
|
|||
let fp = files.getFilePointer(e)
|
||||
|
||||
if (fp.reserved) {
|
||||
if (req.body.target.length == 1) {
|
||||
ServeError(res, 400, `cannot modify a file that is being uploaded, please contact an administrator if your file is stuck in this state.`)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -112,6 +112,36 @@ export function pwdChng(optPicker) {
|
|||
optPicker.picker(`${response.status} ${response.statusText}`,[])
|
||||
}
|
||||
|
||||
fetchAccountData()
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function customcss(optPicker) {
|
||||
optPicker.picker("Set custom CSS",[
|
||||
{
|
||||
name: "Enter a file ID",
|
||||
icon: "/static/assets/icons/file.svg",
|
||||
id: "fileid",
|
||||
inputSettings: {}
|
||||
},
|
||||
{
|
||||
name: "OK",
|
||||
icon: "/static/assets/icons/update.svg",
|
||||
description: "Refresh to apply changes",
|
||||
id: true
|
||||
}
|
||||
]).then((exp) => {
|
||||
if (exp && exp.selected) {
|
||||
fetch(`/auth/customcss`,{method:"POST", body:JSON.stringify({
|
||||
fileId:exp.fileid
|
||||
})}).then((response) => {
|
||||
|
||||
if (response.status != 200) {
|
||||
optPicker.picker(`${response.status} ${response.statusText}`,[])
|
||||
}
|
||||
|
||||
fetchAccountData()
|
||||
})
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@
|
|||
<div class="category">
|
||||
<p>Uploads</p>
|
||||
</div>
|
||||
|
||||
|
||||
<button on:click={() => uplOpts.dfv(optPicker)}>
|
||||
<img src={`/static/assets/icons/${$account.defaultFileVisibility || "public"}.svg`} alt={$account.defaultFileVisibility || "public"}>
|
||||
<p>Default file visibility<span><br />Uploads will be <strong>{$account.defaultFileVisibility || "public"}</strong> by default</span></p>
|
||||
|
@ -164,7 +164,16 @@
|
|||
<img src="/static/assets/icons/logout.svg" alt="logout">
|
||||
<p>Log out<span><br />Session expires {new Date($account.sessionExpires).toLocaleDateString()}</span></p>
|
||||
</button>
|
||||
|
||||
|
||||
<div class="category">
|
||||
<p>Customization</p>
|
||||
</div>
|
||||
|
||||
<button on:click={() => accOpts.customcss(optPicker)}>
|
||||
<img src="/static/assets/icons/paint.svg" alt="logout_all">
|
||||
<p>Set custom CSS<span><br />{@html $account.customCSS ? `Using file ID <span class="number">${$account.customCSS}</span>` : "No custom CSS set"}</span></p>
|
||||
</button>
|
||||
|
||||
{#if $account.admin}
|
||||
|
||||
<div class="category">
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
{#if file.reserved}
|
||||
<br />
|
||||
<img src="/static/assets/icons/update.svg" alt="uploading"/>
|
||||
This file is currently being uploaded. Please wait.
|
||||
Uploading...
|
||||
{/if}
|
||||
{#if file.tag}
|
||||
<br />
|
||||
|
|
Loading…
Reference in a new issue