Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/80 #93

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,10 @@ rules: {
'camelcase': 'off',
'class-methods-use-this': 'off',
'prefer-destructuring': 'off',
'vuejs-accessibility/click-events-have-key-events': 'off',
'vuejs-accessibility/form-control-has-label': 'off',
'vuejs-accessibility/label-has-for': 'off',
'vuejs-accessibility/no-autofocus': 'off',
'vuejs-accessibility/alt-text': 'off',
'semi': ['error', 'never']
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/public/storage
/public/modpacks
/public/modpacks-data
/public/launcher
/public/js
/public/css
/public/mix-manifest.json
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ foo@bar:~/MultigamingPanel$ npm run prod && php artisan migrate

###### Step 6 Configure your webserver to point to the public/ sub-directory

###### Step 6 Open the required ports
```console
foo@bar:~/MultigamingPanel$ ufw allow 443
foo@bar:~/MultigamingPanel$ ufw allow 6001
foo@bar:~/MultigamingPanel$ ufw allow 6660
```

## Emodyz Sponsors

You can sponsor us through various means.
Expand Down
7 changes: 6 additions & 1 deletion app/Http/Controllers/ModPackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function edit(Request $request, Modpack $modpack): Response|ModPackResour
->get()
->map(fn(Server $server) => $server->only(['id', 'name', 'logo_url', 'game']));

$modpack->servers;
$modpack->load('servers');

return inertia('ModPacks/Edit', compact('servers', 'modpack'));
}
Expand Down Expand Up @@ -209,6 +209,11 @@ public function cancelUpdate(Modpack $modpack): Response
}

$modpack->batch->cancel();

$modpack->update([
'job_batch_id' => null,
]);

return response()->noContent();
}
}
78 changes: 71 additions & 7 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

use App\Actions\Emodyz\Settings\EditSettings;
use App\Http\Requests\Settings\EditVoiceSettingsRequest;
use App\Services\Bridge\BridgeClientService;
use App\Settings\VoiceSettings;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Response;
Expand All @@ -17,18 +20,32 @@ public function __construct()
$this->middleware('can:settings-edit')->only(['edit']);

$this->middleware('can:settings-edit_voice')->only(['updateVoice']);

$this->middleware('can:settings-cp_update_check')->only(['checkForCpUpdate']);

$this->middleware('can:settings-cp_upgrade')->only(['checkForCpUpdate']);
}

/**
* Display a listing of the resource.
*
* @param VoiceSettings $voiceSettings
* @return \Illuminate\Http\Response|Response|ResponseFactory
* @param VoiceSettings $voiceSettings
* @return Response|ResponseFactory
*/
public function edit(VoiceSettings $voiceSettings)
{
$version = 'unknown';
try {
$bridgeClient = new BridgeClientService();

$version = $bridgeClient->getControlPanelVersion();
} catch (Exception $e) {
flash('BRIDGE ERROR', $e->getMessage(), 'error');
}


return inertia('Settings/Edit', [
'voiceSettings' => $voiceSettings->toArray()
'currentVersion' => $version,
'voiceSettings' => $voiceSettings->toArray()
]);
}

Expand All @@ -39,12 +56,59 @@ public function edit(VoiceSettings $voiceSettings)
* @param EditSettings $editor
* @return RedirectResponse
*/
public function updateVoice(EditVoiceSettingsRequest $request, EditSettings $editor): RedirectResponse
{
public function updateVoice(EditVoiceSettingsRequest $request, EditSettings $editor): RedirectResponse
{
$editor->editVoiceSettings($request->all());

flash('Voice Settings', "Your voice settings has been successfully saved.")->success();

return redirect()->back();
}
}

/**
* Check for control panel updates
*
* @return JsonResponse
*/
public function checkForCpUpdate(): JsonResponse
{
$target = 'none';
try {
$bridgeClient = new BridgeClientService();

$target = $bridgeClient->checkForControlPanelUpdate();
} catch (Exception $e) {
flash('BRIDGE ERROR', $e->getMessage(), 'error');
}

if ($target !== 'none') {
flash('A new version of the Control Panel is available.', $target, 'info');
}

return response()->json([
'target' => $target
]);
}

/**
* Initiates the upgrade process for the control panel by calling the cli using the gRpc Bridge
*
* @return JsonResponse
*/
public function upgradeCp(): JsonResponse
{
try {
$bridgeClient = new BridgeClientService();

$bridgeClient->upgradeControlPanel();
} catch (Exception $e) {
flash('BRIDGE ERROR', $e->getMessage(), 'error');
}

flash('Control Panel update started.', 'the application will be offline for a few minutes ', 'warning');

return response()->json([
'upgrade' => 'started'
]);
}
}
35 changes: 18 additions & 17 deletions app/Jobs/ProcessModPackFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Events\ModPack\ModPackProcessProgress;
use App\Models\Modpack;
use App\Services\Modpacks\ModpackUpdaterService;
use Illuminate\Bus\Batchable;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
Expand All @@ -27,15 +28,16 @@ class ProcessModPackFile implements ShouldQueue
/**
* Create a new job instance.
*
* @param Modpack $modpack
* @param string $filePath
* @param Modpack $modpack
* @param string $filePath
*/
public function __construct(Modpack $modpack, string $filePath)
{
$this->modpack = $modpack;
$this->filePath = $filePath;
}


/**
* Execute the job.
*
Expand All @@ -44,36 +46,35 @@ public function __construct(Modpack $modpack, string $filePath)
*/
public function handle()
{
if ($this->batch()->cancelled()) {
if ($this->batch()->cancelled() || $this->batch()->hasFailures()) {
info('Batch canceled or has failures, file skipped '. $this->filePath);
return;
}

info('Processing file '. $this->filePath);

$disk = $this->modpack->disk;

$filePath = Storage::disk($disk)->path($this->filePath);
$fileSize = Storage::disk($disk)->size($this->filePath);
$fileUrl = Storage::disk($disk)->url($this->filePath);
$fileHash = hash_file('sha256', $filePath);
$fileName = basename($filePath);
$filePath = (string)Str::of($this->filePath)->replaceFirst(
$filePath = (string) Str::of($this->filePath)->replaceFirst(
$this->modpack->path,
$this->modpack->name
);
$filePathPrevented = Str::of($filePath)
->replace('.', '-');

$this->modpack->forceFill([
"manifest_info->size" => $this->modpack->manifest_info['size'] + $fileSize,
"manifest_info->files" => $this->modpack->manifest_info['files'] + 1,
"manifest->{$filePathPrevented}" => [
'url' => $fileUrl,
'size' => $fileSize,
'name' => $fileName,
'path' => $filePath,
'sha256' => $fileHash
]
])->saveOrFail();
ModpackUpdaterService::fileProcessed(
modPack: $this->modpack,
fileName: $fileName,
fileSize: $fileSize,
fileUrl: $fileUrl,
filePath: $filePath,
fileHash: $fileHash
);

ModPackProcessProgress::broadcast($this->modpack, $this->batch()->progress());
}
}

38 changes: 22 additions & 16 deletions app/Listeners/Modpack/StartModPackUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
use App\Events\ModPack\ModPackProcessStarted;
use App\Events\ModPack\ModPackUpdateRequested;
use App\Jobs\ProcessModPackFile;
use App\Services\Modpacks\ModpackUpdaterService;
use Exception;
use Illuminate\Bus\Batch;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Throwable;

Expand All @@ -29,37 +32,40 @@ class StartModPackUpdate implements ShouldQueue
public function handle(ModPackUpdateRequested $event)
{
$modpack = $event->modPack;
$savedManifest = $modpack->manifest;
$savedManifestInfo = $modpack->manifest_info;
$modpack->cleanManifest();

$files = collect(Storage::disk($modpack->disk)->files($modpack->path, true));
if ($files->isEmpty()) {
ModPackProcessDone::broadcast($modpack);
return true;
}

ModpackUpdaterService::flush($modpack);

$jobs = $files->map(fn($file) => new ProcessModPackFile($modpack, $file));
$batch = Bus::batch($jobs->toArray())
->then(function (Batch $batch) use ($modpack, $savedManifest, $savedManifestInfo) {
->then(function (Batch $batch) use ($modpack) {
if ($batch->canceled()) {
ModPackProcessCanceled::broadcast($modpack);
return;
}

[$manifest, $manifestInfo] = ModpackUpdaterService::getUpdate($modpack);

if (!empty($manifest) && !empty($manifestInfo)) {
$modpack->update([
'manifest' => $savedManifest,
'manifest_info' => $savedManifestInfo
'manifest' => collect($manifest)->map(fn ($value) => json_decode($value)),
'manifest_info' => $manifestInfo,
'manifest_last_update' => now()->toDateTimeString()
]);
ModPackProcessCanceled::broadcast($modpack);
ModPackProcessDone::broadcast($modpack);
Log::info('Job done');
return;
}
$modpack->update([
'manifest_last_update' => now()->toDateTimeString()
]);
ModPackProcessDone::broadcast($modpack);
})->catch(function () use ($modpack, $savedManifest, $savedManifestInfo) {
$modpack->update([
'manifest' => $savedManifest,
'manifest_info' => $savedManifestInfo
]);

throw new Exception('Job not finalized correctly...');
})->catch(function () use ($modpack) {
ModPackProcessFailed::broadcast($modpack);
Log::alert('Job failed');
})->finally(function () use ($modpack) {
$modpack->update([
'job_batch_id' => null,
Expand Down
14 changes: 0 additions & 14 deletions app/Models/Modpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,4 @@ public function getBatchAttribute(): ?Batch
}
return Bus::findBatch($this->job_batch_id);
}

/**
* void
*/
public function cleanManifest()
{
$this->update([
'manifest' => [],
'manifest_info' => [
"size" => 0,
"files" => 0
]
]);
}
}
Loading