Skip to content
This repository has been archived by the owner on Jan 10, 2021. It is now read-only.

Commit

Permalink
move admin logic to admin path
Browse files Browse the repository at this point in the history
  • Loading branch information
cntoplolicon committed Nov 3, 2015
1 parent c2b7aeb commit 0d4f237
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 31 deletions.
9 changes: 9 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 30 additions & 0 deletions controllers/admin.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'rmagick'
require 'ruby_apk'
require 'nokogiri'

def validate_admin_account
@user = User.where(username: params[:username]).take
Expand Down Expand Up @@ -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
30 changes: 0 additions & 30 deletions controllers/release.rb

This file was deleted.

2 changes: 1 addition & 1 deletion public/js/components/androidRelease.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 0d4f237

Please sign in to comment.