-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor routes and controllers to better use HTTP verbs.
- Loading branch information
Showing
67 changed files
with
875 additions
and
1,057 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
class APIController < ApplicationController | ||
#skip_before_action :verify_authenticity_token | ||
before_action :find_server | ||
rescue_from ActiveRecord::RecordNotFound, with: :not_found | ||
|
||
def status | ||
active = server.running? | ||
status = server.pending_operation | ||
minecraft = server.minecraft.running? | ||
ip = server.remote.exists? ? server.remote.ip_address : nil | ||
download = server.minecraft.world_download_url | ||
render json: { | ||
server: active, | ||
status:, | ||
minecraft:, | ||
ip:, | ||
domain: server.host_name, | ||
download:, | ||
} | ||
end | ||
|
||
def start | ||
err = @server.start | ||
@server.user.invalidate_digital_ocean_cache_droplets | ||
@server.user.invalidate_digital_ocean_cache_volumes | ||
@server.user.invalidate_digital_ocean_cache_snapshots | ||
render json: { | ||
error: err, | ||
} | ||
end | ||
|
||
def stop | ||
err = @server.stop | ||
render json: { | ||
error: err, | ||
} | ||
end | ||
|
||
def reboot | ||
err = @server.reboot | ||
render json: { | ||
error: err, | ||
} | ||
end | ||
|
||
def pause | ||
err = @server.minecraft.pause | ||
render json: { | ||
error: err, | ||
} | ||
end | ||
|
||
def resume | ||
err = @server.minecraft.resume | ||
render json: { | ||
error: err, | ||
} | ||
end | ||
|
||
def backup | ||
err = @server.minecraft.backup | ||
render json: { | ||
error: err, | ||
} | ||
end | ||
|
||
def exec | ||
err = @server.minecraft.exec(@server.user, params[:command]) | ||
render json: { | ||
error: err, | ||
} | ||
end | ||
|
||
private | ||
def find_server | ||
@server = Server.find_by(id: params[:id], api_key: params[:key]) | ||
end | ||
|
||
def not_found | ||
render json: { | ||
error: 'Not found', | ||
}, status: 404 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class DigitalOcean::DropletsController < ApplicationController | ||
before_action :authenticate_user! | ||
layout false | ||
|
||
def index | ||
@do_droplets = current_user.digital_ocean_droplets | ||
end | ||
|
||
def destroy | ||
error = current_user.digital_ocean.droplet_delete(params[:id]) | ||
current_user.invalidate_digital_ocean_cache_droplets | ||
if error | ||
return redirect_to servers_path, flash: { error: } | ||
end | ||
redirect_to servers_path, flash: { notice: 'Deleted droplet on Digital Ocean' } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class DigitalOcean::ImagesController < ApplicationController | ||
before_action :authenticate_user! | ||
layout false | ||
|
||
def index | ||
@do_images = current_user.digital_ocean_images | ||
end | ||
|
||
def destroy | ||
error = current_user.digital_ocean.image_delete(params[:id]) | ||
current_user.invalidate_digital_ocean_cache_images | ||
if error | ||
return redirect_to servers_path, flash: { error: } | ||
end | ||
redirect_to servers_path, flash: { notice: 'Deleted snapshot on Digital Ocean' } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class DigitalOcean::SnapshotsController < ApplicationController | ||
before_action :authenticate_user! | ||
layout false | ||
|
||
def index | ||
@do_snapshots = current_user.digital_ocean_snapshots | ||
end | ||
|
||
def destroy | ||
error = current_user.digital_ocean.snapshot_delete(params[:id]) | ||
current_user.invalidate_digital_ocean_cache_snapshots | ||
if error | ||
return redirect_to volumes_path, flash: { error: } | ||
end | ||
redirect_to volumes_path, flash: { notice: 'Deleted snapshot on Digital Ocean' } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class DigitalOcean::SshKeysController < ApplicationController | ||
before_action :authenticate_user! | ||
layout false | ||
|
||
def index | ||
@do_ssh_keys = current_user.digital_ocean_ssh_keys | ||
end | ||
|
||
def create | ||
ssh_key_name = params[:digital_ocean_ssh_key][:name] | ||
ssh_public_key = params[:digital_ocean_ssh_key][:data] | ||
f = { success: 'Added SSH public key to Digital Ocean' } | ||
ssh_key = current_user.digital_ocean.ssh_key_create(ssh_key_name, ssh_public_key) | ||
if ssh_key.error? | ||
f = { error: ssh_key } | ||
end | ||
redirect_back fallback_location: servers_path, flash: f | ||
end | ||
|
||
def destroy | ||
error = current_user.digital_ocean.ssh_key_delete(params[:id]) | ||
current_user.invalidate_digital_ocean_cache_ssh_keys | ||
f = { success: 'Deleted SSH public key from Digital Ocean' } | ||
if error | ||
f = { error: } | ||
end | ||
redirect_back fallback_location: servers_path, flash: f | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class DigitalOcean::VolumesController < ApplicationController | ||
before_action :authenticate_user! | ||
layout false | ||
|
||
def index | ||
@do_volumes = current_user.digital_ocean_volumes | ||
end | ||
|
||
def destroy | ||
error = current_user.digital_ocean.volume_delete(params[:id]) | ||
current_user.invalidate_digital_ocean_cache_volumes | ||
if error | ||
return redirect_to volumes_path, flash: { error: } | ||
end | ||
redirect_to volumes_path, flash: { notice: 'Deleted volume on Digital Ocean' } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.