mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: import/export theme should work with uploads
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
require_dependency 'upload_creator'
|
||||
require 'base64'
|
||||
|
||||
class Admin::ThemesController < Admin::AdminController
|
||||
|
||||
@@ -31,7 +32,28 @@ class Admin::ThemesController < Admin::AdminController
|
||||
|
||||
@theme = Theme.new(name: theme["name"], user_id: current_user.id)
|
||||
theme["theme_fields"]&.each do |field|
|
||||
@theme.set_field(target: field["target"], name: field["name"], value: field["value"])
|
||||
|
||||
if field["raw_upload"]
|
||||
begin
|
||||
tmp = Tempfile.new
|
||||
tmp.binmode
|
||||
file = Base64.decode64(field["raw_upload"])
|
||||
tmp.write(file)
|
||||
tmp.rewind
|
||||
upload = UploadCreator.new(tmp, field["filename"]).create_for(current_user.id)
|
||||
field["upload_id"] = upload.id
|
||||
ensure
|
||||
tmp.unlink
|
||||
end
|
||||
end
|
||||
|
||||
@theme.set_field(
|
||||
target: field["target"],
|
||||
name: field["name"],
|
||||
value: field["value"],
|
||||
type_id: field["type_id"],
|
||||
upload_id: field["upload_id"]
|
||||
)
|
||||
end
|
||||
|
||||
if @theme.save
|
||||
@@ -168,7 +190,7 @@ class Admin::ThemesController < Admin::AdminController
|
||||
|
||||
response.headers['Content-Disposition'] = "attachment; filename=#{@theme.name.parameterize}.dcstyle.json"
|
||||
response.sending_file = true
|
||||
render json: ThemeSerializer.new(@theme)
|
||||
render json: ThemeWithEmbeddedUploadsSerializer.new(@theme, root: 'theme')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user