Speedrunned Bluesky integration for news posts.
This commit is contained in:
parent
0701298fa1
commit
b3112ce433
6 changed files with 243 additions and 5 deletions
public-legacy/manage/news
|
@ -2,6 +2,7 @@
|
|||
namespace Misuzu;
|
||||
|
||||
use RuntimeException;
|
||||
use Index\XDateTime;
|
||||
|
||||
if(!isset($msz) || !($msz instanceof \Misuzu\MisuzuContext))
|
||||
die('Script must be called through the Misuzu route dispatcher.');
|
||||
|
@ -59,9 +60,73 @@ while($_SERVER['REQUEST_METHOD'] === 'POST' && CSRF::validateRequest()) {
|
|||
[$postInfo->id]
|
||||
);
|
||||
|
||||
if($isNew) {
|
||||
if($postInfo->featured) {
|
||||
// Twitter integration used to be here, replace with Railgun Pulse integration
|
||||
if($isNew && $postInfo->featured) {
|
||||
$bsky = $msz->config->scopeTo('bsky');
|
||||
if($bsky->hasValues(['identifier', 'password'])) {
|
||||
try {
|
||||
$xrpc = new \Misuzu\ATProto\XrpcClient($bsky->getString('pds', 'https://bsky.social'));
|
||||
$session = $xrpc->call(
|
||||
'com.atproto.server.createSession',
|
||||
data: [
|
||||
'identifier' => $bsky->getString('identifier'),
|
||||
'password' => $bsky->getString('password'),
|
||||
]
|
||||
)->data;
|
||||
|
||||
if(isset($session->accessJwt) && is_string($session->accessJwt)
|
||||
&& isset($session->did) && is_string($session->did)) {
|
||||
$url = $msz->siteInfo->url . $msz->urls->format('news-post', ['post' => $postInfo->id]);
|
||||
$body = sprintf("News :: %s\n", $postInfo->title);
|
||||
$urlStart = strlen($body);
|
||||
$body .= $url;
|
||||
$urlEnd = strlen($body);
|
||||
|
||||
$xrpc->call(
|
||||
'com.atproto.repo.createRecord',
|
||||
headers: [
|
||||
'authorization' => sprintf('Bearer %s', $session->accessJwt),
|
||||
],
|
||||
data: [
|
||||
'repo' => $session->did,
|
||||
'collection' => 'app.bsky.feed.post',
|
||||
'record' => [
|
||||
'$type' => 'app.bsky.feed.post',
|
||||
'createdAt' => XDateTime::toIso8601String($postInfo->createdAt),
|
||||
'text' => $body,
|
||||
'embed' => [
|
||||
'$type' => 'app.bsky.embed.external',
|
||||
'external' => [
|
||||
'uri' => $url,
|
||||
'title' => $postInfo->title,
|
||||
'description' => mb_substr($postInfo->firstParagraph, 0, 500),
|
||||
],
|
||||
],
|
||||
'facets' => [
|
||||
[
|
||||
'index' => [
|
||||
'byteStart' => $urlStart,
|
||||
'byteEnd' => $urlEnd,
|
||||
],
|
||||
'features' => [
|
||||
[
|
||||
'$type' => 'app.bsky.richtext.facet#link',
|
||||
'uri' => $url,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
$xrpc->call(
|
||||
'com.atproto.server.deleteSession',
|
||||
headers: [
|
||||
'authorization' => sprintf('Bearer %s', $session->accessJwt),
|
||||
],
|
||||
);
|
||||
}
|
||||
} catch(RuntimeException $ex) {}
|
||||
}
|
||||
|
||||
Tools::redirect($msz->urls->format('manage-news-post', ['post' => $postInfo->id]));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue