mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-24 22:56:26 -08:00
hopeuflly this can fix some stuf
This commit is contained in:
parent
df44249539
commit
2c5984d628
|
@ -20,7 +20,8 @@ export interface Account {
|
||||||
defaultFileVisibility : FileVisibility
|
defaultFileVisibility : FileVisibility
|
||||||
}
|
}
|
||||||
|
|
||||||
export function create(username:string,pwd:string,admin:boolean=false) {
|
export function create(username:string,pwd:string,admin:boolean=false):Promise<string> {
|
||||||
|
return new Promise((resolve,reject) => {
|
||||||
let accId = crypto.randomBytes(12).toString("hex")
|
let accId = crypto.randomBytes(12).toString("hex")
|
||||||
|
|
||||||
Accounts.push(
|
Accounts.push(
|
||||||
|
@ -34,9 +35,8 @@ export function create(username:string,pwd:string,admin:boolean=false) {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
save()
|
save().then(() => resolve(accId))
|
||||||
|
})
|
||||||
return accId
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFromUsername(username:string) {
|
export function getFromUsername(username:string) {
|
||||||
|
@ -55,7 +55,7 @@ export function getFromToken(token:string) {
|
||||||
|
|
||||||
export function deleteAccount(id:string) {
|
export function deleteAccount(id:string) {
|
||||||
Accounts.splice(Accounts.findIndex(e => e.id == id),1)
|
Accounts.splice(Accounts.findIndex(e => e.id == id),1)
|
||||||
save()
|
return save()
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace password {
|
export namespace password {
|
||||||
|
@ -74,7 +74,7 @@ export namespace password {
|
||||||
if (!acc) return
|
if (!acc) return
|
||||||
|
|
||||||
acc.password = hash(password)
|
acc.password = hash(password)
|
||||||
save()
|
return save()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function check(id:string,password:string) {
|
export function check(id:string,password:string) {
|
||||||
|
@ -95,7 +95,7 @@ export namespace files {
|
||||||
if (acc.files.find(e => e == fileId)) return
|
if (acc.files.find(e => e == fileId)) return
|
||||||
|
|
||||||
acc.files.push(fileId)
|
acc.files.push(fileId)
|
||||||
save()
|
return save()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deindex(accountId:string,fileId:string) {
|
export function deindex(accountId:string,fileId:string) {
|
||||||
|
@ -104,13 +104,13 @@ export namespace files {
|
||||||
let fi = acc.files.findIndex(e => e == fileId)
|
let fi = acc.files.findIndex(e => e == fileId)
|
||||||
if (fi) {
|
if (fi) {
|
||||||
acc.files.splice(fi,1)
|
acc.files.splice(fi,1)
|
||||||
save()
|
return save()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function save() {
|
export function save() {
|
||||||
writeFile(`${process.cwd()}/.data/accounts.json`,JSON.stringify(Accounts))
|
return writeFile(`${process.cwd()}/.data/accounts.json`,JSON.stringify(Accounts))
|
||||||
.catch((err) => console.error(err))
|
.catch((err) => console.error(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -192,12 +192,6 @@ export default class Files {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// save
|
|
||||||
|
|
||||||
if (settings.owner) {
|
|
||||||
files.index(settings.owner,uploadId)
|
|
||||||
}
|
|
||||||
|
|
||||||
// this code deletes the files from discord, btw
|
// this code deletes the files from discord, btw
|
||||||
// if need be, replace with job queue system
|
// if need be, replace with job queue system
|
||||||
|
|
||||||
|
@ -227,9 +221,15 @@ export default class Files {
|
||||||
: undefined
|
: undefined
|
||||||
),
|
),
|
||||||
// so that json.stringify doesnt include tag:undefined
|
// so that json.stringify doesnt include tag:undefined
|
||||||
...(ogf.tag ? {tag:ogf.tag} : {})
|
...((ogf||{}).tag ? {tag:ogf.tag} : {})
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
|
|
||||||
|
// save
|
||||||
|
|
||||||
|
if (settings.owner) {
|
||||||
|
await files.index(settings.owner,uploadId)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,8 +92,8 @@ authRoutes.post("/create", parser, (req,res) => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let newAcc = Accounts.create(req.body.username,req.body.password)
|
Accounts.create(req.body.username,req.body.password)
|
||||||
|
.then((newAcc) => {
|
||||||
/*
|
/*
|
||||||
assign token
|
assign token
|
||||||
*/
|
*/
|
||||||
|
@ -102,6 +102,10 @@ authRoutes.post("/create", parser, (req,res) => {
|
||||||
res.status(200)
|
res.status(200)
|
||||||
res.end()
|
res.end()
|
||||||
})
|
})
|
||||||
|
.catch(() => {
|
||||||
|
ServeError(res,500,"internal server error")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
authRoutes.post("/logout", (req,res) => {
|
authRoutes.post("/logout", (req,res) => {
|
||||||
if (!auth.validate(req.cookies.auth)) {
|
if (!auth.validate(req.cookies.auth)) {
|
||||||
|
|
Loading…
Reference in a new issue