Skip to content
Permalink
Browse files

github issue #98, additional API functionality

  • Loading branch information...
Raekye committed Aug 13, 2019
1 parent c5fd7b4 commit aa4f3bb88f336703ac05e905c721ff0093ea060f
Showing with 37 additions and 6 deletions.
  1. +31 −1 app/controllers/servers_controller.rb
  2. +6 −5 config/routes.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
@@ -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

@@ -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
@@ -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

0 comments on commit aa4f3bb

Please sign in to comment.
You can’t perform that action at this time.