@estiva-app/protocol 0.42.0 → 0.44.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/CHANGELOG.md +41 -0
- package/dist/bridge-content.d.ts +5 -0
- package/dist/bridge-content.d.ts.map +1 -1
- package/dist/bridge-content.js +9 -9
- package/dist/bridge-content.js.map +1 -1
- package/dist/content.d.ts +31 -7
- package/dist/content.d.ts.map +1 -1
- package/dist/content.js +128 -7
- package/dist/content.js.map +1 -1
- package/dist/description-text.d.ts.map +1 -1
- package/dist/description-text.js +5 -7
- package/dist/description-text.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/media.d.ts +16 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +40 -26
- package/dist/media.js.map +1 -1
- package/package.json +1 -1
- package/src/bridge-content.ts +15 -10
- package/src/content.ts +127 -11
- package/src/description-text.ts +4 -6
- package/src/index.ts +1 -1
- package/src/media.ts +54 -20
package/src/media.ts
CHANGED
|
@@ -118,8 +118,35 @@ export interface Imeta {
|
|
|
118
118
|
thumb?: string
|
|
119
119
|
/** The name a person gave it. Display only — storage is content-addressed. */
|
|
120
120
|
filename?: string
|
|
121
|
+
/*
|
|
122
|
+
The rest of the relay's allowlist. No Estiva app writes these yet, but
|
|
123
|
+
Buzz desktop does (blurhash, duration), and an edit re-lists a message's
|
|
124
|
+
files (SPEC §6.8): a field this did not read back is one an edit would
|
|
125
|
+
silently strip. Kept as the strings the tag held, so a re-listed file is
|
|
126
|
+
the file it was.
|
|
127
|
+
*/
|
|
128
|
+
/** NIP-94 blurhash placeholder. */
|
|
129
|
+
blurhash?: string
|
|
130
|
+
/** Seconds, for audio and video. The relay checks it against the stored blob. */
|
|
131
|
+
duration?: string
|
|
132
|
+
/** Bits per second, for audio and video. */
|
|
133
|
+
bitrate?: string
|
|
134
|
+
/** A poster frame's `/media/` path; the relay checks that blob too. */
|
|
135
|
+
image?: string
|
|
136
|
+
/**
|
|
137
|
+
* Other places the same blob can be fetched from — the one key that may
|
|
138
|
+
* repeat (NIP-94). **Unchecked**: the relay accepts any scheme and host here,
|
|
139
|
+
* so it is carried through on a re-list and never used as an `href` or `src`
|
|
140
|
+
* without an https and host check.
|
|
141
|
+
*/
|
|
142
|
+
fallback?: string[]
|
|
121
143
|
}
|
|
122
144
|
|
|
145
|
+
/** The optional {@link Imeta} fields, in the order {@link imetaTag} writes them. */
|
|
146
|
+
const OPTIONAL_FIELDS = ['dim', 'blurhash', 'alt', 'thumb', 'fallback', 'duration', 'bitrate', 'image', 'filename'] as const
|
|
147
|
+
/** The ones {@link imetaOf} adds only when present, so a file without them reads as it always did. */
|
|
148
|
+
const ADDED_FIELDS = ['blurhash', 'duration', 'bitrate', 'image'] as const
|
|
149
|
+
|
|
123
150
|
/**
|
|
124
151
|
* One `imeta` tag — NIP-92, as Buzz validates it.
|
|
125
152
|
*
|
|
@@ -127,7 +154,7 @@ export interface Imeta {
|
|
|
127
154
|
* inside a single tag, not one tag per field.
|
|
128
155
|
*
|
|
129
156
|
* The relay's allowlist is `url m x size dim blurhash alt thumb fallback
|
|
130
|
-
* duration bitrate image filename`, each at most once
|
|
157
|
+
* duration bitrate image filename`, each at most once but `fallback`, and it checks two things
|
|
131
158
|
* this cannot: that `url` is a **local** `/media/` path, and — through
|
|
132
159
|
* `verify_imeta_blobs` — that **the blob is already stored**. So the upload has
|
|
133
160
|
* to land before the message that names it, and a dangling reference cannot be
|
|
@@ -135,10 +162,9 @@ export interface Imeta {
|
|
|
135
162
|
*/
|
|
136
163
|
export function imetaTag(meta: Imeta): NostrTag {
|
|
137
164
|
const parts = [`url ${meta.url}`, `m ${meta.m}`, `x ${meta.x}`, `size ${meta.size}`]
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (meta.filename) parts.push(`filename ${meta.filename}`)
|
|
165
|
+
for (const key of OPTIONAL_FIELDS) {
|
|
166
|
+
for (const value of [meta[key]].flat()) if (value) parts.push(`${key} ${value}`)
|
|
167
|
+
}
|
|
142
168
|
return ['imeta', ...parts]
|
|
143
169
|
}
|
|
144
170
|
|
|
@@ -155,17 +181,20 @@ export function imetaOf(event: { tags: NostrTag[] }): Imeta[] {
|
|
|
155
181
|
for (const tag of event.tags) {
|
|
156
182
|
if (tag[0] !== 'imeta') continue
|
|
157
183
|
const fields: Record<string, string> = {}
|
|
184
|
+
const fallback: string[] = []
|
|
158
185
|
for (const part of tag.slice(1)) {
|
|
159
186
|
const space = part.indexOf(' ')
|
|
160
187
|
if (space <= 0) continue
|
|
161
188
|
const key = part.slice(0, space)
|
|
162
|
-
|
|
163
|
-
//
|
|
164
|
-
|
|
189
|
+
const value = part.slice(space + 1)
|
|
190
|
+
// First wins: the relay rejects duplicates of every key but `fallback`,
|
|
191
|
+
// so a second is a malformed event rather than an override.
|
|
192
|
+
if (key === 'fallback') fallback.push(value)
|
|
193
|
+
else if (!(key in fields)) fields[key] = value
|
|
165
194
|
}
|
|
166
195
|
const size = Number.parseInt(fields.size ?? '', 10)
|
|
167
196
|
if (!fields.url || !fields.m || !fields.x || !Number.isFinite(size)) continue
|
|
168
|
-
|
|
197
|
+
const meta: Imeta = {
|
|
169
198
|
url: fields.url,
|
|
170
199
|
m: fields.m,
|
|
171
200
|
x: fields.x,
|
|
@@ -174,7 +203,10 @@ export function imetaOf(event: { tags: NostrTag[] }): Imeta[] {
|
|
|
174
203
|
alt: fields.alt,
|
|
175
204
|
thumb: fields.thumb,
|
|
176
205
|
filename: fields.filename,
|
|
177
|
-
}
|
|
206
|
+
}
|
|
207
|
+
for (const key of ADDED_FIELDS) if (fields[key]) meta[key] = fields[key]
|
|
208
|
+
if (fallback.length) meta.fallback = fallback
|
|
209
|
+
out.push(meta)
|
|
178
210
|
}
|
|
179
211
|
return out
|
|
180
212
|
}
|
|
@@ -189,21 +221,23 @@ export function imetaOf(event: { tags: NostrTag[] }): Imeta[] {
|
|
|
189
221
|
*/
|
|
190
222
|
export function imetaFromAttrs(attrs: Record<string, unknown> | undefined): Imeta | undefined {
|
|
191
223
|
if (!attrs) return undefined
|
|
192
|
-
const { url, m, x, size
|
|
224
|
+
const { url, m, x, size } = attrs
|
|
193
225
|
if (typeof url !== 'string' || !url) return undefined
|
|
194
226
|
if (typeof m !== 'string' || !m) return undefined
|
|
195
227
|
if (typeof x !== 'string' || !x) return undefined
|
|
196
228
|
if (typeof size !== 'number' || !Number.isFinite(size)) return undefined
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
229
|
+
const meta: Imeta = { url, m, x, size }
|
|
230
|
+
/*
|
|
231
|
+
Only the fields the editor's attachment block holds. A description is
|
|
232
|
+
re-saved under whoever saves it, and attrs nothing in the editor wrote
|
|
233
|
+
(a hand-published `fallback` URL, an `image` not stored) would become
|
|
234
|
+
their signed tag, or a save the relay refuses.
|
|
235
|
+
*/
|
|
236
|
+
for (const key of ['dim', 'thumb', 'alt', 'filename'] as const) {
|
|
237
|
+
const value = attrs[key]
|
|
238
|
+
if (typeof value === 'string' && value) meta[key] = value
|
|
206
239
|
}
|
|
240
|
+
return meta
|
|
207
241
|
}
|
|
208
242
|
|
|
209
243
|
/**
|