This commit is contained in:
May 2024-03-01 11:45:36 -08:00 committed by GitHub
parent 0621f55c20
commit 0a78c197a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -184,7 +184,25 @@ export class UploadStream extends Writable {
if (!this.name) throw new WebError(400, "no filename provided") if (!this.name) throw new WebError(400, "no filename provided")
if (!this.uploadId) this.setUploadId(generateFileId()) if (!this.uploadId) this.setUploadId(generateFileId())
// commit to db here... let ogf = this.files.files[this.uploadId]
this.files.files[this.uploadId] = {
filename: this.name,
mime: this.mime,
messageids: this.messages,
owner: this.owner,
sizeInBytes: this.filled,
visibility: ogf ? ogf.visibility
: (
this.owner
? Accounts.getFromId(this.owner)?.defaultFileVisibility
: undefined
),
// so that json.stringify doesnt include tag:undefined
...((ogf||{}).tag ? {tag:ogf.tag} : {}),
chunkSize: this.files.config.maxDiscordFileSize
}
} }
// exposed methods // exposed methods
@ -214,9 +232,13 @@ export class UploadStream extends Writable {
|| id.length > this.files.config.maxUploadIdLength) || id.length > this.files.config.maxUploadIdLength)
return this.destroy( new WebError(400, "invalid file ID") ) return this.destroy( new WebError(400, "invalid file ID") )
// There's more stuff to check here! if (this.files.files[id] && this.files.files[id].owner != this.owner)
// Make sure to check if the upload ID is locked return this.destroy( new WebError(403, "you don't own this file") )
// and if the user owns this file...
if (false /* check if locked here */)
return this.destroy( new WebError(409, "a file with this ID is already being uploaded") )
/* lock the id */
this.uploadId = id this.uploadId = id
return this return this
@ -232,7 +254,6 @@ export class UploadStream extends Writable {
private async startMessage(): Promise<Readable | undefined> { private async startMessage(): Promise<Readable | undefined> {
if (!this.newmessage_debounce) return if (!this.newmessage_debounce) return
this.newmessage_debounce = false this.newmessage_debounce = false