fix: fix saving files that aren't in the cache

This commit is contained in:
omar rashed 2024-11-16 21:46:38 -05:00
parent 7ecbd02fef
commit ee531d7139

View File

@ -385,11 +385,20 @@ export class FileManager {
throw new Error("File size too large. Please reduce the file size.") throw new Error("File size too large. Please reduce the file size.")
} }
await RemoteFileStorage.saveFile(this.getRemoteFileId(fileId), body) await RemoteFileStorage.saveFile(this.getRemoteFileId(fileId), body)
const file = this.fileData.find((f) => f.id === fileId)
if (!file) return
file.data = body
await this.sandbox.files.write(path.posix.join(this.dirName, file.id), body) let file = this.fileData.find((f) => f.id === fileId)
if (file) {
file.data = body
} else {
// If the file wasn't in our cache, add it
file = {
id: fileId,
data: body,
}
this.fileData.push(file)
}
await this.sandbox.files.write(path.posix.join(this.dirName, fileId), body)
this.fixPermissions() this.fixPermissions()
} }