scinote-web/app/controllers/tiny_mce_assets_controller.rb

29 lines
860 B
Ruby
Raw Normal View History

2019-03-11 20:43:50 +08:00
# frozen_string_literal: true
2017-04-19 15:13:16 +08:00
class TinyMceAssetsController < ApplicationController
def create
2017-04-21 22:09:04 +08:00
image = params.fetch(:file) { render_404 }
2017-04-25 19:44:31 +08:00
tiny_img = TinyMceAsset.new(image: image,
2019-03-11 20:43:50 +08:00
team_id: current_team.id,
saved: false)
2017-04-21 22:09:04 +08:00
if tiny_img.save
render json: {
2017-04-24 22:22:25 +08:00
image: {
url: view_context.image_url(tiny_img.url(:large)),
token: Base62.encode(tiny_img.id)
}
2017-04-21 22:09:04 +08:00
}, content_type: 'text/html'
else
2017-04-24 22:22:25 +08:00
render json: {
error: tiny_img.errors.full_messages
}, status: :unprocessable_entity
2017-04-21 22:09:04 +08:00
end
2017-04-19 15:13:16 +08:00
end
2017-04-19 23:22:57 +08:00
2019-05-01 00:32:59 +08:00
def update
image = TinyMceAsset.find_by_id(Base62.decode(params[:id]))
2019-05-03 21:24:28 +08:00
image.update(image: params[:image], image_file_name: image.image_file_name)
2019-05-01 00:32:59 +08:00
render json: { url: view_context.image_url(image.url) }
end
2017-04-19 15:13:16 +08:00
end