mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-28 16:36:27 -08:00
hopeuflly this can fix some stuf
This commit is contained in:
parent
df44249539
commit
2c5984d628
|
@ -20,23 +20,23 @@ 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> {
|
||||||
let accId = crypto.randomBytes(12).toString("hex")
|
return new Promise((resolve,reject) => {
|
||||||
|
let accId = crypto.randomBytes(12).toString("hex")
|
||||||
|
|
||||||
Accounts.push(
|
Accounts.push(
|
||||||
{
|
{
|
||||||
id: accId,
|
id: accId,
|
||||||
username: username,
|
username: username,
|
||||||
password: password.hash(pwd),
|
password: password.hash(pwd),
|
||||||
files: [],
|
files: [],
|
||||||
admin: admin,
|
admin: admin,
|
||||||
defaultFileVisibility: "public"
|
defaultFileVisibility: "public"
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -191,12 +191,6 @@ export default class Files {
|
||||||
reject({status:500,message:"please try again"}); return
|
reject({status:500,message:"please try again"}); return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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,15 +92,19 @@ 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
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
res.cookie("auth",auth.create(newAcc,(3*24*60*60*1000)))
|
||||||
assign token
|
res.status(200)
|
||||||
*/
|
res.end()
|
||||||
|
})
|
||||||
res.cookie("auth",auth.create(newAcc,(3*24*60*60*1000)))
|
.catch(() => {
|
||||||
res.status(200)
|
ServeError(res,500,"internal server error")
|
||||||
res.end()
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
authRoutes.post("/logout", (req,res) => {
|
authRoutes.post("/logout", (req,res) => {
|
||||||
|
|
Loading…
Reference in a new issue