update post endpoint, add upload script

This commit is contained in:
Rawley Fowler
2023-07-10 12:59:07 -06:00
parent 1442f95a72
commit 8f79ecba00
2 changed files with 48 additions and 3 deletions

37
upload.pl Normal file
View File

@@ -0,0 +1,37 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Mojo::UserAgent;
use Mojo::File;
use Carp qw(croak carp);
my $file = Mojo::File->new(shift)
|| croak q{Expected $1 to be a file path, or couldn't open file};
my $ua = Mojo::UserAgent->new;
my $hn = shift || croak q{Expected $2 to be header name};
my $pw = shift || croak q{Expected $3 to be password};
my $ti = shift || croak q{Expected $4 to be title};
my $sl = shift || croak q{Expected $5 to be slug};
my $uri =
$ENV{BLOG_DEVELOPMENT} ? 'http://localhost:3000' : 'https://rawley.xyz';
my $j = {
content => $file->slurp,
title => $ti,
slug => $sl
};
my $r =
$ua->post( ( $uri . '/blog' ) => { $hn => $pw } => json => $j )->result;
if ( $r->is_success ) {
print 'Upload successful';
}
else {
carp q{Failed to upload } . $r->code;
exit 1;
}