「GNU social」の版間の差分

提供:GNU social JP Wiki
(Basic)
246行目: 246行目:
     }
     }
   ]
   ]
== Develop ==
=== Config ===
「[https://notabug.org/gnusocialjp/gnusocial/src/develop/lib/util/default.php lib/util/default.php]」にデフォルト設定一覧がある。
ここの設定項目は、 <code>common_config(key1, key2)</code>で参照できる。
=== Basic ===
バグ修正などで、通信と実コードの対応関係を特定する手順があるので整理する。
まず、GNU socialのサイトにアクセスすると、以下のpublic/.htaccessの内容に従って、URLがindex.php?p=<path>の形式に書き換えられる。
  <code>RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule (.*) index.php?p=$1 [L,QSA]</code>
lib/router.php: ルーティング処理 (URLによる挙動の変更) 。ここで<path>と呼び出される処理 (action) が対応づけられている。
index.php内の[https://notabug.org/gnusocialjp/gnusocial/src/develop/public/index.php main関数]でcall_user_func内で最終的にパスに対応するactionクラスのhandleを呼び出しており、このhandleの連鎖で処理が進む。
actionはactions配下にaction名.phpの形式で格納されている。
こういう風に見ると、ソースコードの該当処理を探しやすい。
例えば、グループを新規作成する画面は、POST group/newの通信を行う。これに対応づくactionはnewgroupとなっている。
実際、actions/newgroup.phpというファイルが存在する。この中にdoPost() があり、これで処理している。
このような流れで、だいたい行っている処理の場所を特定できる。
=== Register ===
* main/register
* api/account/register.:format

2024年1月18日 (木) 17:55時点における版

API

GNU socialのWeb APIについては,フッターの [Help](doc/help), [About](doc/about), [TOS](doc/tos) などを選択して遷移できるDOCS画面の [API](doc/api) (Api - GNU social JP) を選択することで表示できる。

ソースコード上はdoc-src (v2.0.2 - NotABug.org: Free code hosting) 配下にAPI文書が格納されている。

AtomPubとTwitter互換APIの2種類のAPIを利用可能。Twitter APIのほうがシンプルだが、AtomPubだとリッチテキストが使用可能など、機能に若干の違いがある。

以下の記事も参考になる。

API末尾の拡張子atom/xml/jsonに応じた形式の応答をサーバーが返す模様。

Twitter API

GNU socialのTwitter APIは完全互換ではないので注意が必要。

Post

wget -O - \
    --http-user=vaginaplant \
    --http-passwd=XXXXXX \
    --post-data='status=LGBTPZN' \
    https://freezepeach.xyz/api/statuses/update.json
curl -u username:password -d "status=status" https://domain/api/statuses/update.json

添付ファイルの例。

curl -u username:password \
  -F "media=@image.jpg" \
  -F "status=post message" \
  https://domain.jp/api/statuses/update.json

返信する場合、リクエストボディーにin_reply_to_status_idで返信先投稿IDを指定する。Twitter APIだと、本文に@メンションが必須だが、GSの場合、メンションは任意の模様。ただ、他の実装だと必須のものもあったりする。あるほうが安定するかもしれない。

Get

JSONの配列で応答が返ってくる。

 curl $HOST/api/statuses/user_timeline/test.json
 [
   {
     "text": "QSettings",
     "truncated": false,
     "created_at": "Thu Jan 04 11:51:11 +0900 2024",
     "in_reply_to_status_id": null,
     "uri": "tag:gnusocial.jp,2024-01-04:noticeId=5026657:objectType=note",
     "source": "",
     "source_link": null,
     "id": 5026657,
     "in_reply_to_user_id": null,
     "in_reply_to_screen_name": null,
     "geo": null,
     "user": {
       "id": 2,
       "name": "test",
       "screen_name": "test",
       "location": "Japan",
       "description": "gnusocial.jpのテストアカウントです。\r\nID/PW=test/666666。\r\n投稿にはメール登録が必要です。基本は閲覧用です。",
       "profile_image_url": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-stream.png",
       "profile_image_url_https": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-stream.png",
       "profile_image_url_profile_size": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-profile.png",
       "profile_image_url_original": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-profile.png",
       "groups_count": 1,
       "linkcolor": false,
       "backgroundcolor": false,
       "url": "https://example.com",
       "protected": false,
       "followers_count": 15,
       "friends_count": 1,
       "created_at": "Mon Jul 18 13:10:39 +0900 2022",
       "utc_offset": "32400",
       "time_zone": "Asia/Tokyo",
       "statuses_count": 35,
       "following": false,
       "statusnet_blocking": false,
       "notifications": false,
       "statusnet_profile_url": "https://gnusocial.jp/test",
       "cover_photo": false,
       "background_image": false,
       "profile_link_color": false,
       "profile_background_color": false,
       "profile_banner_url": false,
       "is_local": true,
       "is_silenced": false,
       "rights": {
         "delete_user": false,
         "delete_others_notice": false,
         "silence": false,
         "sandbox": false
       },
       "is_sandboxed": false,
       "ostatus_uri": "https://gnusocial.jp/index.php/user/2",
       "favourites_count": 0
     },
     "statusnet_html": "QSettings",
     "statusnet_conversation_id": 2539347,
     "statusnet_in_groups": false,
     "external_url": "https://gnusocial.jp/notice/5026657",
     "in_reply_to_profileurl": null,
     "in_reply_to_ostatus_uri": null,
     "attentions": [],
     "fave_num": 0,
     "repeat_num": 0,
     "is_post_verb": true,
     "is_local": true,
     "favorited": false,
     "repeated": false
   },
   {
     "text": "test 2",
     "truncated": false,
     "created_at": "Thu Jan 04 10:41:35 +0900 2024",
     "in_reply_to_status_id": null,
     "uri": "tag:gnusocial.jp,2024-01-04:noticeId=5026119:objectType=note",
     "source": "",
     "source_link": null,
     "id": 5026119,
     "in_reply_to_user_id": null,
     "in_reply_to_screen_name": null,
     "geo": null,
     "user": {
       "id": 2,
       "name": "test",
       "screen_name": "test",
       "location": "Japan",
       "description": "gnusocial.jpのテストアカウントです。\r\nID/PW=test/666666。\r\n投稿にはメール登録が必要です。基本は閲覧用です。",
       "profile_image_url": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-stream.png",
       "profile_image_url_https": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-stream.png",
       "profile_image_url_profile_size": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-profile.png",
       "profile_image_url_original": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-profile.png",
       "groups_count": 1,
       "linkcolor": false,
       "backgroundcolor": false,
       "url": "https://example.com",
       "protected": false,
       "followers_count": 15,
       "friends_count": 1,
       "created_at": "Mon Jul 18 13:10:39 +0900 2022",
       "utc_offset": "32400",
       "time_zone": "Asia/Tokyo",
       "statuses_count": 35,
       "following": false,
       "statusnet_blocking": false,
       "notifications": false,
       "statusnet_profile_url": "https://gnusocial.jp/test",
       "cover_photo": false,
       "background_image": false,
       "profile_link_color": false,
       "profile_background_color": false,
       "profile_banner_url": false,
       "is_local": true,
       "is_silenced": false,
       "rights": {
         "delete_user": false,
         "delete_others_notice": false,
         "silence": false,
         "sandbox": false
       },
       "is_sandboxed": false,
       "ostatus_uri": "https://gnusocial.jp/index.php/user/2",
       "favourites_count": 0
     },
     "statusnet_html": "test 2",
     "statusnet_conversation_id": 2539084,
     "statusnet_in_groups": false,
     "external_url": "https://gnusocial.jp/notice/5026119",
     "in_reply_to_profileurl": null,
     "in_reply_to_ostatus_uri": null,
     "attentions": [],
     "fave_num": 0,
     "repeat_num": 0,
     "is_post_verb": true,
     "is_local": true,
     "favorited": false,
     "repeated": false
   },
   {
     "text": "test (https://gnusocial.jp/test) started following めうるみ (とけた) (https://mewl.me/@mewl).",
     "truncated": false,
     "created_at": "Thu Sep 08 08:32:22 +0900 2022",
     "in_reply_to_status_id": null,
     "uri": "tag:gnusocial.jp,2022-09-07:subscription:2:person:9308:2022-09-08T08:32:22+09:00",
     "source": "activity",
     "source_link": null,
     "id": 274143,
     "in_reply_to_user_id": null,
     "in_reply_to_screen_name": null,
     "geo": null,
     "user": {
       "id": 2,
       "name": "test",
       "screen_name": "test",
       "location": "Japan",
       "description": "gnusocial.jpのテストアカウントです。\r\nID/PW=test/666666。\r\n投稿にはメール登録が必要です。基本は閲覧用です。",
       "profile_image_url": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-stream.png",
       "profile_image_url_https": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-stream.png",
       "profile_image_url_profile_size": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-profile.png",
       "profile_image_url_original": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-profile.png",
       "groups_count": 1,
       "linkcolor": false,
       "backgroundcolor": false,
       "url": "https://example.com",
       "protected": false,
       "followers_count": 15,
       "friends_count": 1,
       "created_at": "Mon Jul 18 13:10:39 +0900 2022",
       "utc_offset": "32400",
       "time_zone": "Asia/Tokyo",
       "statuses_count": 35,
       "following": false,
       "statusnet_blocking": false,
       "notifications": false,
       "statusnet_profile_url": "https://gnusocial.jp/test",
       "cover_photo": false,
       "background_image": false,
       "profile_link_color": false,
       "profile_background_color": false,
       "profile_banner_url": false,
       "is_local": true,
       "is_silenced": false,
       "rights": {
         "delete_user": false,
         "delete_others_notice": false,
         "silence": false,
         "sandbox": false
       },
       "is_sandboxed": false,
       "ostatus_uri": "https://gnusocial.jp/index.php/user/2",
       "favourites_count": 0
     },
     "statusnet_html": "test started following めうるみ (とけた).",
     "statusnet_conversation_id": 154562,
     "statusnet_in_groups": false,
     "external_url": "https://gnusocial.jp/notice/274143",
     "in_reply_to_profileurl": null,
     "in_reply_to_ostatus_uri": null,
     "attentions": [],
     "fave_num": 0,
     "repeat_num": 0,
     "is_post_verb": false,
     "is_local": true,
     "favorited": false,
     "repeated": false
   }
 ]

Develop

Config

lib/util/default.php」にデフォルト設定一覧がある。

ここの設定項目は、 common_config(key1, key2)で参照できる。

Basic

バグ修正などで、通信と実コードの対応関係を特定する手順があるので整理する。

まず、GNU socialのサイトにアクセスすると、以下のpublic/.htaccessの内容に従って、URLがindex.php?p=<path>の形式に書き換えられる。

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule (.*) index.php?p=$1 [L,QSA]

lib/router.php: ルーティング処理 (URLによる挙動の変更) 。ここで<path>と呼び出される処理 (action) が対応づけられている。

index.php内のmain関数でcall_user_func内で最終的にパスに対応するactionクラスのhandleを呼び出しており、このhandleの連鎖で処理が進む。

actionはactions配下にaction名.phpの形式で格納されている。

こういう風に見ると、ソースコードの該当処理を探しやすい。

例えば、グループを新規作成する画面は、POST group/newの通信を行う。これに対応づくactionはnewgroupとなっている。

実際、actions/newgroup.phpというファイルが存在する。この中にdoPost() があり、これで処理している。

このような流れで、だいたい行っている処理の場所を特定できる。

Register

  • main/register
  • api/account/register.:format