hopeuflly this can fix some stuf

This commit is contained in:
split / May 2023-05-11 15:32:00 -07:00
parent df44249539
commit 2c5984d628
3 changed files with 39 additions and 35 deletions

View file

@ -20,7 +20,8 @@ export interface Account {
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")
Accounts.push(
@ -34,9 +35,8 @@ export function create(username:string,pwd:string,admin:boolean=false) {
}
)
save()
return accId
save().then(() => resolve(accId))
})
}
export function getFromUsername(username:string) {
@ -55,7 +55,7 @@ export function getFromToken(token:string) {
export function deleteAccount(id:string) {
Accounts.splice(Accounts.findIndex(e => e.id == id),1)
save()
return save()
}
export namespace password {
@ -74,7 +74,7 @@ export namespace password {
if (!acc) return
acc.password = hash(password)
save()
return save()
}
export function check(id:string,password:string) {
@ -95,7 +95,7 @@ export namespace files {
if (acc.files.find(e => e == fileId)) return
acc.files.push(fileId)
save()
return save()
}
export function deindex(accountId:string,fileId:string) {
@ -104,13 +104,13 @@ export namespace files {
let fi = acc.files.findIndex(e => e == fileId)
if (fi) {
acc.files.splice(fi,1)
save()
return 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))
}

View file

@ -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
// if need be, replace with job queue system
@ -227,9 +221,15 @@ export default class Files {
: 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)
}
})
}

View file

@ -92,8 +92,8 @@ authRoutes.post("/create", parser, (req,res) => {
return
}
let newAcc = Accounts.create(req.body.username,req.body.password)
Accounts.create(req.body.username,req.body.password)
.then((newAcc) => {
/*
assign token
*/
@ -101,6 +101,10 @@ authRoutes.post("/create", parser, (req,res) => {
res.cookie("auth",auth.create(newAcc,(3*24*60*60*1000)))
res.status(200)
res.end()
})
.catch(() => {
ServeError(res,500,"internal server error")
})
})
authRoutes.post("/logout", (req,res) => {