Refactor into function and apply to all uses

This commit is contained in:
Citlali del Rey 2023-09-01 13:05:11 -07:00
parent 18994b5543
commit 6d20d13400
Signed by: nullobsi
GPG Key ID: 933A1F44222C2634
1 changed files with 13 additions and 16 deletions

View File

@ -8,6 +8,15 @@ use IpfsUpload::Util;
use Mojo::UserAgent;
use Mojo::JSON qw(decode_json encode_json);
# Form CID object, seperate so we can leave {name}
# out of it
sub pin_obj($name, $cid) {
my %cidobj = ();
$cidobj{cid} = $cid;
$cidobj{name} = $name if defined $name;
return \%cidobj;
}
sub list($c) {
$c->openapi->valid_input or return;
@ -34,10 +43,7 @@ sub list($c) {
# TODO
status => "pinned",
created => IpfsUpload::Util::date_format($v->{created_at}),
pin => {
cid => $v->{cid},
name => $v->{name},
},
pin => pin_obj($v->{name}, $v->{cid}),
delegates => $c->config->{ipfs}->{delegates},
meta => { app_name => $v->{app_name}},
};
@ -75,10 +81,7 @@ sub get($c) {
# TODO
status => "pinned",
created => IpfsUpload::Util::date_format($pin->{created_at}),
pin => {
cid => $pin->{cid},
name => $pin->{name} || $pin->{cid},
},
pin => pin_obj($pin->{name}, $pin->{cid}),
delegates => $c->config->{ipfs}->{delegates},
meta => { app_name => $pin->{app_name}},
});
@ -222,10 +225,7 @@ sub replace($c) {
# TODO
status => "pinned",
created => IpfsUpload::Util::date_format($pin->{created_at}),
pin => {
cid => $cid,
name => $name || $cid,
},
pin => pin_obj($name, $cid),
delegates => $c->config->{ipfs}->{delegates},
meta => { app_name => $app_name},
}, status => 202);
@ -384,10 +384,7 @@ sub add($c) {
# TODO
status => "pinned",
created => IpfsUpload::Util::date_format($res->{created_at}),
pin => {
cid => $cid,
name => $name || $cid,
},
pin => pin_obj($name, $cid),
delegates => $c->config->{ipfs}->{delegates},
meta => { app_name => $app_name},
}, status => 202)