7d22cfe5c4
Issue #3
66 lines
1.6 KiB
Perl
Executable File
66 lines
1.6 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 $format = $c->req->json->{format};
|
|
my $render_returned;
|
|
eval {
|
|
$render_returned = $c->render(
|
|
json => Peertube::DL::URLHandler::getDownloadDataFromURL(
|
|
$url, { ( ( defined $format ) ? ( format => $format ) : () ) },
|
|
)
|
|
);
|
|
};
|
|
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/
|
|
|| $url =~ s/https?:\/\///r =~ s/\/.*$//r =~ /googlevideo\.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;
|