applesauce-core 0.0.0-next-20250211165042 → 0.0.0-next-20250211182348
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers/blossom.d.ts +9 -0
- package/dist/helpers/blossom.js +22 -0
- package/dist/helpers/blossom.test.d.ts +1 -0
- package/dist/helpers/blossom.test.js +13 -0
- package/dist/helpers/file-metadata.d.ts +1 -1
- package/dist/helpers/file-metadata.js +1 -1
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +1 -0
- package/dist/helpers/url.js +2 -3
- package/dist/queries/blossom.d.ts +2 -0
- package/dist/queries/blossom.js +10 -0
- package/dist/queries/index.d.ts +1 -0
- package/dist/queries/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const BLOSSOM_SERVER_LIST_KIND = 10063;
|
|
2
|
+
/** Check if two servers are the same */
|
|
3
|
+
export declare function areBlossomServersEqual(a: string | URL, b: string | URL): boolean;
|
|
4
|
+
/** Checks if a string is a sha256 hash */
|
|
5
|
+
export declare function isSha256(str: string): boolean;
|
|
6
|
+
/** Returns an ordered array of servers found in a server list event (10063) */
|
|
7
|
+
export declare function getBlossomServersFromList(event: {
|
|
8
|
+
tags: string[][];
|
|
9
|
+
} | string[][]): URL[];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isNameValueTag, processTags } from "./tags.js";
|
|
2
|
+
export const BLOSSOM_SERVER_LIST_KIND = 10063;
|
|
3
|
+
/** Check if two servers are the same */
|
|
4
|
+
export function areBlossomServersEqual(a, b) {
|
|
5
|
+
const hostnameA = new URL("/", a).toString();
|
|
6
|
+
const hostnameB = new URL("/", b).toString();
|
|
7
|
+
return hostnameA === hostnameB;
|
|
8
|
+
}
|
|
9
|
+
/** Checks if a string is a sha256 hash */
|
|
10
|
+
export function isSha256(str) {
|
|
11
|
+
return !!str.match(/^[0-9a-f]{64}$/);
|
|
12
|
+
}
|
|
13
|
+
/** Returns an ordered array of servers found in a server list event (10063) */
|
|
14
|
+
export function getBlossomServersFromList(event) {
|
|
15
|
+
const tags = Array.isArray(event) ? event : event.tags;
|
|
16
|
+
return processTags(tags, (tag) => {
|
|
17
|
+
if (isNameValueTag(tag, "server") && URL.canParse(tag[1]))
|
|
18
|
+
return new URL("/", tag[1]);
|
|
19
|
+
else
|
|
20
|
+
return undefined;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { areBlossomServersEqual } from "./blossom.js";
|
|
3
|
+
describe("areBlossomServersEqual", () => {
|
|
4
|
+
it("should ignore path", () => {
|
|
5
|
+
expect(areBlossomServersEqual("https://cdn.server.com/pathname", "https://cdn.server.com")).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
it("should not ignore protocol", () => {
|
|
8
|
+
expect(areBlossomServersEqual("http://cdn.server.com", "https://cdn.server.com")).toBe(false);
|
|
9
|
+
});
|
|
10
|
+
it("should not ignore port", () => {
|
|
11
|
+
expect(areBlossomServersEqual("http://cdn.server.com:4658", "https://cdn.server.com")).toBe(false);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -52,4 +52,4 @@ export declare function getMediaAttachments(event: NostrEvent): FileMetadata[];
|
|
|
52
52
|
*/
|
|
53
53
|
export declare function getFileMetadata(file: NostrEvent): FileMetadata;
|
|
54
54
|
/** Returns the last 64 length hex string in a URL */
|
|
55
|
-
export declare function getSha256FromURL(url: string | URL): string |
|
|
55
|
+
export declare function getSha256FromURL(url: string | URL): string | undefined;
|
package/dist/helpers/index.d.ts
CHANGED
package/dist/helpers/index.js
CHANGED
package/dist/helpers/url.js
CHANGED
|
@@ -44,13 +44,12 @@ export function isSameURL(a, b) {
|
|
|
44
44
|
* Does not remove the trailing slash
|
|
45
45
|
*/
|
|
46
46
|
export function normalizeURL(url) {
|
|
47
|
-
if (typeof url === "string" && url.indexOf("://") === -1)
|
|
48
|
-
url = "wss://" + url;
|
|
49
47
|
let p = new URL(url);
|
|
50
48
|
// remove any double slashes
|
|
51
49
|
p.pathname = p.pathname.replace(/\/+/g, "/");
|
|
52
50
|
// drop the port if its not needed
|
|
53
|
-
if ((p.port === "80" && p.protocol === "ws:"
|
|
51
|
+
if ((p.port === "80" && (p.protocol === "ws:" || p.protocol === "http:")) ||
|
|
52
|
+
(p.port === "443" && (p.protocol === "wss:" || p.protocol === "https:")))
|
|
54
53
|
p.port = "";
|
|
55
54
|
// sort the query params
|
|
56
55
|
p.searchParams.sort();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { map } from "rxjs/operators";
|
|
2
|
+
import { BLOSSOM_SERVER_LIST_KIND, getBlossomServersFromList } from "../helpers/blossom.js";
|
|
3
|
+
export function UserBlossomServersQuery(pubkey) {
|
|
4
|
+
return {
|
|
5
|
+
key: pubkey,
|
|
6
|
+
run: (store) => store
|
|
7
|
+
.replaceable(BLOSSOM_SERVER_LIST_KIND, pubkey)
|
|
8
|
+
.pipe(map((event) => event && getBlossomServersFromList(event))),
|
|
9
|
+
};
|
|
10
|
+
}
|
package/dist/queries/index.d.ts
CHANGED
package/dist/queries/index.js
CHANGED