List uploads on web interface

This commit is contained in:
Citlali del Rey 2022-11-05 09:28:17 -07:00
parent 2efd2fa6f3
commit 1865b08f0a
Signed by: nullobsi
GPG Key ID: 933A1F44222C2634
4 changed files with 69 additions and 1 deletions

View File

@ -12,7 +12,8 @@ ldap:
dnBase: 'CN=%u,OU=Users,DC=example,DC=org';
ipfs:
# Please add leading slash
# Please add leading slash for both
gatewayWriteUrl: "http://localhost:5001/"
gatewayPubUrl: "http://localhost:8080/ipfs/"
delegates:
- "/ip4/203.0.113.1/tcp/4001/p2p/QmServicePeerId"

View File

@ -67,6 +67,7 @@ sub startup($self) {
# Normal route to controller
$r->get('/login')->to('Login#login');
$r->post('/auth')->to('Login#auth');
$r->get('/my')->to('Interface#landing');
}
1;

View File

@ -0,0 +1,44 @@
package IpfsUpload::Controller::Interface;
use strict;
use warnings FATAL => 'all';
use experimental q/signatures/;
use Mojo::Base 'Mojolicious::Controller', -signatures;
sub landing($c) {
my $uid = $c->session->{uid};
if (!defined $uid) {
return $c->redirect_to("/login");
}
my $gateway = $c->config->{ipfs}->{gatewayPubUrl};
my $limit = $c->param('limit') || 10;
my $before = $c->param('before');
my %query = (
uid => $uid,
);
if (defined $before) {
$query{created_at} = { '<' => $before };
}
$c->pins->list(\%query, $limit)->then(sub ($res) {
$c->stash(
pins => $res,
limit => $limit,
gateway => $gateway,
);
if (@$res == $limit) {
$c->stash(nextPage => $res->[-1]->{created_at});
} else {
$c->stash(nextPage => 0);
}
$c->render('interface/landingPage');
})
}
1;

View File

@ -0,0 +1,22 @@
% layout "default";
% title "Uploads";
<h1>Uploads</h1>
<p>
Manage your uploads here.
<a href="/my/tokens">Click here</a> to manage your access tokens.
</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>
</li>
% }
</ul>
% if (scalar @$pins == 0) {
<p>Seems like there's nothing here.</p>
% } elsif (scalar @$pins == $limit) {
<a href="/my?before=<%= $nextPage %>">Next page</a>
% }