[READ ONLY MIRROR] Spark Social AppView Server
github.com/sprksocial/server
atproto
deno
hono
lexicon
1import { AtUri } from "@atp/syntax";
2import { ids } from "../lex/lexicons.ts";
3import {
4 Main as StrongRef,
5 validateMain as validateStrongRef,
6} from "../lex/types/com/atproto/repo/strongRef.ts";
7
8/**
9 * Convert a post URI to a threadgate URI. If the URI is not a valid
10 * post URI, return URI unchanged. Threadgate lookups will then fail.
11 * Threadgates aren't implemented yet but will be in the future.
12 */
13export function postUriToThreadgateUri(postUri: string) {
14 const urip = new AtUri(postUri);
15 if (urip.collection === ids.AppBskyFeedPost) {
16 urip.collection = ids.AppBskyFeedThreadgate;
17 }
18 return urip.toString();
19}
20
21/**
22 * Convert a post URI to a postgate URI. If the URI is not a valid
23 * post URI, return URI unchanged. Postgate lookups will then fail.
24 * Postgates aren't implemented yet but will be in the future.
25 */
26export function postUriToPostgateUri(postUri: string) {
27 const urip = new AtUri(postUri);
28 if (urip.collection === ids.AppBskyFeedPost) {
29 urip.collection = ids.AppBskyFeedPostgate;
30 }
31 return urip.toString();
32}
33
34export function uriToDid(uri: string) {
35 return new AtUri(uri).hostname;
36}
37
38// @TODO temp fix for proliferation of invalid pinned post values
39export function safePinnedPost(value: unknown) {
40 if (!value || typeof value !== "object") {
41 return;
42 }
43 const validated = validateStrongRef(value);
44 if (!validated.success) {
45 return;
46 }
47 return validated.value as StrongRef;
48}