カスタムフィードを作ってみる?
1.ソース修正
Githubから取得
code:shell
code:.env
# Whichever port you want to run this on
FEEDGEN_PORT=3000
# Change this to use a different bind address
FEEDGEN_LISTENHOST="localhost"
# Set to something like db.sqlite to store persistently
# ファイルに保存する場合はファイルパス
FEEDGEN_SQLITE_LOCATION=":memory:"
# Don't change unless you're working in a different environment than the primary Bluesky network
FEEDGEN_SUBSCRIPTION_ENDPOINT="wss://bsky.social"
# Set this to the hostname that you intend to run the service at
FEEDGEN_HOSTNAME="${カスタムフィードのドメイン}"
# Set this to the DID of the account you'll use to publish the feed
# You can find your accounts DID by going to
FEEDGEN_PUBLISHER_DID="${カスタムフィードを公開するユーザのdid}"
# Only use this if you want a service did different from did:web
# FEEDGEN_SERVICE_DID="did:plc:abcde..."
サンプルとして以下のコードを修正した単純なもので説明する。
下記は「cat」「dog」を含んだ投稿をフィードとしています。src/algos/animals.tsはwhats-alf.tsをコピーして作成
code:src/algos/animals.ts(whats-alf.tsをコピーしたファイル)
- export const shortname = 'whats-alf'
+ export const shortname = 'animals' //レコード名(何でも良い。但し、scripts/publishFeedGen.tsのrecordNameと同じ値)
code:src/algos/index.ts
import { AppContext } from '../config'
import {
QueryParams,
OutputSchema as AlgoOutput,
} from '../lexicon/types/app/bsky/feed/getFeedSkeleton'
-import * as whatsAlf from './whats-alf'
+import * as animals from './animals'
type AlgoHandler = (ctx: AppContext, params: QueryParams) => Promise<AlgoOutput>
const algos: Record<string, AlgoHandler> = {
}
code:subscription.ts
const postsToDelete = ops.posts.deletes.map((del) => del.uri)
const postsToCreate = ops.posts.creates
.filter((create) => {
+ if (create.record.text.toLowerCase().includes(' cat ')) {
+ return true
+ }
+ if (create.record.text.toLowerCase().includes(' dog ')) {
+ return true
+ }
+ return false
})
.map((create) => {
// map alf-related posts to a db row
return {
uri: create.uri,
実行
code:sh
yarn start
2.Nginx設定
code:default
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/ドメイン名/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/ドメイン名privkey.pem; location / {
add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Methods "POST, GET, OPTIONS";
add_header Access-Control-Allow-Headers "Origin, Authorization, Accept";
add_header Access-Control-Allow-Credentials true;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
listen 80;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
}
カスタムフィードに直接アクセスする場合、
bluesky経由でアクセスする場合、
scripts/publishFeedGen.tsに必要事項を記入して実行でBlueskyに登録されるはず。
code:scripts/publishFeedGen.ts
// YOUR bluesky handle
// Ex: user.bsky.social
const handle = '${カスタムフィードを公開するユーザのhandle}'
// YOUR bluesky password, or preferably an App Password (found in your client settings)
// Ex: abcd-1234-efgh-5678
const password = '${カスタムフィードを公開するユーザのAppPassword}'
// A short name for the record that will show in urls
// Lowercase with no spaces.
// Ex: whats-hot
const recordName = '${algos/animals.tsで設定したshortName}'
// A display name for your feed
// Ex: What's Hot
const displayName = '${フィードの名前}'
// (Optional) A description of your feed
// Ex: Top trending content from the whole network
const description = ' ${フィードの説明}'
// (Optional) The path to an image to be used as your feed's avatar
// Ex: ~/path/to/avatar.jpeg
const avatar: string = '${フィードのアバターのパス}'
以下のコマンドで登録
code:sh
yarn publishFeed