IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    @招手即停

    吴奕茗 (chengdulittlea@outlook.com)发表于 2023-01-10 14:34:32
    love 0

    ActivityPub是个好东西

    规格书↗

    如何实现一个ActivityPub↗

    但需要重新设计下有多人发帖时的空间。那么的维基主要的话题阅读模式不改变。

    也就是说评论可以评论但不可以插嘴

    阿最后这还是要ssl牌照

    到时候一元申请一个去

    Fediverse↗ 是一个开放社交媒体联合体,有其他标准和已经搭建的站点。

    gnu也有社交工具 gnu-social↗

    那么怎么做这么个呢

    对于我的用途实现个这个好像也没必要,把这个小网站做好看更重要……

    https://matrix.org/↗ → 一种分布运行的聊天工具。

    最近了解到的:

    使用indieweb系列工具可以做一个低科技社交互联,比如:利用h-entry↗和Web Mention↗。

    使用Self Auth↗可以自行验证密码而无需借助第三方帐号来反向链接,这个代码不大,可以修改修改整合到那么的维基中去。

    找到了一款足够简单的PHP→Mastodon的接口脚本↗,应该能够轻松整合近那么的维基。Fediverse型社交网站的主要问题仍然是,各个实例会自行保留一份数据拷贝,这种做法似乎并不理想。

    还挺好用的

    从那么的维基发帖到长毛象!

    Send posts from laMDWiki to Mastodon!

    图片

    Posting menu looks like this... also with replying.

    Images

    好的至少这个可以了

    为什么Activitypub没有卵用↗

    虽然但是,Bridgy有代码可以看,或许改成个极简实现:https://github.com/snarfed/bridgy-fed↗

    目前的Webfinger和(对外只读的)Outbox实现:

    function APubEnsureWebfinger($name, $host){
            if(!is_dir('.well-known')) mkdir('.well-known');
            if(!is_dir('.well-known/webfinger')) mkdir('.well-known/webfinger');
            $f = fopen('.well-known/webfinger/index.php',"w");
            $without_protocol = parse_url($host, PHP_URL_HOST);
            $finger = ["subject"=>"acct:".$name.'@'.$without_protocol,
                       "links"=>[["rel"=>"self", "type"=>"application/activity+json", "href"=>$host."?apub_actor=1"]]];
            fwrite($f, "<?php header('Content-Type: application/json'); echo '".json_encode($finger, JSON_UNESCAPED_SLASHES)."'; ?>"); fclose($f);
    
            if(!file_exists('.well-known/apub_public_key.pem') || !file_exists('.well-known/apub_private_key.php')){
                $res = openssl_pkey_new();
                $this->APubPublicKey = openssl_pkey_get_details($res)['key'];
                openssl_pkey_export($res, $this->APubPrivateKey);
                $f = fopen('.well-known/apub_public_key.pem',"w");
                fwrite($f, $this->APubPublicKey); fclose($f);
                $f = fopen('.well-known/apub_private_key.php',"w");
                fwrite($f, "<?php exit; ?>".PHP_EOL.PHP_EOL.$this->APubPrivateKey); fclose($f);
            }
        }
    
        function APubEnsureInfo(){
            if(!isset($this->APubID) || !isset($this->HostURL)) return;
            if(!file_exists('.well-known/apub_public_key.pem')){$this->APubEnsureWebfinger($this->APubID, $this->HostURL);}
            $pk = file_get_contents('.well-known/apub_public_key.pem'); //$pk = preg_replace('/\n/u','\\n',$pk);
            $actor = ["@context"=>["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1"],
                      "id"=> $this->HostURL."?apub_actor=1",
                      "type"=> "Person",
                      "name"=> $this->DisplayName,
                      "url"=> $this->HostURL,
                      "summary"=> "Lazy... No summary",
                      "preferredUsername"=> $this->APubID,
                      "inbox"=> $this->HostURL."?apub_inbox=1",
                      "outbox"=> $this->HostURL."?apub_outbox=1",
                      "publicKey"=> ["id"=> $this->HostURL."?apub_actor=1#main-key",
                                     "owner"=> $this->HostURL."?apub_actor=1",
                                     "publicKeyPem"=>$pk]];
            $this->APubActor = json_encode($actor, JSON_UNESCAPED_SLASHES);
        }
    
        function APubMakeOutbox(){
            $this->ReadPosts();$this->ReadImages();
            $obj = ["@context"=>"https://www.w3.org/ns/activitystreams",
                    "id"=>$this->HostURL."?apub_outbox=1",
                    "type"=>"OrderedCollection"];
            $items=[]; $i=0;
            foreach(array_reverse($this->Posts) as &$p){
                $this->ConvertPost($p);
                $text = strip_tags(preg_replace('/<\/(p|blockquote|h[0-9])>/u',"\n\n",$p['html']));
                $time = DateTime::createFromFormat('YmdHis', $p['id'], new DateTimeZone('+0800'));
                $ob = ["@context"=>"https://www.w3.org/ns/activitystreams",
                       "type"=> "Create",
                       "id"=> $this->HostURL."?post=".$p['id']."?apub_object=1",
                       "published"=> $time->format('Y-m-d\TH:i:s\Z'),
                       //"to"=> ["https://chatty.example/ben/"],
                       "actor"=> $this->HostURL."?apub_actor=1",
                       "to"=> ["https://www.w3.org/ns/activitystreams#Public"],
                       "object"=> ["type"=> "Note",
                                   "id"=> $this->HostURL."?post=".$p['id'],
                                   "published"=> $time->format('Y-m-d\TH:i:s\Z'),
                                   "attributedTo"=> $this->HostURL."?apub_actor=1",
                                   "to"=> ["https://www.w3.org/ns/activitystreams#Public"],
                                   "content"=> $text]];
                $items[] = $ob;
                $i++; if($i>20) break;
            }
            $obj['orderedItems'] = $items; $obj["totalItems"] = sizeof($items);
            return json_encode($obj, JSON_UNESCAPED_SLASHES);
        }

    这个设计很奇怪。Mastodon上如果没有向对方实例上的人发送“我发了这个消息”消息,那么那条消息就不会记录在Mastodon的数据库里,即使通过跨实例搜索用户可以显示出用户以及已发送消息数量。用户的Outbox是可以随时阅读的,请求对应的outbox.json就可以,因此不清楚为什么要这么设计。

    我如果只是想看别人的消息,只通过一个简单的程序抓取Outbox即可,而这和直接去阅读一堆RSS有什么区别?

    所有对其他用户的交互,例如评论和点赞都需要我向它们的Inbox发送通知,它们才能看间,因为至少Mastodon不主动抓取别人家的Outbox来了解行为。ActivityPub标准里面说明了Outbox可访问并查询到至少该用户发送的所有公开帖子,那么为什么Mastodon不这样实现?

    ActivityPub的优点是它“可能”能减少访问负荷,并且相比起订阅RSS,你可以收到来自未订阅者的消息。但是它的实现就其标准而言极不可靠:“出现网络错误时‘应该’↗重试”。这就远不如直接使用电子邮件了。

    上述特征也可以被认为有利,它兼容一种若即若离的非常连通网络社区,对传统社交空间和精力造成更小的影响并且推崇它们。

    这个有个似乎可用的符合几个apub实现的带签名的发送代码,看看:

    https://github.com/Zatnosk/StarShip↗

    要发送到公共主页:https://github.com/mastodon/mastodon/discussions/18389↗

    规范改了也球不说一声 垃圾

    https://socialhub.activitypub.rocks/t/help-needed-cannot-send-post-to-mastodon-inbox-verification-issue/2533/3↗

    好了请求现在是通的了

    2021/10/05 10:42:04 - 2023/01/10 14:34:32


沪ICP备19023445号-2号
友情链接