Delete pins from webUI
This commit is contained in:
parent
db5898c07f
commit
58b8d33e69
|
@ -79,6 +79,7 @@ sub startup($self) {
|
|||
$r->get('/my/tokens/generate')->to('Interface#gen_token_get');
|
||||
$r->post('/my/tokens/generate')->to('Interface#gen_token_post');
|
||||
$r->get('/my/tokens/#id/delete')->to('Interface#del_token');
|
||||
$r->get('/my/pins/#id/delete')->to('Interface#del_pin');
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -94,4 +94,56 @@ sub del_token($c) {
|
|||
});
|
||||
}
|
||||
|
||||
sub del_pin($c) {
|
||||
my $uid = $c->session->{uid};
|
||||
my $id = $c->param('id');
|
||||
if (!defined $uid) {
|
||||
return $c->redirect_to("/login");
|
||||
}
|
||||
|
||||
return $c->pins->get({
|
||||
id => $id,
|
||||
uid => $uid,
|
||||
})->then(sub ($pin) {
|
||||
if (!defined $pin) {
|
||||
$c->flash(msg => "That pin doesn't exist.");
|
||||
return $c->redirect_to('/my/tokens');
|
||||
}
|
||||
|
||||
# I wonder if this could cause a race condition.
|
||||
# Who cares!
|
||||
my $cid = $pin->{cid};
|
||||
say $cid;
|
||||
|
||||
return $c->pins->cid_count($cid)->then(sub ($count) {
|
||||
if ($count == 1) {
|
||||
my $url = Mojo::URL->new($c->config->{ipfs}->{gatewayWriteUrl});
|
||||
$url->path("api/v0/pin/rm");
|
||||
$url->query({
|
||||
arg => $cid,
|
||||
recursive => "true",
|
||||
});
|
||||
|
||||
return $c->ua->post_p($url);
|
||||
}
|
||||
|
||||
return 1;
|
||||
})->then(sub ($tx) {
|
||||
if ($tx != 1) {
|
||||
my $res = $tx->result;
|
||||
if (!$res->is_success) {
|
||||
die "Could not delete pin!";
|
||||
}
|
||||
}
|
||||
|
||||
return $c->pins->del({
|
||||
id => $id,
|
||||
});
|
||||
})->then(sub {
|
||||
$c->flash(msg => "Pin deleted.");
|
||||
return $c->redirect_to('/my');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -294,7 +294,8 @@ sub delete($c) {
|
|||
my $id = $c->param('requestid');
|
||||
|
||||
return $c->pins->get({
|
||||
id => $id,
|
||||
id => $id,
|
||||
uid => $uid,
|
||||
})->then(sub ($pin) {
|
||||
if (!defined $pin) {
|
||||
return $c->render(status => 404, openapi => {
|
||||
|
@ -304,14 +305,6 @@ sub delete($c) {
|
|||
},
|
||||
});
|
||||
}
|
||||
if ($pin->{uid} ne $uid) {
|
||||
return $c->render(status => 401, openapi => {
|
||||
error => {
|
||||
reason => "UNAUTHORIZED",
|
||||
details => "You cannot delete that pin.",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
# I wonder if this could cause a race condition.
|
||||
# Who cares!
|
||||
|
|
|
@ -6,11 +6,20 @@
|
|||
<a href="/my/tokens">Click here</a> to manage your access tokens.
|
||||
</p>
|
||||
|
||||
% if (my $msg = flash 'msg') {
|
||||
<p>
|
||||
<b>
|
||||
%= $msg
|
||||
</b>
|
||||
</p>
|
||||
% }
|
||||
|
||||
<ul>
|
||||
% for my $pin (@$pins) {
|
||||
<li>
|
||||
<a href="<%= $gateway %><%= $pin->{cid} %>"><%= $pin->{name} || $pin->{cid} %></a>:
|
||||
<a href="/my/delete/<%= $pin->{id} %>">Delete</a>
|
||||
<a href="/my/pins/<%= $pin->{id} %>/delete">Delete</a>
|
||||
<small>Created by: <%= $pin->{app_name} %></small>
|
||||
</li>
|
||||
% }
|
||||
</ul>
|
||||
|
|
Loading…
Reference in New Issue