@sockethub/platform-metadata 1.0.1-alpha.9 → 1.0.1-beta.1
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/README.md +72 -4
- package/dist/index.d.ts +55 -0
- package/dist/index.js +6657 -3355
- package/dist/index.js.map +66 -62
- package/dist/resolvers.d.ts +231 -0
- package/dist/schema.d.ts +25 -0
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -77,9 +77,72 @@ The platform returns an ActivityStream object with extracted metadata:
|
|
|
77
77
|
The platform extracts the following metadata when available:
|
|
78
78
|
|
|
79
79
|
* **Open Graph data**: Title, description, images, site name, URL, locale
|
|
80
|
-
* **Site information**: Favicon, character encoding
|
|
80
|
+
* **Site information**: Favicon, character encoding — when a page declares no
|
|
81
|
+
icon, `favicon` falls back to the conventional relative `/favicon.ico` so
|
|
82
|
+
clients can resolve it against the page URL and decorate previews
|
|
81
83
|
* **Canonical URLs**: Resolved and canonical page URLs
|
|
82
|
-
* **Media**: Images with dimensions and type information
|
|
84
|
+
* **Media**: Images with dimensions and type information; for X/Twitter posts,
|
|
85
|
+
a `video` object (direct media URL, poster `thumbnail`, dimensions, duration)
|
|
86
|
+
|
|
87
|
+
## Site-Specific Handling
|
|
88
|
+
|
|
89
|
+
Some large platforms don't expose a post's own media to Open Graph scrapers,
|
|
90
|
+
so those URLs are resolved through preview services built for this purpose:
|
|
91
|
+
|
|
92
|
+
* **X / Twitter status URLs** (`x.com`, `twitter.com`, incl. `/i/web/status/…`)
|
|
93
|
+
are fetched from the [FxTwitter API](https://github.com/FxEmbed/FxEmbed)
|
|
94
|
+
instead of scraped — X serves only a generic site banner to scrapers. The
|
|
95
|
+
response carries the post's text, its actual photo (or video + poster
|
|
96
|
+
thumbnail), and the canonical `x.com` URL. If the API is unavailable or the
|
|
97
|
+
post can't be resolved, the platform falls back to the regular scrape
|
|
98
|
+
(which still yields the post text).
|
|
99
|
+
* **Reddit post URLs** use `old.reddit.com`'s structured JSON response, avoiding
|
|
100
|
+
Reddit's unreliable HTML and Open Graph crawler behavior. The post title,
|
|
101
|
+
self-text, and direct `i.redd.it` image are mapped into the preview; text posts
|
|
102
|
+
intentionally have no image. oEmbed remains a title-only failure fallback.
|
|
103
|
+
See `compatUserAgent` below.
|
|
104
|
+
* **Facebook** remains best-effort: post text usually comes through. The
|
|
105
|
+
video or photo thumbnail is taken from the post's Open Graph image, then
|
|
106
|
+
its Twitter card image, and finally the image rendered by Facebook's public
|
|
107
|
+
embed plugin (`/plugins/video.php` or `/plugins/post.php`), which Facebook
|
|
108
|
+
serves to third parties when it withholds Open Graph media from a
|
|
109
|
+
datacenter address. Full media still requires authentication.
|
|
110
|
+
|
|
111
|
+
### `userAgent`
|
|
112
|
+
|
|
113
|
+
All outbound requests identify as
|
|
114
|
+
`Mozilla/5.0 (compatible; SockethubBot/<version>; +https://sockethub.org)`.
|
|
115
|
+
Sites gate scraper-facing behavior on the user agent — preview services serve
|
|
116
|
+
their Open Graph payload to bot-like UAs, and many hosts reject undici's
|
|
117
|
+
default UA. Override per deployment via `packageConfig`:
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"packageConfig": {
|
|
122
|
+
"@sockethub/platform-metadata": {
|
|
123
|
+
"userAgent": "MyDeployment/1.0 (+https://my.example)"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### `compatUserAgent`
|
|
130
|
+
|
|
131
|
+
Sites that only serve metadata to *recognized* embed crawlers (Reddit)
|
|
132
|
+
are fetched with a link-preview crawler user agent instead — the established
|
|
133
|
+
practice for self-hosted preview fetchers. Defaults to
|
|
134
|
+
`Mozilla/5.0 (compatible; Discordbot/2.0; +https://discordapp.com)`;
|
|
135
|
+
override via `packageConfig`:
|
|
136
|
+
|
|
137
|
+
```json
|
|
138
|
+
{
|
|
139
|
+
"packageConfig": {
|
|
140
|
+
"@sockethub/platform-metadata": {
|
|
141
|
+
"compatUserAgent": "Mozilla/5.0 (compatible; TelegramBot/1.0)"
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
83
146
|
|
|
84
147
|
## Dependencies
|
|
85
148
|
|
|
@@ -92,9 +155,14 @@ Because the server fetches whatever URL a client supplies as `actor.id`, metadat
|
|
|
92
155
|
requests are hardened against server-side request forgery (SSRF) and resource
|
|
93
156
|
exhaustion. The fetch runs through a guarded connection layer that:
|
|
94
157
|
|
|
158
|
+
* rejects URL schemes other than `http` and `https`;
|
|
95
159
|
* refuses to connect to loopback, private, link-local, carrier-grade NAT, or
|
|
96
|
-
cloud-metadata addresses (e.g. `169.254.169.254`),
|
|
97
|
-
|
|
160
|
+
cloud-metadata addresses (e.g. `169.254.169.254`), validated at connection
|
|
161
|
+
time so it also covers redirect hops. IPv4-mapped, IPv4-compatible, and
|
|
162
|
+
well-known NAT64 (`64:ff9b::/96`) embeddings are judged as the embedded IPv4
|
|
163
|
+
address. The local-use NAT64 prefix `64:ff9b:1::/48` is refused entirely.
|
|
164
|
+
The ranges are listed under
|
|
165
|
+
[Outbound URL guard](../../docs/configuration.md#outbound-url-guard);
|
|
98
166
|
* caps the response body size.
|
|
99
167
|
|
|
100
168
|
### `allowPrivateAddresses`
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { ActivityStream, PlatformCallback, PlatformConfig, PlatformInterface, PlatformSession } from "@sockethub/schemas";
|
|
2
|
+
/** Enforce a deadline independently of a dependency's AbortSignal handling. */
|
|
3
|
+
export declare function withDeadline<T>(promise: Promise<T>, timeoutMs: number): Promise<T>;
|
|
2
4
|
export default class Metadata implements PlatformInterface {
|
|
3
5
|
private readonly log;
|
|
6
|
+
private readonly fetchImpl;
|
|
4
7
|
private dispatcher?;
|
|
5
8
|
config: PlatformConfig;
|
|
6
9
|
constructor(session: PlatformSession);
|
|
@@ -88,6 +91,28 @@ export default class Metadata implements PlatformInterface {
|
|
|
88
91
|
image: {
|
|
89
92
|
$ref: string;
|
|
90
93
|
};
|
|
94
|
+
video: {
|
|
95
|
+
type: string;
|
|
96
|
+
required: string[];
|
|
97
|
+
additionalProperties: boolean;
|
|
98
|
+
properties: {
|
|
99
|
+
url: {
|
|
100
|
+
type: string;
|
|
101
|
+
};
|
|
102
|
+
thumbnail: {
|
|
103
|
+
type: string;
|
|
104
|
+
};
|
|
105
|
+
width: {
|
|
106
|
+
type: string;
|
|
107
|
+
};
|
|
108
|
+
height: {
|
|
109
|
+
type: string;
|
|
110
|
+
};
|
|
111
|
+
duration: {
|
|
112
|
+
type: string;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
};
|
|
91
116
|
url: {
|
|
92
117
|
type: string;
|
|
93
118
|
};
|
|
@@ -118,6 +143,9 @@ export default class Metadata implements PlatformInterface {
|
|
|
118
143
|
height: {
|
|
119
144
|
type: string[];
|
|
120
145
|
};
|
|
146
|
+
alt: {
|
|
147
|
+
type: string;
|
|
148
|
+
};
|
|
121
149
|
};
|
|
122
150
|
};
|
|
123
151
|
};
|
|
@@ -129,6 +157,33 @@ export default class Metadata implements PlatformInterface {
|
|
|
129
157
|
* Stateless platforms are always ready to handle jobs.
|
|
130
158
|
*/
|
|
131
159
|
isInitialized(): boolean;
|
|
160
|
+
private userAgent;
|
|
161
|
+
private compatUserAgent;
|
|
132
162
|
fetch(job: ActivityStream, cb: PlatformCallback): void;
|
|
163
|
+
/**
|
|
164
|
+
* Verify likely direct-image links when possible. Origins commonly block
|
|
165
|
+
* server-side preview agents, so a strong file extension remains a useful
|
|
166
|
+
* fallback: the client can still request the original resource itself.
|
|
167
|
+
*/
|
|
168
|
+
private fetchDirectImage;
|
|
169
|
+
/** Fetch and validate YouTube's official preview metadata. */
|
|
170
|
+
private fetchYouTubeEmbed;
|
|
171
|
+
/**
|
|
172
|
+
* Last-resort thumbnail for a Facebook post whose page carried no
|
|
173
|
+
* Open Graph image: the media image rendered by Facebook's public embed
|
|
174
|
+
* plugin, which is served to third parties without a login wall.
|
|
175
|
+
*/
|
|
176
|
+
private fetchFacebookEmbedImage;
|
|
177
|
+
private fetchTweet;
|
|
178
|
+
private fetchReddit;
|
|
179
|
+
/**
|
|
180
|
+
* Fetch Reddit's fixed-host JSON endpoint without the Undici dispatcher.
|
|
181
|
+
* The platform child runtime has exhibited stuck Undici requests even when
|
|
182
|
+
* AbortSignal fires. node:https gives us an independently enforced socket
|
|
183
|
+
* timeout; the outer withDeadline still guarantees callback completion.
|
|
184
|
+
*/
|
|
185
|
+
private fetchRedditJson;
|
|
186
|
+
private fetchRedditEmbed;
|
|
187
|
+
private scrape;
|
|
133
188
|
cleanup(cb: PlatformCallback): void;
|
|
134
189
|
}
|