Peertube-dl/bin/peertube-dl-web
2020-12-29 12:00:55 +01:00

47 lines
1.3 KiB
Perl
Executable File

#!/usr/bin/env perl
use Mojolicious::Lite -signatures;
use strict;
use warnings;
use feature 'say';
use Peertube::DL::URLHandler;
use Peertube::DL;
get '/' => sub {
my $c = shift;
return $c->redirect_to('index.html');
};
post '/api' => sub {
my $c = shift;
my $url = $c->req->json->{url}
// ( return $c->render( text => 'Malformed request due missing url json parameter.', status => 400 ) );
my $render_returned;
eval { $render_returned = $c->render( json => Peertube::DL::URLHandler::getDownloadDataFromURL($url) ); };
if ($@) {
return $c->render( text => $@, status => 500 );
}
return $render_returned;
};
post '/proxy_to_get' => sub {
my $c = shift;
my $url = $c->req->json->{url}
// ( return $c->render( text => 'Malformed request due missing url json parameter.', status => 400 ) );
die "Not supported url" unless $url =~ s/^https:\/\///r =~ /^storage\.googleapis\.com/;
my $ua = Peertube::DL::URLHandler::generateUA();
return $c->render(
data => $ua->get($url)->decoded_content,
format => 'bin'
);
};
push @{ app->renderer->paths }, ( Peertube::DL::getDir() . '/Peertube/DL/templates' );
push @{ app->static->paths }, ( Peertube::DL::getDir() . '/Peertube/DL/public' );
my $config = plugin 'Config';
app->start;