From 0d4f237a83977838bdc2c3748224fb8a73a6b0ff Mon Sep 17 00:00:00 2001 From: cntoplolicon Date: Tue, 3 Nov 2015 09:52:34 +0800 Subject: [PATCH] move admin logic to admin path --- app.rb | 9 ++++++++ controllers/admin.rb | 30 +++++++++++++++++++++++++ controllers/release.rb | 30 ------------------------- public/js/components/androidRelease.jsx | 2 +- 4 files changed, 40 insertions(+), 31 deletions(-) delete mode 100644 controllers/release.rb diff --git a/app.rb b/app.rb index 4ccb031..4128bcd 100644 --- a/app.rb +++ b/app.rb @@ -39,3 +39,12 @@ def success get '/' do send_file File.join(settings.public_folder, 'index.html') end + +get '/app_release/android' do + @app_release = AppRelease.first + if @app_release + json @app_release + else + json version_code: 0 + end +end diff --git a/controllers/admin.rb b/controllers/admin.rb index 1cf0873..ea708f8 100644 --- a/controllers/admin.rb +++ b/controllers/admin.rb @@ -1,4 +1,6 @@ require 'rmagick' +require 'ruby_apk' +require 'nokogiri' def validate_admin_account @user = User.where(username: params[:username]).take @@ -106,3 +108,31 @@ def validate_admin_account @user = User.where(id: params[:user_id]).includes(posts: :post_pages).take render :rabl, :admin_user end + +get '/admin/app_release/android' do + @app_release = AppRelease.first + if @app_release + json @app_release + else + json version_code: 0 + end +end + +post '/admin/app_release/android' do + @app_release = AppRelease.first_or_initialize + @app_release.message = params[:message] + + if params[:archive] + apk = Android::Apk.new(params[:archive][:tempfile].path) + manifest = apk.manifest + xml = Nokogiri::XML(manifest.to_xml) + version_code = xml.root['android:versionCode'].to_i + @app_release.version_code = version_code + + path = upload_file_to_s3(params[:archive], key: params[:archive][:filename], bucket: settings.s3[:storage_bucket]) + @app_release.download_url = settings.cdn[:storage_host] + path + end + + @app_release.save + json @app_release +end diff --git a/controllers/release.rb b/controllers/release.rb deleted file mode 100644 index fd8b2d5..0000000 --- a/controllers/release.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'ruby_apk' -require 'nokogiri' - -get '/app_release/android' do - @app_release = AppRelease.first - if @app_release - json @app_release - else - json version_code: 0 - end -end - -post '/admin/app_release/android' do - @app_release = AppRelease.first_or_initialize - @app_release.message = params[:message] - - if params[:archive] - apk = Android::Apk.new(params[:archive][:tempfile].path) - manifest = apk.manifest - xml = Nokogiri::XML(manifest.to_xml) - version_code = xml.root['android:versionCode'].to_i - @app_release.version_code = version_code - - path = upload_file_to_s3(params[:archive], key: params[:archive][:filename], bucket: settings.s3[:storage_bucket]) - @app_release.download_url = settings.cdn[:storage_host] + path - end - - @app_release.save - json @app_release -end diff --git a/public/js/components/androidRelease.jsx b/public/js/components/androidRelease.jsx index a4ece7f..e98139c 100644 --- a/public/js/components/androidRelease.jsx +++ b/public/js/components/androidRelease.jsx @@ -13,7 +13,7 @@ module.exports = React.createClass({ }, loadReleaseFromServer: function() { - var url = '/app_release/android' + var url = '/admin/app_release/android' $.ajax({ url: url, dataType: 'json',