mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-25 07:06:25 -08:00
drop .getFilePointer()
This commit is contained in:
parent
1fabc2ff82
commit
a5964f5ac8
|
@ -245,15 +245,7 @@ export default class Files {
|
|||
}
|
||||
}
|
||||
|
||||
// this code deletes the files from discord, btw
|
||||
// if need be, replace with job queue system
|
||||
|
||||
if (existingFile && this.uploadChannel) {
|
||||
for (let x of existingFile.messageids) {
|
||||
this.api.deleteMessage(x)
|
||||
.catch((err) => console.error(err))
|
||||
}
|
||||
}
|
||||
if (existingFile) this.api.deleteMessages(existingFile.messageids)
|
||||
|
||||
const { filename, mime, owner } = metadata
|
||||
|
||||
|
@ -482,50 +474,20 @@ export default class Files {
|
|||
* @param noWrite Whether or not the change should be written to disk. Enable for bulk deletes
|
||||
*/
|
||||
async unlink(uploadId: string, noWrite: boolean = false): Promise<void> {
|
||||
let tmp = this.files[uploadId]
|
||||
if (!tmp) {
|
||||
return
|
||||
}
|
||||
if (tmp.owner) {
|
||||
let id = files.deindex(tmp.owner, uploadId, noWrite)
|
||||
let target = this.files[uploadId]
|
||||
if (!target) return
|
||||
if (target.owner) {
|
||||
let id = files.deindex(target.owner, uploadId, noWrite)
|
||||
if (id) await id
|
||||
}
|
||||
// this code deletes the files from discord, btw
|
||||
// if need be, replace with job queue system
|
||||
|
||||
if (!this.uploadChannel) {
|
||||
return
|
||||
}
|
||||
/*
|
||||
for (let x of tmp.messageids) {
|
||||
this.api.deleteMessage(x)
|
||||
.catch((err) => console.error(err))
|
||||
}*/
|
||||
this.api.deleteMessages(tmp.messageids)
|
||||
await this.api.deleteMessages(target.messageids)
|
||||
|
||||
delete this.files[uploadId]
|
||||
if (noWrite) {
|
||||
return
|
||||
}
|
||||
return writeFile(
|
||||
process.cwd() + "/.data/files.json",
|
||||
JSON.stringify(
|
||||
this.files,
|
||||
null,
|
||||
process.env.NODE_ENV === "development" ? 4 : undefined
|
||||
)
|
||||
).catch((err) => {
|
||||
this.files[uploadId] = tmp // !! this may not work, since tmp is a link to this.files[uploadId]?
|
||||
if (noWrite) return
|
||||
return this.write().catch((err) => {
|
||||
throw err
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a file's FilePointer
|
||||
* @param uploadId Target file's ID
|
||||
* @returns FilePointer for the file
|
||||
*/
|
||||
getFilePointer(uploadId: string): FilePointer {
|
||||
return this.files[uploadId]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ module.exports = function (files: Files) {
|
|||
return ctx.status(404)
|
||||
}
|
||||
|
||||
let targetFile = files.getFilePointer(body.target)
|
||||
let targetFile = files.files[body.target]
|
||||
|
||||
if (!targetFile) {
|
||||
return ctx.status(404)
|
||||
|
@ -154,7 +154,7 @@ module.exports = function (files: Files) {
|
|||
return ctx.status(404)
|
||||
}
|
||||
|
||||
let targetFile = files.getFilePointer(body.target)
|
||||
let targetFile = files.files[body.target]
|
||||
if (!targetFile) {
|
||||
return ctx.status(404)
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ module.exports = function (files: Files) {
|
|||
targetFile.owner = newOwner ? newOwner.id : undefined
|
||||
|
||||
files
|
||||
.writeFile(body.target, targetFile)
|
||||
.write()
|
||||
.then(() => ctx.status(200))
|
||||
.catch(() => ctx.status(500))
|
||||
})
|
||||
|
@ -187,12 +187,12 @@ module.exports = function (files: Files) {
|
|||
return ctx.status(400)
|
||||
}
|
||||
|
||||
let targetFile = files.getFilePointer(body.target)
|
||||
let targetFile = files.files[body.target]
|
||||
if (!targetFile) {
|
||||
return ctx.status(404)
|
||||
}
|
||||
|
||||
if (files.getFilePointer(body.new)) {
|
||||
if (files.files[body.new]) {
|
||||
return ctx.status(400)
|
||||
}
|
||||
|
||||
|
@ -201,9 +201,10 @@ module.exports = function (files: Files) {
|
|||
Accounts.files.index(targetFile.owner, body.new)
|
||||
}
|
||||
delete files.files[body.target]
|
||||
files.files[body.new] = targetFile
|
||||
|
||||
return files
|
||||
.writeFile(body.new, targetFile)
|
||||
.write()
|
||||
.then(() => ctx.status(200))
|
||||
.catch(() => {
|
||||
files.files[body.target] = body.new
|
||||
|
|
|
@ -41,7 +41,7 @@ module.exports = function (files: Files) {
|
|||
ctx.json(
|
||||
acc.files
|
||||
.map((e) => {
|
||||
let fp = files.getFilePointer(e)
|
||||
let fp = files.files[e]
|
||||
if (!fp) {
|
||||
Accounts.files.deindex(accId, e)
|
||||
return null
|
||||
|
@ -77,7 +77,7 @@ module.exports = function (files: Files) {
|
|||
body.target.forEach((e: string) => {
|
||||
if (!acc.files.includes(e)) return
|
||||
|
||||
let fp = files.getFilePointer(e)
|
||||
let fp = files.files[e]
|
||||
|
||||
if (fp.reserved) {
|
||||
return
|
||||
|
|
|
@ -36,7 +36,7 @@ module.exports = function (files: Files) {
|
|||
|
||||
let acc = ctx.get("account") as Accounts.Account
|
||||
|
||||
let file = files.getFilePointer(fileId)
|
||||
let file = files.files[fileId]
|
||||
ctx.header("Access-Control-Allow-Origin", "*")
|
||||
ctx.header("Content-Security-Policy", "sandbox allow-scripts")
|
||||
if (ctx.req.query("attachment") == "1")
|
||||
|
@ -119,7 +119,7 @@ module.exports = function (files: Files) {
|
|||
// primaryApi.head(
|
||||
// ["/file/:fileId", "/cpt/:fileId/*", "/:fileId"],
|
||||
// async (ctx) => {
|
||||
// let file = files.getFilePointer(req.params.fileId)
|
||||
// let file = files.files[req.params.fileId]
|
||||
|
||||
// if (
|
||||
// file.visibility == "private" &&
|
||||
|
|
|
@ -10,7 +10,7 @@ export = (files: Files): Handler =>
|
|||
let acc = ctx.get("account") as Accounts.Account
|
||||
const fileId = ctx.req.param("fileId")
|
||||
const host = ctx.req.header("Host")
|
||||
const file = files.getFilePointer(fileId)
|
||||
const file = files.files[fileId]
|
||||
if (file) {
|
||||
if (file.visibility == "private" && acc?.id != file.owner) {
|
||||
return ServeError(ctx, 403, "you do not own this file")
|
||||
|
|
Loading…
Reference in a new issue