This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package App::DuckPAN::Cmd::Poupload; | ||
# ABSTRACT: Command for uploading .po files to the DuckDuckGo Community Platform | ||
|
||
use Moo; | ||
with qw( App::DuckPAN::Cmd ); | ||
|
||
use MooX::Options; | ||
use HTTP::Request::Common qw(POST); | ||
use LWP::UserAgent; | ||
use Path::Class; | ||
use Dist::Zilla::Util; | ||
|
||
option domain => ( | ||
is => 'ro', | ||
format => 's', | ||
predicate => 1, | ||
); | ||
|
||
option upload_uri => ( | ||
is => 'ro', | ||
format => 's', | ||
lazy => 1, | ||
builder => 1, | ||
); | ||
|
||
sub _build_upload_uri { 'https://dukgo.com/translate/po/upload' } | ||
|
||
sub get_request { | ||
my ( $self, $file ) = @_; | ||
my ( $user, $pass ) = $self->app->ddg->get_dukgo_user_pass; | ||
my $req = POST( | ||
$self->upload_uri, | ||
Content_Type => 'form-data', | ||
Content => { | ||
CAN_MULTIPART => 1, | ||
HIDDENNAME => $user, | ||
po_upload => [ $file ], | ||
$self->has_domain ? ( token_domain => $self->domain ) : (), | ||
}, | ||
); | ||
$req->authorization_basic($user, $pass); | ||
return $req; | ||
} | ||
|
||
sub run { | ||
my ( $self, @args ) = @_; | ||
for (@args) { | ||
$self->upload($_); | ||
} | ||
} | ||
|
||
sub upload { | ||
my ( $self, $file ) = @_; | ||
die "File not found" unless -f $file; | ||
print "Uploading ".$file."... "; | ||
my $response = $self->app->http->request($self->get_request($file)); | ||
die "Error: ".$response->code if $response->is_error || $response->is_redirect; | ||
print "success!\n"; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters