Skip to content

Commit

Permalink
[s3] manual re-sync button
Browse files Browse the repository at this point in the history
  • Loading branch information
shish authored and Giraffaman committed Jan 6, 2024
1 parent a7bb3d8 commit 2a5dd59
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions ext/s3/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Shimmie2;

use function MicroHTML\INPUT;

require_once "config.php";

class S3 extends Extension
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2a5dd59

Please sign in to comment.