Commit f6d4271b authored by jz143's avatar jz143

attempt to fix download counts

parent df92b9cc
......@@ -27,19 +27,23 @@ class AppFilesController < ApplicationController
format.apk do
send_file @app_file.archive.path
@app_file.increment!(:download_count)
increment_download_count
end
format.plist do
render 'manifest.plist'
@app_file.increment!(:download_count)
if @app_file.signed?
render 'manifest.plist'
else
render json: { :error => 'Signed ipa is not available yet' }, status: :bad_request
end
increment_download_count
end
format.ipa do
if @app_file.signed?
send_file @app_file.signed_ipa_location, :type => 'application/octet-stream'
else
render json: { :error => 'Signed ipa is not available yet' }
render json: { :error => 'Signed ipa is not available yet' }, status: :bad_request
end
end
end
......@@ -109,6 +113,16 @@ class AppFilesController < ApplicationController
end
private
def increment_download_count
# ignore request if Range header exists and starting range is not 0
range = request.headers['Range'].match(/bytes=(?<begin>\d+)-(?<end>\d*)/)
if range[:begin] != '0'
return
end
@app_file.increment!(:download_count)
end
# Use callbacks to share common setup or constraints between actions.
def set_app_file
@app_file = AppFile.find(params[:id])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment