Skip to content

Commit

Permalink
Updated ApiController
Browse files Browse the repository at this point in the history
  • Loading branch information
faab007nl committed Dec 18, 2023
1 parent 94f90d2 commit 7fab0e5
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 128 deletions.
34 changes: 26 additions & 8 deletions app/Http/Controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
use App\Models\UpdateRequest;
use App\Models\UpdateRequestStatus;
use App\Services\MavenDownloader;
use Illuminate\Support\Facades\Storage;
use Nette\Utils\Random;

class ApiController extends Controller
{
public function onNewRelease(){
// TODO: Change to laravel validation
$plugin_value_raw = request()->input('plugin_name');
$release_title = request()->input('release_title');
$release_description = request()->input('release_description');
Expand Down Expand Up @@ -92,7 +92,6 @@ public function onNewRelease(){
}

public function onVersionCheck(){
// TODO: Change to laravel validation
$plugin_value_raw = request()->input('plugin_name');
$current_version = request()->input('current_version');

Expand Down Expand Up @@ -154,7 +153,6 @@ public function onVersionCheck(){
}

public function onGetPlugins(){
// TODO: Change to laravel validation
$update_token = request()->input('update_token');

if (empty($update_token)){
Expand Down Expand Up @@ -220,10 +218,17 @@ public function onGetPlugins(){
}

public function onRequestUpdateCreate(){
// TODO: Change to laravel validation
$plugin_value_raw = request()->input('plugin_name');
$current_version = request()->input('current_version');

if (empty($plugin_value_raw) || empty($current_version)) {
return response()->json([
'status' => 'error',
'code' => 400,
'message' => 'Missing required parameters. plugin_name, current_version are required'
], 400);
}

if (!empty($current_version) && !$this->isValidVersion($current_version)){
return response()->json([
'status' => 'error',
Expand Down Expand Up @@ -274,9 +279,16 @@ public function onRequestUpdateCreate(){
}

public function onRequestUpdateCheck(){
// TODO: Change to laravel validation
$update_token = request()->input('update_token');

if(empty($update_token)){
return response()->json([
'status' => 'error',
'code' => 400,
'message' => 'Missing required parameters. update_token is required.'
], 400);
}

/** @var UpdateRequest $update_request */
$update_request = UpdateRequest::query()
->where('update_token', $update_token)
Expand All @@ -300,9 +312,16 @@ public function onRequestUpdateCheck(){
}

public function onRequestUpdateUpdate(){
// TODO: Change to laravel validation
$update_token = request()->input('update_token');

if (empty($update_token)){
return response()->json([
'status' => 'error',
'code' => 400,
'message' => 'Missing required parameters. update_token is required.'
], 400);
}

/** @var UpdateRequest $update_request */
$update_request = UpdateRequest::query()
->where('update_token', $update_token)
Expand Down Expand Up @@ -430,7 +449,6 @@ public function onRequestUpdateUpdate(){
}

public function onDownloadJar(){
// TODO: Change to laravel validation
$update_token = request()->input('update_token');
if (empty($update_token)){
return response()->json([
Expand Down Expand Up @@ -496,7 +514,7 @@ public function onDownloadJar(){
$update_request->status = UpdateRequestStatus::DOWNLOADED;
$update_request->save();

$file = \Storage::drive('plugins')->path($filename);
$file = Storage::drive('plugins')->path($filename);
return response()->download($file, $plugin_name.".jar");
} else {
return response()->json([
Expand Down
Loading

0 comments on commit 7fab0e5

Please sign in to comment.