[ImageThumbnail] Structure of plugin to generate thumbnails for image attachments

This commit is contained in:
Hugo Sales 2021-04-15 22:47:33 +00:00
parent 7284c833a6
commit ee87961d96
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
2 changed files with 86 additions and 0 deletions

View File

@ -0,0 +1,53 @@
<?php
// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
namespace Plugin\ImageThumbnail\Controller;
use App\Core\Controller;
use App\Core\DB\DB;
use App\Util\Common;
use Symfony\Component\HttpFoundation\Request;
class ImageThumbnail extends Controller
{
/**
* Get a thumbnail for the attachment with id $id
*/
public function thumbnail(Request $request, int $id)
{
$attachemnt = DB::findOneBy('attachment', ['id' => $id]);
if (!is_null($attachemnt->getScope())) {
// && ($attachemnt->scope | VisibilityScope::PUBLIC) != 0
// $user = Common::ensureLoggedIn();
assert(false, 'Attachment scope not implemented');
}
// TODO rate limit
$max_width = Common::config('thumbnail', 'width');
$max_height = Common::config('thumbnail', 'height');
$width = Common::clamp($this->int('w') ?? $max_width, min: 0, max: $max_width);
$height = Common::clamp($this->int('h') ?? $max_height, min: 0, max: $max_height);
$crop = $this->bool('c') ?? false;
dd($width, $height, $crop);
}
}

View File

@ -0,0 +1,33 @@
<?php
// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
namespace Plugin\ImageThumbnail;
use App\Core\Event;
use App\Core\Modules\Module;
use App\Core\Router\RouteLoader;
class ImageThumbnail extends Module
{
public function onAddRoute(RouteLoader $r)
{
$r->connect('thumbnail', '/thumbnail/{id<\d+>}', [Controller\ImageThumbnail::class, 'thumbnail']);
return Event::next;
}
}