From b4f61efbfc6296b10fb5ce823c596ed2619e7c5d Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 6 Jan 2024 22:26:22 +0000 Subject: [PATCH] [s3] manual re-sync button --- ext/s3/main.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/ext/s3/main.php b/ext/s3/main.php index 9c85a317f..41cbab02d 100644 --- a/ext/s3/main.php +++ b/ext/s3/main.php @@ -4,6 +4,8 @@ namespace Shimmie2; +use function MicroHTML\INPUT; + require_once "config.php"; class S3 extends Extension @@ -52,6 +54,36 @@ public function onCommand(CommandEvent $event) } } + public function onPageRequest(PageRequestEvent $event) + { + global $config, $page, $user; + if ($event->page_matches("s3/sync")) { + if ($user->check_auth_token()) { + if ($user->can(Permissions::DELETE_IMAGE) && isset($_POST['image_id'])) { + $id = int_escape($_POST['image_id']); + if ($id > 0) { + $this->sync_post(Image::by_id($id)); + log_info("s3", "Manual resync for >>$id", "File re-sync'ed"); + $page->set_mode(PageMode::REDIRECT); + $page->set_redirect(make_link("post/view/$id")); + } + } + } + } + } + + public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) + { + global $user; + if ($user->can(Permissions::DELETE_IMAGE)) { + $event->add_part(SHM_SIMPLE_FORM( + "s3/sync", + INPUT(["type" => 'hidden', "name" => 'image_id', "value" => $event->image->id]), + INPUT(["type" => 'submit', "value" => 'CDN Re-Sync']), + )); + } + } + public function onImageAddition(ImageAdditionEvent $event) { // Tags aren't set at this point, let's wait for the TagSetEvent