mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-21 13:36:25 -08:00
bearer-auth: make fileApiRoutes use middleware
This commit is contained in:
parent
64dd66dc03
commit
14d4261858
|
@ -7,6 +7,7 @@ import {writeFile} from "fs";
|
|||
|
||||
import ServeError from "../lib/errors";
|
||||
import Files from "../lib/files";
|
||||
import { getAccount, requiresAccount } from "../lib/middleware";
|
||||
|
||||
let parser = bodyParser.json({
|
||||
type: ["text/plain","application/json"]
|
||||
|
@ -21,14 +22,11 @@ export function setFilesObj(newFiles:Files) {
|
|||
|
||||
let config = require(`${process.cwd()}/config.json`)
|
||||
|
||||
fileApiRoutes.get("/list", (req,res) => {
|
||||
fileApiRoutes.use(getAccount);
|
||||
|
||||
if (!auth.validate(req.cookies.auth)) {
|
||||
ServeError(res, 401, "not logged in")
|
||||
return
|
||||
}
|
||||
fileApiRoutes.get("/list", requiresAccount, (req,res) => {
|
||||
|
||||
let acc = Accounts.getFromToken(req.cookies.auth)
|
||||
let acc = res.locals.acc as Accounts.Account
|
||||
|
||||
if (!acc) return
|
||||
let accId = acc.id
|
||||
|
@ -48,12 +46,7 @@ fileApiRoutes.get("/list", (req,res) => {
|
|||
|
||||
fileApiRoutes.post("/manage", 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
|
||||
let acc = res.locals.acc as Accounts.Account
|
||||
|
||||
if (!acc) return
|
||||
if (!req.body.target || !(typeof req.body.target == "object") || req.body.target.length < 1) return
|
||||
|
|
Loading…
Reference in a new issue