Skip to content

Commit

Permalink
(#590) Add an endpoint to Shinobu API for resetting the filemap
Browse files Browse the repository at this point in the history
  • Loading branch information
Difegue committed Mar 20, 2022
1 parent 543609b commit 9995d70
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/LANraragi/Controller/Api/Shinobu.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,32 @@ sub shinobu_status {
);
}

sub reset_filemap {
my $self = shift;

# This is a shinobu endpoint even though we're deleting stuff in redis
# since we'll have to restart shinobu anyway to proc filemap re-creation.

my $redis = $self->LRR_CONF->get_redis;
$redis->del("LRR_FILEMAP");

my $shinobu = ${ retrieve( get_temp . "/shinobu.pid" ) };

#commit sudoku
$shinobu->kill();

# Create a new Process, automatically stored in TEMP_FOLDER/shinobu.pid
my $proc = start_shinobu($self);

$self->render(
json => {
operation => "shinobu_rescan",
success => $proc->poll(),
new_pid => $proc->pid
}
);
}

sub stop_shinobu {
my $self = shift;
my $shinobu = ${ retrieve( get_temp . "/shinobu.pid" ) };
Expand Down
1 change: 1 addition & 0 deletions lib/LANraragi/Utils/Routing.pm
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ sub apply_routes {
$logged_in_api->get('/api/shinobu')->to('api-shinobu#shinobu_status');
$logged_in_api->post('/api/shinobu/stop')->to('api-shinobu#stop_shinobu');
$logged_in_api->post('/api/shinobu/restart')->to('api-shinobu#restart_shinobu');
$logged_in_api->post('/api/shinobu/rescan')->to('api-shinobu#reset_filemap');

# Minion API
$public_api->get('/api/minion/:jobid')->to('api-minion#minion_job_status');
Expand Down
9 changes: 9 additions & 0 deletions templates/config.html.tt2
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@
});
}

function rescanContentFolder() {
$("#rescan-button").prop("disabled", true);
Server.callAPI("/api/shinobu/rescan", "POST", "Content folder rescan started!", "Error while restarting Worker:",
() => {
$("#rescan-button").prop("disabled", false);
shinobuStatus();
});
}

// Update the status of the background worker.
function shinobuStatus() {
Server.callAPI("/api/shinobu", "GET", null, "Error while querying Shinobu status:",
Expand Down
14 changes: 14 additions & 0 deletions templates/templates_config/config_files.html.tt2
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@
</td>
</tr>

<tr></tr>

<tr>
<td class="option-td">
<input id="rescan-button" class='stdbtn' type='button' onclick="rescanContentFolder()"
value='Rescan Archive Directory' />
</td>
<td class="config-td">
Click this button to trigger a rescan of the Archive Directory in case you're missing files, <br>
or some data such as total page counts. <br>
<br>
</td>
</tr>

<tr>
<td class="option-td">
<h2 class="ih"> Maximum <br>Temporary Folder Size </h2>
Expand Down

0 comments on commit 9995d70

Please sign in to comment.