Skip to content

Commit

Permalink
Merge pull request #2187 from Wotuu/development
Browse files Browse the repository at this point in the history
Release v7.9 - Added API to generate custom thumbnails for routes
  • Loading branch information
Wotuu authored Feb 5, 2024
2 parents 66eb763 + 64cf5f1 commit 9015f0e
Show file tree
Hide file tree
Showing 333 changed files with 18,577 additions and 828 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy_live.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
key: ${{ secrets.DEPLOY_PRIVATE_KEY }}
script: cd /var/www/html/keystone.guru.live/;
php artisan readonly:enable &&
php artisan db:backup &&
php artisan db:backup;
php artisan up;
php artisan down --render="errors::503" --retry 60;
php artisan environment:updateprepare live &&
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
key: ${{ secrets.DEPLOY_PRIVATE_KEY }}
script: cd /var/www/html/keystone.guru.testing/;
php artisan readonly:enable &&
php artisan db:backup &&
php artisan db:backup;
php artisan up;
php artisan down --render="errors::503" --retry 60;
php artisan environment:updateprepare testing &&
Expand Down
7 changes: 5 additions & 2 deletions app/Console/Commands/Environment/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function handle()
// User permissions are funky for local environments - tell git to ignore them
if ($environment === 'local') {
$this->shell([
'git config --global --add safe.directory /var/www'
'git config --global --add safe.directory /var/www',
]);
}

Expand All @@ -121,7 +121,10 @@ public function handle()
RefreshDiscoverCache::dispatch();
$this->call('keystoneguru:view', ['operation' => 'cache']);

// Bit of a nasty hack to fix permission issues
// Regenerate API docs
$this->call('l5-swagger:generate');

// A bit of a nasty hack to fix permission issues
$this->shell(sprintf('chown www-data:www-data -R %s', base_path('storage')));
$this->shell(sprintf('chown www-data:www-data -R %s', base_path('bootstrap/cache')));

Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/Mapping/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Console\Commands\Traits\ExecutesShellCommands;
use App\Models\Dungeon;
use App\Models\DungeonFloorSwitchMarker;
use App\Models\DungeonRoute;
use App\Models\DungeonRoute\DungeonRoute;
use App\Models\Floor\Floor;
use App\Models\Mapping\MappingCommitLog;
use App\Models\Mapping\MappingVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Commands\Scheduler;

use App\Models\DungeonRoute;
use App\Models\DungeonRoute\DungeonRoute;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Commands\Scheduler;

use App\Models\DungeonRoute;
use App\Models\DungeonRoute\DungeonRoute;
use App\Service\DungeonRoute\ThumbnailServiceInterface;
use Exception;
use Illuminate\Console\Command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Console\Commands\Scheduler\Telemetry\Measurement;


use App\Models\DungeonRoute;
use App\Models\DungeonRoute\DungeonRoute;
use App\Models\PublishedState;
use Illuminate\Support\Collection;
use InfluxDB\Point;
Expand Down
59 changes: 59 additions & 0 deletions app/Console/Commands/Thumbnail/DeleteExpiredJobs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace App\Console\Commands\Thumbnail;

use App\Models\DungeonRoute\DungeonRouteThumbnailJob;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;

class DeleteExpiredJobs extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'thumbnail:deleteexpiredjobs';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Deletes any expired thumbnail jobs from the database.';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* @return int
*/
public function handle(): int
{
$count = 0;

DungeonRouteThumbnailJob::where('status', '<>', DungeonRouteThumbnailJob::STATUS_EXPIRED)
->where('created_at', '<', Carbon::now()->subSeconds(
config('keystoneguru.api.dungeon_route.thumbnail.expiration_time_seconds')
))->chunk(100, function (Collection $rows) use (&$count) {
/** @var Collection|DungeonRouteThumbnailJob[] $rows */
foreach ($rows as $row) {
$row->expire();
}

$count += $rows->count();
});

$this->info(sprintf('Cleaned up %d thumbnail jobs', $count));

return 0;
}
}
7 changes: 7 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
use App\Console\Commands\Scheduler\Telemetry\Telemetry;
use App\Console\Commands\Supervisor\StartSupervisor;
use App\Console\Commands\Supervisor\StopSupervisor;
use App\Console\Commands\Thumbnail\DeleteExpiredJobs;
use App\Console\Commands\View\Cache;
use App\Console\Commands\Wowhead\FetchHealth;
use App\Console\Commands\WowTools\RefreshDisplayIds;
Expand Down Expand Up @@ -149,6 +150,9 @@ class Kernel extends ConsoleKernel
StartSupervisor::class,
StopSupervisor::class,

// Thumbnail
DeleteExpiredJobs::class,

// Test
Random::class,

Expand Down Expand Up @@ -217,6 +221,9 @@ protected function schedule(Schedule $schedule)
// Sync ads.txt
$schedule->command('adprovider:syncadstxt')->everyFifteenMinutes();

// Cleanup the generated custom thumbnails
$schedule->command('thumbnail:deleteexpiredjobs')->everyFifteenMinutes();

Log::channel('scheduler')->debug('Finished scheduler');
}

Expand Down
2 changes: 1 addition & 1 deletion app/Events/ContextEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Events;

use App\Models\Dungeon;
use App\Models\DungeonRoute;
use App\Models\DungeonRoute\DungeonRoute;
use App\Models\LiveSession;
use App\User;
use Illuminate\Broadcasting\Channel;
Expand Down
7 changes: 4 additions & 3 deletions app/Helpers/ColorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @param $v
* @return float[]|int[]
*/
function hsv2rgb($h, $s, $v)
function hsv2rgb($h, $s, $v): array
{
$f = function ($n, $k = null) use ($h, $s, $v) {
if ($k === null) {
Expand All @@ -25,7 +25,7 @@ function hsv2rgb($h, $s, $v)
* @param $b
* @return array
*/
function rgb2hsv($r, $g, $b)
function rgb2hsv($r, $g, $b): array
{
$v = max($r, $g, $b);
$n = $v - min($r, $g, $b);
Expand All @@ -47,7 +47,7 @@ function rgb2hsv($r, $g, $b)
* @return array|float[]|int[]
* @throws Exception
*/
function hex2rgb($hex)
function hex2rgb($hex): array
{
$parts = str_split(substr($hex, 1), 2);
if (!$parts || count($parts) < 3) {
Expand Down Expand Up @@ -81,6 +81,7 @@ function hsv2name($h, $s, $v)
/**
* @param $hex
* @return mixed
* @throws Exception
*/
function hex2name($hex)
{
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/AdminToolsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use App\Logic\MDT\Exception\ImportWarning;
use App\Logic\MDT\Exception\InvalidMDTStringException;
use App\Models\Dungeon;
use App\Models\DungeonRoute;
use App\Models\DungeonRoute\DungeonRoute;
use App\Models\Floor\Floor;
use App\Models\Mapping\MappingVersion;
use App\Models\Npc;
Expand Down
108 changes: 60 additions & 48 deletions app/Http/Controllers/Ajax/AjaxBrushlineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
use App\Http\Controllers\Controller;
use App\Http\Controllers\Traits\SavesPolylines;
use App\Http\Requests\Brushline\APIBrushlineFormRequest;
use App\Http\Requests\Brushline\APIBrushlineUpdateFormRequest;
use App\Models\Brushline;
use App\Models\DungeonRoute;
use App\Models\DungeonRoute\DungeonRoute;
use App\Models\Floor\Floor;
use App\Models\Polyline;
use App\Service\Coordinates\CoordinatesServiceInterface;
use Exception;
Expand All @@ -17,6 +19,7 @@
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Teapot\StatusCode\Http;

class AjaxBrushlineController extends Controller
Expand All @@ -28,8 +31,9 @@ class AjaxBrushlineController extends Controller
* @param CoordinatesServiceInterface $coordinatesService
* @param DungeonRoute $dungeonRoute
* @param Brushline|null $brushline
* @return Brushline
* @return Brushline|Response
* @throws AuthorizationException
* @throws \Throwable
*/
function store(
APIBrushlineFormRequest $request,
Expand All @@ -44,57 +48,65 @@ function store(

$validated = $request->validated();

if ($brushline === null) {
$brushline = Brushline::create([
'dungeon_route_id' => $dungeonRoute->id,
'floor_id' => $validated['floor_id'],
'polyline_id' => -1,
]);
$success = $brushline instanceof Brushline;
} else {
$success = $brushline->update([
'dungeon_route_id' => $dungeonRoute->id,
'floor_id' => $validated['floor_id'],
]);
if (Floor::findOrFail($validated['floor_id'])->dungeon_id !== $dungeonRoute->dungeon_id) {
return response(__('controller.brushline.error.floor_not_found_in_dungeon'), 422);
}

try {
if ($success) {
// Create a new polyline and save it
$changedFloor = null;
$polyline = $this->savePolyline(
$coordinatesService,
$dungeonRoute->mappingVersion,
Polyline::findOrNew($brushline->polyline_id),
$brushline,
$validated['polyline'],
$changedFloor
);

// Couple the path to the polyline
$brushline->update([
'polyline_id' => $polyline->id,
'floor_id' => optional($changedFloor)->id ?? $brushline->floor_id,
]);
$result = null;

// Load the polyline so it can be echoed back to the user
$brushline->load(['polyline']);
DB::transaction(function () use ($coordinatesService, $brushline, $dungeonRoute, $validated, &$result) {
if ($brushline === null) {
$brushline = Brushline::create([
'dungeon_route_id' => $dungeonRoute->id,
'floor_id' => $validated['floor_id'],
'polyline_id' => -1,
]);
$success = $brushline instanceof Brushline;
} else {
$success = $brushline->update([
'dungeon_route_id' => $dungeonRoute->id,
'floor_id' => $validated['floor_id'],
]);
}

// Something's updated; broadcast it
if (Auth::check()) {
broadcast(new ModelChangedEvent($dungeonRoute, Auth::user(), $brushline));
try {
if ($success) {
// Create a new polyline and save it
$changedFloor = null;
$polyline = $this->savePolyline(
$coordinatesService,
$dungeonRoute->mappingVersion,
Polyline::findOrNew($brushline->polyline_id),
$brushline,
$validated['polyline'],
$changedFloor
);

// Couple the path to the polyline
$brushline->update([
'polyline_id' => $polyline->id,
'floor_id' => optional($changedFloor)->id ?? $brushline->floor_id,
]);

// Load the polyline, so it can be echoed back to the user
$brushline->load(['polyline']);

// Something's updated; broadcast it
if (Auth::check()) {
broadcast(new ModelChangedEvent($dungeonRoute, Auth::user(), $brushline));
}

// Touch the route so that the thumbnail gets updated
$dungeonRoute->touch();
} else {
throw new \Exception(__('controller.generic.error.unable_to_save'));
}

// Touch the route so that the thumbnail gets updated
$dungeonRoute->touch();
} else {
throw new \Exception('Unable to save brushline!');
$result = $brushline;
} catch (Exception $ex) {
$result = response(__('controller.generic.error.not_found'), Http::NOT_FOUND);
}

$result = $brushline;
} catch (Exception $ex) {
$result = response('Not found', Http::NOT_FOUND);
}
});

return $result;
}
Expand Down Expand Up @@ -124,10 +136,10 @@ function delete(Request $request, DungeonRoute $dungeonRoute, Brushline $brushli

$result = response()->noContent();
} else {
$result = response('Unable to save Brushline', Http::INTERNAL_SERVER_ERROR);
$result = response(__('controller.generic.error.unable_to_save'), Http::INTERNAL_SERVER_ERROR);
}
} catch (Exception $ex) {
$result = response('Not found', Http::NOT_FOUND);
$result = response(__('controller.generic.error.not_found'), Http::NOT_FOUND);
}

return $result;
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Ajax/AjaxDungeonRouteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
use App\Logic\MapContext\DungeonRouteProperties;
use App\Logic\MDT\Exception\ImportWarning;
use App\Models\Dungeon;
use App\Models\DungeonRoute;
use App\Models\DungeonRouteFavorite;
use App\Models\DungeonRouteRating;
use App\Models\DungeonRoute\DungeonRoute;
use App\Models\DungeonRoute\DungeonRouteFavorite;
use App\Models\DungeonRoute\DungeonRouteRating;
use App\Models\Expansion;
use App\Models\GameServerRegion;
use App\Models\PublishedState;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Ajax/AjaxEchoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Http\Controllers\Ajax;

use App\Http\Controllers\Controller;
use App\Models\DungeonRoute;
use App\Models\DungeonRoute\DungeonRoute;
use Illuminate\Http\Request;

class AjaxEchoController extends Controller
Expand Down
Loading

0 comments on commit 9015f0e

Please sign in to comment.