Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Remove need to store file data in the database using active storage.

Matthew Kennedydfbcd8eab0a8
diff --git a/api/app/controllers/spree/api/v2/storefront/digitals_controller.rb b/api/app/controllers/spree/api/v2/storefront/digitals_controller.rb
index 65749de8f7..40d0e5ff91 100644
--- a/api/app/controllers/spree/api/v2/storefront/digitals_controller.rb
+++ b/api/app/controllers/spree/api/v2/storefront/digitals_controller.rb
@@ -8,8 +8,8 @@ module Spree
if digital_link.authorize!
send_file(
ActiveStorage::Blob.service.path_for(attachment.key),
- filename: attachment.record.attachment_file_name,
- type: attachment.record.attachment_content_type,
+ filename: attachment.filename.to_s,
+ type: attachment.content_type.to_s,
status: :ok
) and return
end
diff --git a/api/app/serializers/spree/api/v2/platform/digital_serializer.rb b/api/app/serializers/spree/api/v2/platform/digital_serializer.rb
index 486219c739..98826aea57 100644
--- a/api/app/serializers/spree/api/v2/platform/digital_serializer.rb
+++ b/api/app/serializers/spree/api/v2/platform/digital_serializer.rb
@@ -5,13 +5,23 @@ module Spree
class DigitalSerializer < BaseSerializer
set_type :digital
- attributes :attachment_file_name, :attachment_file_size, :attachment_content_type
-
attribute :url do |digital|
url_helpers = Rails.application.routes.url_helpers
url_helpers.polymorphic_url(digital.attachment, only_path: true)
end
+ attribute :content_type do |digital|
+ digital.attachment.content_type
+ end
+
+ attribute :filename do |digital|
+ digital.attachment.filename
+ end
+
+ attribute :byte_size do |digital|
+ digital.attachment.byte_size
+ end
+
belongs_to :variant
end
end
diff --git a/core/db/migrate/20210929093238_create_spree_digitals.rb b/core/db/migrate/20210929093238_create_spree_digitals.rb
index 45d0bf583e..443cb05f78 100644
--- a/core/db/migrate/20210929093238_create_spree_digitals.rb
+++ b/core/db/migrate/20210929093238_create_spree_digitals.rb
@@ -2,9 +2,6 @@ class CreateSpreeDigitals < ActiveRecord::Migration[5.2]
def change
create_table :spree_digitals, if_not_exists: true do |t|
t.belongs_to :variant
- t.string :attachment_file_name
- t.string :attachment_content_type
- t.integer :attachment_file_size
t.timestamps
end