2020-12-29 06:45:06 +01:00
|
|
|
#!/usr/bin/env perl
|
2020-12-29 06:33:37 +01:00
|
|
|
use Mojolicious::Lite -signatures;
|
2020-12-29 07:27:16 +01:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use feature 'say';
|
|
|
|
|
2020-12-29 06:33:37 +01:00
|
|
|
use Peertube::DL::URLHandler;
|
2020-12-29 07:27:16 +01:00
|
|
|
use Peertube::DL;
|
2020-12-29 06:33:37 +01:00
|
|
|
|
|
|
|
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'
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-12-29 07:27:16 +01:00
|
|
|
push @{ app->renderer->paths }, ( Peertube::DL::getDir() . '/Peertube/DL/templates' );
|
|
|
|
push @{ app->static->paths }, ( Peertube::DL::getDir() . '/Peertube/DL/public' );
|
2020-12-29 06:33:37 +01:00
|
|
|
|
2020-12-29 12:00:55 +01:00
|
|
|
my $config = plugin 'Config';
|
|
|
|
|
|
|
|
app->start;
|