mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-21 21:36:26 -08:00
delete your own account endpoint
This commit is contained in:
parent
c51d8dab95
commit
01bb4684a3
|
@ -1,5 +1,6 @@
|
|||
// Modules
|
||||
|
||||
import { writeFile } from 'fs'
|
||||
import { Router } from "express";
|
||||
import bodyParser from "body-parser";
|
||||
|
||||
|
@ -142,5 +143,35 @@ module.exports = function(files: Files) {
|
|||
}
|
||||
)
|
||||
|
||||
router.delete("/me",
|
||||
requiresAccount,
|
||||
noAPIAccess,
|
||||
parser,
|
||||
(req, res) => {
|
||||
const Account = res.locals.acc as Accounts.Account
|
||||
|
||||
const accountId = Account.id
|
||||
|
||||
Authentication.AuthTokens.filter(e => e.account == accountId).forEach((token) => {
|
||||
Authentication.invalidate(token.token)
|
||||
})
|
||||
|
||||
const deleteAccount = () => Accounts.deleteAccount(accountId).then(_ => res.send("account deleted"))
|
||||
|
||||
if (req.body.deleteFiles) {
|
||||
const Files = Account.files.map(e => e)
|
||||
|
||||
for (let fileId of Files) {
|
||||
files.unlink(fileId, true).catch(err => console.error)
|
||||
}
|
||||
|
||||
writeFile(process.cwd() + "/.data/files.json", JSON.stringify(files.files), (err) => {
|
||||
if (err) console.log(err)
|
||||
deleteAccount()
|
||||
})
|
||||
} else deleteAccount()
|
||||
}
|
||||
)
|
||||
|
||||
return router
|
||||
}
|
Loading…
Reference in a new issue