@sockethub/platform-metadata 1.0.1-alpha.8 → 1.0.1-beta.0

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 CHANGED
@@ -77,9 +77,68 @@ 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, but
105
+ media requires authentication and no public preview service exists.
106
+
107
+ ### `userAgent`
108
+
109
+ All outbound requests identify as
110
+ `Mozilla/5.0 (compatible; SockethubBot/<version>; +https://sockethub.org)`.
111
+ Sites gate scraper-facing behavior on the user agent — preview services serve
112
+ their Open Graph payload to bot-like UAs, and many hosts reject undici's
113
+ default UA. Override per deployment via `packageConfig`:
114
+
115
+ ```json
116
+ {
117
+ "packageConfig": {
118
+ "@sockethub/platform-metadata": {
119
+ "userAgent": "MyDeployment/1.0 (+https://my.example)"
120
+ }
121
+ }
122
+ }
123
+ ```
124
+
125
+ ### `compatUserAgent`
126
+
127
+ Sites that only serve metadata to *recognized* embed crawlers (Reddit)
128
+ are fetched with a link-preview crawler user agent instead — the established
129
+ practice for self-hosted preview fetchers. Defaults to
130
+ `Mozilla/5.0 (compatible; Discordbot/2.0; +https://discordapp.com)`;
131
+ override via `packageConfig`:
132
+
133
+ ```json
134
+ {
135
+ "packageConfig": {
136
+ "@sockethub/platform-metadata": {
137
+ "compatUserAgent": "Mozilla/5.0 (compatible; TelegramBot/1.0)"
138
+ }
139
+ }
140
+ }
141
+ ```
83
142
 
84
143
  ## Dependencies
85
144
 
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,27 @@ 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
+ private fetchTweet;
172
+ private fetchReddit;
173
+ /**
174
+ * Fetch Reddit's fixed-host JSON endpoint without the Undici dispatcher.
175
+ * The platform child runtime has exhibited stuck Undici requests even when
176
+ * AbortSignal fires. node:https gives us an independently enforced socket
177
+ * timeout; the outer withDeadline still guarantees callback completion.
178
+ */
179
+ private fetchRedditJson;
180
+ private fetchRedditEmbed;
181
+ private scrape;
133
182
  cleanup(cb: PlatformCallback): void;
134
183
  }