Skip to content

Commit

Permalink
add hacky support for custom feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa authored Feb 25, 2024
1 parent 99fa985 commit 04aa34b
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 39 deletions.
4 changes: 2 additions & 2 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"imports": {
"std/": "https://deno.land/std@0.204.0/",
"markup_tag": "https://deno.land/x/markup_tag@0.4.0/mod.ts",
"@atproto/api": "npm:@atproto/api@0.6.20"
"@atproto/api": "npm:@atproto/api@0.10.1"
},
"tasks": {
// runner
"dev": "deno run --allow-env=DENO_DEPLOYMENT_ID,BLUESKY_IDENTIFIER,BLUESKY_PASSWORD --allow-read=index.html,.env --allow-net=0.0.0.0,bsky.social --watch server.ts",
"dev": "deno run --allow-env=DENO_DEPLOYMENT_ID,BLUESKY_IDENTIFIER,BLUESKY_PASSWORD --allow-read=index.html,.env --allow-net --watch server.ts",
// development
"test": "deno test --allow-env=DENO_DEPLOYMENT_ID,BLUESKY_IDENTIFIER,BLUESKY_PASSWORD --allow-read=.env --allow-net=bsky.social --allow-none",
"cov": "deno task test --coverage=cov_profile; deno coverage cov_profile",
Expand Down
52 changes: 29 additions & 23 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<h1>Bluestream</h1>
<div>
<p>RSS feed generator for Bluesky.</p>
<p>Access to the path /bsky-handle directory or input handle of Bluesky here ↓</p>
<p>Access to the path /bsky-handle, /at://feed directory or input handle or feed at:// URI here ↓</p>
<form id="form">
<div>
<input id="input-handle" name="input-handle" aria-label="input-handle" required autofocus placeholder="xxx.bsky.social" />
Expand Down Expand Up @@ -73,7 +73,8 @@ <h1>Bluestream</h1>
<p>You can use DID (like <code>did:plc:xxxx</code>) instead of handle.</p>
<p>Currently only posts in bsky.social is supported.</p>
<p>
<a title="https://github.com/kawarimidoll/bluestream" target="_blank" rel="noopener noreferrer nofollow" href="https://github.com/kawarimidoll/bluestream">https://github.com/kawarimidoll/bluestream</a>
<a title="https://github.com/Erisa/bluestream" target="_blank" rel="noopener noreferrer nofollow" href="https://github.com/Erisa/bluestream">https://github.com/Erisa/bluestream</a>
</br>Fork of <a title="https://github.com/kawarimidoll/bluestream" target="_blank" rel="noopener noreferrer nofollow" href="https://github.com/kawarimidoll/bluestream">https://github.com/kawarimidoll/bluestream</a>
</p>
</div>
<script>
Expand Down
50 changes: 38 additions & 12 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,25 +387,51 @@ Deno.serve(async (request: Request) => {
});
}

const { did, handle } = await getActor(pathname.replace(/^\//, ""));
if (did === "") {
return new Response("Unable to resolve handle", {
headers: { "content-type": "text/plain" },
});
const feedid = pathname.replace(/^\//, "");
let name = feedid;
let did = "";

if (!name.startsWith("at://")) {
const actor = await getActor(name);
did = actor.did;
if (actor.displayName !== undefined) {
name = actor.displayName;
} else {
name = actor.handle;
}
} else {
// return new Response("Unable to resolve handle", {
// headers: { "content-type": "text/plain" },
// });
const feedGeneratorResponse = await agent.api.app.bsky.feed
.getFeedGenerator({
feed: name,
});

name = feedGeneratorResponse.data.view.displayName;
}

if (!pathname.startsWith("/did:plc:")) {
if (!pathname.startsWith("/did:plc:") && !pathname.startsWith("/at://")) {
return Response.redirect(origin + "/" + did + search);
}

const response = await agent.api.app.bsky.feed.getAuthorFeed({
actor: did,
});
let response;
if (feedid.startsWith("at://")) {
response = await agent.api.app.bsky.feed.getFeed({
feed: feedid,
});
} else {
response = await agent.api.app.bsky.feed.getAuthorFeed({
actor: did,
});
}

if (!response?.data?.feed) {
return new Response("Unable to get posts", {
headers: { "content-type": "text/plain" },
});
}

const authorFeed: AtoprotoAPI.AppBskyFeedDefs.FeedViewPost[] =
response.data.feed;

Expand Down Expand Up @@ -452,20 +478,20 @@ Deno.serve(async (request: Request) => {
},
tag(
"channel",
tag("title", `Bluestream (${handle})`),
tag("title", `Bluestream (${name})`),
`<atom:link href="${
sanitize(origin + "/" + did + search)
}" rel="self" type="application/rss+xml" />`,
tag("link", `https://bsky.app/profile/${did}`),
tag("description", `${handle}'s posts in ${BLUESKY_SERVICE}`),
tag("description", `Posts from ${name} in ${BLUESKY_SERVICE}`),
AppBskyFeedDefs.isPostView(firstPost) &&
AppBskyFeedPost.isRecord(firstPost.record)
? tag("lastBuildDate", toUTCString(firstPost.record.createdAt))
: "",
...feeds.map(({ post, reason, reply }) =>
tag(
"item",
tag("title", genTitle({ did, handle }, { post, reason, reply })),
tag("title", genTitle(post.author, { post, reason, reply })),
tag(
"description",
...genMainContent(
Expand Down

0 comments on commit 04aa34b

Please sign in to comment.