App-bsky
view release on metacpan or search on metacpan
lib/App/bsky.pm view on Meta::CPAN
$displayName //= $profile->{displayName};
$description //= $profile->{description};
}
if ( defined $avatar ) {
if ( $avatar =~ m[^https?://] ) {
my ( $content, $headers ) = $bsky->at->http->get($avatar);
use Carp;
$content // confess 'failed to download avatar from ' . $avatar;
# TODO: check content type HTTP::Tiny and Mojo::UserAgent do this differently
$avatar = $bsky->uploadFile( $content, $headers->{'content-type'} );
}
elsif ( -e $avatar ) {
use Path::Tiny;
$avatar = path($avatar)->slurp_raw;
my $type = substr( $avatar, 0, 2 ) eq pack 'H*',
'ffd8' ? 'image/jpeg' : substr( $avatar, 1, 3 ) eq 'PNG' ? 'image/png' : 'image/jpeg'; # XXX: Assume it's a jpeg?
$avatar = $bsky->uploadFile( $avatar, $type );
}
else {
$self->err('unsure what to do with this avatar; does not seem to be a URL or local file');
}
if ($avatar) {
$self->say( 'uploaded avatar... %d bytes', $avatar->{size} );
}
else {
$self->say('failed to upload avatar');
}
}
if ( defined $banner ) {
if ( $banner =~ m[^https?://] ) {
my ( $content, $headers ) = $bsky->at->http->get($banner);
use Carp;
$content // confess 'failed to download banner from ' . $banner;
# TODO: check content type HTTP::Tiny and Mojo::UserAgent do this differently
$banner = $bsky->uploadFile( $content, $headers->{'content-type'} );
}
elsif ( -e $banner ) {
use Path::Tiny;
$banner = path($banner)->slurp_raw;
my $type = substr( $banner, 0, 2 ) eq pack 'H*',
'ffd8' ? 'image/jpeg' : substr( $banner, 1, 3 ) eq 'PNG' ? 'image/png' : 'image/jpeg'; # XXX: Assume it's a jpeg?
$banner = $bsky->uploadFile( $banner, $type );
}
else {
$self->err('unsure what to do with this banner; does not seem to be a URL or local file');
}
if ($banner) {
$self->say( 'uploaded banner... %d bytes', $banner->{size} );
}
else {
$self->say('failed to upload banner');
}
}
my $res = $bsky->at->put_record(
'app.bsky.actor.profile',
'self',
{ defined $displayName ? ( displayName => $displayName ) : (),
defined $description ? ( description => $description ) : (),
defined $avatar ? ( avatar => $avatar ) : (),
defined $banner ? ( banner => $banner ) : ()
}
( run in 0.679 second using v1.01-cache-2.11-cpan-b16cb0d3907 )