标签 Gotosocial 下的文章

使用API创建一个应用

curl -X POST 'https://your.instance.url/api/v1/apps' \ 
  -H 'Content-Type:application/json' \
  -d '{
      "client_name": "memos",
      "redirect_uris": "urn:ietf:wg:oauth:2.0:oob",
      "scopes": "read"
    }'

得到"client_id"和"client_secret"

{
    "id": "01MAXW228JRT327ACDW2MVQCR6",
    "name": "memos",
    "redirect_uri": "urn:ietf:wg:oauth:2.0:oob",
    "client_id": "01D9XG149GN5RTEWWQE5MDPA",
    "client_secret": "8799e15b-5978-4367-ba51-fd171fbb4d"
}

授权应用

访问 https://your.instance.url/oauth/authorize?client_id=your_new_client_id-id&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code

点击通过

得到了一个code,类似

NDEYYZBKOTQTYTCWYI0ZMZKYLWE5OTYTZDHKMTG2MDQ3YJA

获得access token

用上面获取的"client_id":,"client_secret","code"执行

curl -X POST 'https://your.instance.url/oauth/token' \
  -H 'Content-Type:application/json' 
  -d '{
      "redirect_uri": "urn:ietf:wg:oauth:2.0:oob",
      "client_id": "01D9XG149GN5RTEWWQE5MDPA",
      "client_secret": "8799e15b-5978-4367-ba51-fd171fbb4d",
      "grant_type": "authorization_code",
      "code": "NDEYYZBKOTQTYTCWYI0ZMZKYLWE5OTYTZDHKMTG2MDQ3YJA"
    }'

获取access_token

{
    "access_token": "MJRJYJMXZGMTMGNJMC0ZYZQ0LWIZYTITZTAZMTUZNDNKYMJ1",
    "created_at": 1716722670,
    "scope": "read",
    "token_type": "Bearer"
}

通过Cloudflare Workers获取json数据

替换以下的{url} {id} {token}即可

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  const url = "https://{url}/api/v1/accounts/{id}/statuses?limit=1000&exclude_replies=true&only_public=true&only_media=true";
  const init = {
    method: "GET",
    headers: {
      "content-type": "application/json;charset=UTF-8",
      "User-Agent": "Node.js/v14.15.1",
      "Authorization": "Bearer {token}" // Use your real token here
    }
  };

  let response = await fetch(url, init);
  const results = await response.json();

  // 构建新的响应并添加CORS头
  let corsHeaders = {
    "Access-Control-Allow-Origin": "*",  // 这将允许所有源访问,如果你想限制访问可以更改为特定的URI
    "Access-Control-Allow-Methods": "GET,POST,PUT,PATCH,DELETE,OPTIONS",  // 你可以根据实际需要更改这些方法
    "Access-Control-Allow-Headers": "Content-Type, Authorization, User-Agent"  // 加入你用到的其他头
  }

  let newResponse = new Response(JSON.stringify(results), {
    headers: corsHeaders
  });

  return newResponse;
}

根据API文档,此查询会默认获取30条 包括 回复 未公开的全部内容

获取最近1000条公开的未包括回复的内容

/api/v1/accounts/01MQ6Y9ZKC7TAJ7B97Q2TAMHXQ/statuses?limit=1000&exclude_replies=true&only_public=true

获取最近1000条公开的未回复的仅多媒体的内容

/api/v1/accounts/01MQ6Y9ZKC7TAJ7B97Q2TAMHXQ/statuses?limit=1000&exclude_replies=true&only_public=true&only_media=true

替换以上的API节点

演示地址
https://bbapi.ima.cm


[article id=1388]

介绍了如何优雅的部署Gotosocial.

本文是Gotosocial的使用进阶教程,如有不足,请指正

部署

根据官方示例文档,使用docker compose部署
编写docker-compose.yaml,如下

services:
  gotosocial:
    image: superseriousbusiness/gotosocial:latest
    container_name: gotosocial
    networks:
      - gotosocial
    environment:
      GTS_HOST: ima.cm
      GTS_DB_TYPE: sqlite
      GTS_DB_ADDRESS: /gotosocial/storage/sqlite.db
      GTS_STORAGE_BACKEND: s3
      GTS_STORAGE_S3_BUCKET: 
      GTS_STORAGE_S3_ENDPOINT: 
      GTS_STORAGE_S3_ACCESS_KEY: 
      GTS_STORAGE_S3_SECRET_KEY: 
      GTS_STORAGE_S3_PROXY: false
      GTS_ACCOUNTS_ALLOW_CUSTOM_CSS: true
      TZ: Asia/Chongqing
    ports:
      - "127.0.0.1:8080:8080"  
    volumes:
      - ./data:/gotosocial/storage
      - ./web:/gotosocial/web #映射出来
    restart: "always"

networks:
  gotosocial:
    ipam:
      driver: default

主要是为了把容器内的/gotosocial/web目录映射到本地目录./web,然后我们可以根据自己的需求来修改前端的模板

由于源码内的前端资源需要编译,所以我偷懒打包了一份编译好的提供给大家使用,

下载地址

该主题我粗略翻译了一下,演示如下

https://ima.cm

Environment

根据官方文档,参考设置文件config.yaml来自定义

https://github.com/superseriousbusiness/gotosocial/blob/main/example/config.yaml

其中,如果想更改数据库类型可以参照db-type: "postgres"来定义,在Environment 中必须全部使用大写字母和下划线,如GTS_DB_TYPE.:后面的设定值无需双引号""包裹.

WEB设置

默认值

# Default: "./web/template/"
web-template-base-dir: "./web/template/"
# Default: "./web/assets/"
web-asset-base-dir: "./web/assets/"

也可以通过更改Environment设置来自定义WEB的映射目录.

实例语言设置,貌似暂时不支持中文

# Example: ["nl", "en-gb", "fr"]
# Default: []
instance-languages: []

自定义CSS 的设置

# Options: [true, false]
# Default: false 默认关闭
accounts-allow-custom-css: false

如需开启则需要

GTS_ACCOUNTS_ALLOW_CUSTOM_CSS: true

储存设置

可以选择本地储存还是使用S3标准协议的对象储存来保存附件.

SMTP设置

# Default: ""
smtp-host: ""
# Default: 0
smtp-port: 0
# Default: ""
smtp-username: ""
# Default: ""
smtp-password: ""
# Default: ""
smtp-from: ""

以此

GTS_SMTP_HOST:
GTS_SMTP_PORT:
GTS_SMTP_USERNAME:
GTS_SMTP_PASSWORD:
GTS_SMTP_FROM:

字母全部大写,前面加上GTS,-一律写为_即可


Gotosocial是什么

GoToSocial 是一个使用 Golang 编写的 ActivityPub 社交网络服务器,它是一个轻量级、安全的联邦社交网络入口,可让用户保持联系、发布和分享图片、文章等内容。GoToSocial 强调用户的隐私和自由,不会跟踪用户的行为,也不会为了向用户展示广告而收集他们的数据。 使用 GoToSocial 可以让用户进入联邦社交网络的世界,联邦网络是一种基于协议的社交网络结构,它允许用户从一个社交网络实例互相跟随、交流和分享内容。这种结构可以让用户自由选择社交网络平台,同时避免某个平台垄断市场。用户可以在不同的实例之间进行跟随和互动,这样就可以更好地保护用户的隐私和自由。

部署方式

使用docker-compose部署

创建安装目录并更改权限

mkdir -p /var/www/gotosocial/data && cd /var/www/gotosocial && chown 1000:1000 ./data

配置 docker-compose.yaml 文件

version: "3.3"

services:
  gotosocial:
    image: superseriousbusiness/gotosocial:latest
    container_name: gotosocial
    networks:
      - gotosocial
    environment:
      GTS_HOST: social.example.com
      GTS_DB_TYPE: sqlite
      GTS_DB_ADDRESS: /gotosocial/storage/sqlite.db
      GTS_LETSENCRYPT_ENABLED: "false"
      GTS_STORAGE_BACKEND: "s3"
      GTS_STORAGE_S3_BUCKET: "BUCKET名称"
      GTS_STORAGE_S3_ENDPOINT: "#S3 API"
      GTS_STORAGE_S3_ACCESS_KEY: "#api-tokens"
      GTS_STORAGE_S3_SECRET_KEY: "#api-tokens"
      GTS_STORAGE_S3_PROXY: "true"
    ports:
      - "127.0.0.1:8080:8080"
    volumes:
      - ./data:/gotosocial/storage
    restart: "always"

networks:
  gotosocial:
    ipam:
      driver: default

支持S3存储

运行

docker compose up -d

创建用户

docker exec -it gotosocial ./gotosocial admin account create --username admin --email YOUR@EMAIL.COM --password  SOME_VERY_GOOD_PASSWD ;

自行更改用户名`密码`邮箱地址

admin改成自己需要的用户名

增加管理员权限

docker exec -it gotosocial ./gotosocial admin account promote --username admin

反向代理

反代127.0.0.1:8080即可 此处就不赘述了.

客户端

https://login.ima.cm

  • 大家都可以使用

演示

https://ima.cm