FIX: Didn't delete upload stub when a new upload is created

Reuse `Discourse.store` to prevent creation of multiple new store objects within `UploadCreator#create_for`.
This commit is contained in:
Gerhard Schlager 2022-06-20 18:35:45 +02:00 committed by Gerhard Schlager
parent 2d6ef232a7
commit 235f172b9c

View File

@ -196,21 +196,24 @@ class UploadCreator
Upload.generate_digest(@file) != sha1_before_changes
end
if @opts[:existing_external_upload_key] && Discourse.store.external?
store = Discourse.store
if @opts[:existing_external_upload_key] && store.external?
should_move = external_upload_too_big || !upload_changed
end
if should_move
# move the file in the store instead of reuploading
url = Discourse.store.move_existing_stored_upload(
url = store.move_existing_stored_upload(
existing_external_upload_key: @opts[:existing_external_upload_key],
upload: @upload
)
else
# store the file and update its url
File.open(@file.path) do |f|
url = Discourse.store.store_upload(f, @upload)
url = store.store_upload(f, @upload)
end
store.delete_file(@opts[:existing_external_upload_key]) if @opts[:existing_external_upload_key]
end
if url.present?