diff --git a/app/channels/asset_sync_channel.rb b/app/channels/asset_sync_channel.rb new file mode 100644 index 0000000000..24d5b159c3 --- /dev/null +++ b/app/channels/asset_sync_channel.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AssetSyncChannel < ApplicationCable::Channel + include Canaid::Helpers::PermissionsHelper + + def subscribed + asset = Asset.find_by(id: params[:asset_id]) + + return reject unless asset&.file&.attached? + return reject unless can_manage_asset?(current_user, asset) && can_open_asset_locally?(current_user, asset) + + stream_for asset + + transmit({ checksum: asset.file.checksum }) + end + + def unsubscribed + stop_all_streams + end +end diff --git a/app/controllers/asset_sync_controller.rb b/app/controllers/asset_sync_controller.rb index 79912834ba..7566979deb 100644 --- a/app/controllers/asset_sync_controller.rb +++ b/app/controllers/asset_sync_controller.rb @@ -44,6 +44,8 @@ def update log_activity(:edit) end + AssetSyncChannel.broadcast_to(@asset, checksum: @asset.file.checksum) + if asset_conflicts ActiveRecord::Base.transaction do conflict_response = AssetSyncTokenSerializer.new(@asset_sync_token).as_json diff --git a/app/controllers/assets_controller.rb b/app/controllers/assets_controller.rb index 5445a5648a..f81aca6bf7 100644 --- a/app/controllers/assets_controller.rb +++ b/app/controllers/assets_controller.rb @@ -442,10 +442,6 @@ def duplicate end end - def checksum - render json: { checksum: @asset.file.blob.checksum } - end - def versions blobs = [@asset.file.blob] + diff --git a/app/controllers/global_constants_controller.rb b/app/controllers/global_constants_controller.rb index da8cccbd37..d42d43ab7a 100644 --- a/app/controllers/global_constants_controller.rb +++ b/app/controllers/global_constants_controller.rb @@ -28,7 +28,6 @@ def load_global_constants FILENAME_MAX_LENGTH: Constants::FILENAME_MAX_LENGTH, FAST_STATUS_POLLING_INTERVAL: Constants::FAST_STATUS_POLLING_INTERVAL, SLOW_STATUS_POLLING_INTERVAL: Constants::SLOW_STATUS_POLLING_INTERVAL, - ASSET_POLLING_INTERVAL: Constants::ASSET_POLLING_INTERVAL, ASSET_SYNC_URL: Constants::ASSET_SYNC_URL, GLOBAL_SEARCH_PREVIEW_LIMIT: Constants::GLOBAL_SEARCH_PREVIEW_LIMIT, SEARCH_LIMIT: Constants::SEARCH_LIMIT, diff --git a/app/javascript/vue/protocol/step.vue b/app/javascript/vue/protocol/step.vue index bd8817e839..0d2814b8fe 100644 --- a/app/javascript/vue/protocol/step.vue +++ b/app/javascript/vue/protocol/step.vue @@ -203,7 +203,6 @@ @attachment:deleted="attachmentDeleted" @attachment:update="updateAttachment" @attachment:uploaded="loadAttachments" - @attachment:changed="reloadAttachment" @attachments:order="changeAttachmentsOrder" @attachment:moved="moveAttachment" @attachments:viewMode="changeAttachmentsViewMode" @@ -596,25 +595,6 @@ this.$emit('step:drag_enter', this.step.id); } }, - reloadAttachment(attachmentId) { - const index = this.attachments.findIndex(attachment => attachment.id === attachmentId); - const attachmentUrl = this.attachments[index].attributes.urls.asset_show - - axios.get(attachmentUrl) - .then((response) => { - const updatedAttachment = response.data.data; - const index = this.attachments.findIndex(attachment => attachment.id === attachmentId); - - if (index !== -1) { - this.attachments[index] = updatedAttachment; - } - }) - .catch((error) => { - console.error("Failed to reload attachment:", error); - }); - - this.showFileModal = false; - }, showStorageUsage() { return (this.elements.length || this.attachments.length) && !this.isCollapsed && this.step.attributes.storage_limit; }, diff --git a/app/javascript/vue/shared/content/attachments.vue b/app/javascript/vue/shared/content/attachments.vue index 20b96f63a5..2a8347e395 100644 --- a/app/javascript/vue/shared/content/attachments.vue +++ b/app/javascript/vue/shared/content/attachments.vue @@ -30,7 +30,7 @@
diff --git a/app/javascript/vue/shared/content/attachments/attachment_actions.vue b/app/javascript/vue/shared/content/attachments/attachment_actions.vue index d27107ad87..c157b214f9 100644 --- a/app/javascript/vue/shared/content/attachments/attachment_actions.vue +++ b/app/javascript/vue/shared/content/attachments/attachment_actions.vue @@ -49,7 +49,6 @@ @attachment:delete="$emit('attachment:delete', $event)" @attachment:moved="$emit('attachment:moved', $event)" @attachment:uploaded="$emit('attachment:uploaded', $event)" - @attachment:changed="$emit('attachment:changed', $event)" @attachment:update="$emit('attachment:update', $event)" @menu-toggle="$emit('attachment:toggle_menu', $event)" @attachment:versionRestored="$emit('attachment:versionRestored', $event)" @@ -72,7 +71,6 @@