Skip to content

Commit

Permalink
Мультиязычность и лицензия
Browse files Browse the repository at this point in the history
  • Loading branch information
kiboko-dev committed Oct 13, 2024
1 parent ce2e455 commit 5a929c9
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 13 deletions.
9 changes: 9 additions & 0 deletions app/Http/Controllers/ConnectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Http\Requests\ConnectRequest;
use App\Http\Services\ConnectionService;
use App\Http\Services\LicenseService;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Knuckles\Scribe\Attributes as SA;
Expand All @@ -29,4 +30,12 @@ public function connect(ConnectRequest $request, ConnectionService $service): Js
$service->connect($request->validated('connection'))
);
}

public function test(): JsonResponse
{
$jwt = request()->input('license');
return response()->json(
LicenseService::checkAvailableNewThread($jwt, 5)
);
}
}
16 changes: 15 additions & 1 deletion app/Http/Requests/ConnectRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,22 @@ public function authorize(): bool

public function rules(): array
{
return [
$rules = [
'connection' => ['uuid', 'exists:connections,id'],
];
if (config('slonik.check_license')) {
$rules['license'] = ['required', 'string'];
}

return $rules;
}

public function messages(): array
{
return [
'license.required' => 'Необходимо указать лицензию',
'connection.exists' => 'Такого подключения не существует',
'connection.uuid' => 'Неверный формат ID подключения',
];
}
}
22 changes: 22 additions & 0 deletions app/Http/Services/LicenseService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Http\Services;

use Firebase\JWT\JWT;
use Firebase\JWT\Key;

class LicenseService
{
public static function checkAvailableNewThread($license, $threadsCount): bool
{
dd(self::decodeJWT($license));
$connections = (int)self::decodeJWT($license)->connections;
return $threadsCount < $connections;
}

private static function decodeJWT(string $jwt): \stdClass
{
return JWT::decode($jwt, new Key(config('slonik.jwt_key'), 'HS256'));
}

}
25 changes: 17 additions & 8 deletions app/MoonShine/Resources/ConnectionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ class ConnectionResource extends ModelResource
{
protected string $model = Connection::class;

protected string $title = 'Соединения';
protected function onBoot(): void
{
$this->formPage()->setTitle(__('slonik.connections_title'));

}

public function getActiveActions(): array
{
Expand All @@ -42,22 +45,22 @@ public function fields(): array
}
return [
ID::make()->sortable(),
Date::make('Настройки получены','last_connection')->sortable()->readonly()->hideOnUpdate(),
Block::make('Настройки',[
Number::make('Количество потоков', 'threads_count')->max(64)->step(1)->hideOnIndex(),
Select::make('Разрешение', 'thread_resolution')->options([
Date::make(__('slonik.last_connection'),'last_connection')->sortable()->readonly()->hideOnUpdate(),
Block::make(__('slonik.settings.title'),[
Number::make(__('slonik.settings.threads_count'), 'threads_count')->max(64)->step(1)->hideOnIndex(),
Select::make(__('slonik.settings.resolution'), 'thread_resolution')->options([
'480p' => '480p',
'720p' => '720p',
'1080p' => '1080p',
])->hideOnIndex(),
Select::make('Частота кадров', 'thread_framerate')->options([
Select::make(__('slonik.settings.thread_framerate'), 'thread_framerate')->options([
10 => 10,
15 => 15,
25 => 25,
30 => 30
])->hideOnIndex(),
Switcher::make('Подсветка активного монитора', 'highlight_active_tread')->hideOnIndex(),
Switcher::make('Подсветка зоны указателя мыши', 'highlight_mouse_pointer_area')->hideOnIndex(),
Switcher::make(__('slonik.settings.highlight_active_tread'), 'highlight_active_tread')->hideOnIndex(),
Switcher::make(__('slonik.settings.highlight_mouse_pointer_area'), 'highlight_mouse_pointer_area')->hideOnIndex(),
]),
];
}
Expand All @@ -66,4 +69,10 @@ public function rules(Model $item): array
{
return [];
}

public function getTitle(): ConnectionResource
{
$this->title = __('auth.failed');
return $this;
}
}
3 changes: 2 additions & 1 deletion app/Providers/MoonShineServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ protected function pages(): array
protected function menu(): array
{
return [
MenuItem::make('Соединения', new ConnectionResource()),
MenuItem::make('slonik.connections_title', new ConnectionResource())
->translatable(),
];
}

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"require": {
"php": "^8.1",
"bensampo/laravel-enum": "^6.11",
"firebase/php-jwt": "^6.10",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.3",
Expand Down
65 changes: 64 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
|
*/

'locale' => 'ru',
'locale' => 'en',

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion config/moonshine.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
'pipelines' => [],
],
'locales' => [
'ru',
'ru','en'
],

'global_search' => [
Expand Down
2 changes: 2 additions & 0 deletions config/slonik.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
'highlightActiveTread' => true,
'highlightMousePointerArea' => true,
],
'jwt_key' => 'X4Ma8mAwZDcTodT6',
'check_license' => false,
];
13 changes: 13 additions & 0 deletions lang/en/slonik.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
return [
'connections_title' => 'Connections',
'last_connection' => 'Last connection',
'settings' => [
'title' => 'Settings',
'threads_count' => 'Threads count',
'resolution' => 'Resolution',
'thread_framerate' => 'Thread framerate',
'highlight_active_tread' => 'Highlight active tread',
'highlight_mouse_pointer_area' => 'Highlight mouse pointer area',
]
];
13 changes: 13 additions & 0 deletions lang/ru/slonik.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
return [
'connections_title' => 'Соединения',
'last_connection' => 'Последнее подключение',
'settings' => [
'title' => 'Настройки',
'threads_count' => 'Количество потоков',
'resolution' => 'Разрешение',
'thread_framerate' => 'Частота кадров',
'highlight_active_tread' => 'Подсветка активного монитора',
'highlight_mouse_pointer_area' => 'Подсветка зоны указателя мыши',
]
];
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@

// Проверка лицензии и подключение
Route::post('/connect', [ConnectionController::class, 'connect']);
Route::post('/test', [ConnectionController::class, 'test']);

0 comments on commit 5a929c9

Please sign in to comment.