Skip to content

Commit

Permalink
github issue #98, additional API functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Raekye committed Aug 13, 2019
1 parent c5fd7b4 commit aa4f3bb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
32 changes: 31 additions & 1 deletion app/controllers/servers_controller.rb
@@ -1,5 +1,15 @@
class ServersController < ApplicationController
before_action :authenticate_user!
@@api_endpoints = [
:api_status,
:api_start,
:api_stop,
:api_reboot,
:api_pause,
:api_resume,
:api_backup,
]
before_action :authenticate_user!, except: @@api_endpoints
skip_before_action :verify_authenticity_token, only: @@api_endpoints

def new
@server = Server.new
Expand Down Expand Up @@ -265,10 +275,16 @@ def api_status
active = server[0].running?
status = server[0].pending_operation
minecraft = server[0].minecraft.running?
ip = server[0].remote.exists? ? server[0].remote.ip_address : nil
domain = "#{server[0].domain}.#{Gamocosm::USER_SERVERS_DOMAIN}"
download = server[0].minecraft.world_download_url
render json: {
server: active,
status: status,
minecraft: minecraft,
ip: ip,
domain: domain,
download: download,
}
end

Expand Down Expand Up @@ -342,6 +358,20 @@ def api_resume
}
end

def api_backup
server = Server.where(id: params[:id], api_key: params[:key])
if server.length == 0
render json: {
error: 'Not found',
}, status: 404
return
end
err = server[0].minecraft.backup
return render json: {
error: err,
}
end

def show_digital_ocean_droplets
@do_droplets = current_user.digital_ocean_droplets
render layout: nil
Expand Down
11 changes: 6 additions & 5 deletions config/routes.rb
Expand Up @@ -90,11 +90,12 @@
get 'autoshutdown_disable'
get 'clear_logs'
get 'api/:key/status', to: 'servers#api_status', as: :api_status
get 'api/:key/start', to: 'servers#api_start', as: :api_start
get 'api/:key/stop', to: 'servers#api_stop', as: :api_stop
get 'api/:key/reboot', to: 'servers#api_reboot', as: :api_reboot
get 'api/:key/pause', to: 'servers#api_pause', as: :api_pause
get 'api/:key/resume', to: 'servers#api_resume', as: :api_resume
post 'api/:key/start', to: 'servers#api_start', as: :api_start
post 'api/:key/stop', to: 'servers#api_stop', as: :api_stop
post 'api/:key/reboot', to: 'servers#api_reboot', as: :api_reboot
post 'api/:key/pause', to: 'servers#api_pause', as: :api_pause
post 'api/:key/resume', to: 'servers#api_resume', as: :api_resume
post 'api/:key/backup', to: 'servers#api_backup', as: :api_backup
end
end

Expand Down

0 comments on commit aa4f3bb

Please sign in to comment.