tangled
alpha
login
or
join now
nekomimi.pet
/
atproto-ui
41
fork
atom
A React component library for rendering common AT Protocol records for applications such as Bluesky and Leaflet.
41
fork
atom
overview
issues
2
pulls
pipelines
forgot file, version bump
waveringana
5 months ago
205ad535
4da3eedd
+38
-1
2 changed files
expand all
collapse all
unified
split
lib
utils
blob.ts
package.json
+37
lib/utils/blob.ts
reviewed
···
1
1
+
import type { BlobWithCdn } from "../hooks/useBlueskyAppview";
2
2
+
3
3
+
/**
4
4
+
* Type guard to check if a blob has a CDN URL from appview.
5
5
+
*/
6
6
+
export function isBlobWithCdn(value: unknown): value is BlobWithCdn {
7
7
+
if (typeof value !== "object" || value === null) return false;
8
8
+
const obj = value as Record<string, unknown>;
9
9
+
return (
10
10
+
obj.$type === "blob" &&
11
11
+
typeof obj.cdnUrl === "string" &&
12
12
+
typeof obj.ref === "object" &&
13
13
+
obj.ref !== null &&
14
14
+
typeof (obj.ref as { $link?: unknown }).$link === "string"
15
15
+
);
16
16
+
}
17
17
+
18
18
+
/**
19
19
+
* Extracts CID from a blob reference object.
20
20
+
* Works with both legacy and modern blob formats.
21
21
+
*/
22
22
+
export function extractCidFromBlob(blob: unknown): string | undefined {
23
23
+
if (typeof blob !== "object" || blob === null) return undefined;
24
24
+
25
25
+
const blobObj = blob as {
26
26
+
ref?: { $link?: string };
27
27
+
cid?: string;
28
28
+
};
29
29
+
30
30
+
if (typeof blobObj.cid === "string") return blobObj.cid;
31
31
+
if (typeof blobObj.ref === "object" && blobObj.ref !== null) {
32
32
+
const link = blobObj.ref.$link;
33
33
+
if (typeof link === "string") return link;
34
34
+
}
35
35
+
36
36
+
return undefined;
37
37
+
}
+1
-1
package.json
reviewed
···
1
1
{
2
2
"name": "atproto-ui",
3
3
-
"version": "0.4.0",
3
3
+
"version": "0.5.0",
4
4
"type": "module",
5
5
"description": "React components and hooks for rendering AT Protocol records.",
6
6
"main": "./lib-dist/index.js",