This repository was archived by the owner on Apr 11, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-json.ts
More file actions
61 lines (50 loc) · 1.75 KB
/
update-json.ts
File metadata and controls
61 lines (50 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import type { UpdateJSON, Version } from '@zotero-plugin-registry/shared'
import { fetchData } from '../utils/http.ts'
/**
* Fetch and parse update.json from remote URL
* @param url The update.json URL
* @param pluginId The plugin ID to extract from the response
* @returns Array of Version objects
* @throws Error if fetch fails or format is invalid
*/
export async function loadUpdateJson(
url: string,
pluginId: string,
): Promise<Version[]> {
const data = await fetchData<UpdateJSON>(url, 'json')
const addonData = data.addons?.[pluginId]
if (!addonData) {
throw new Error(`Plugin ID "${pluginId}" not found in update.json`)
}
if (!Array.isArray(addonData.updates) || addonData.updates.length === 0) {
throw new Error(`Invalid or missing "updates" array for plugin ${pluginId}`)
}
const versions: Version[] = []
for (const u of addonData.updates) {
const { version, update_link, update_hash = '' } = u
if (!version) {
throw new Error(`Missing "version" in update.json for plugin ${pluginId}`)
}
if (!update_link) {
throw new Error(`Missing "update_link" for version ${version} in plugin ${pluginId}`)
}
const strict_min_version = u.applications.zotero
? u.applications.zotero.strict_min_version || '*'
: u.applications.gecko
? (u.applications.gecko.strict_min_version ?? '60.0')
: '*'
const strict_max_version = u.applications.zotero
? u.applications.zotero.strict_max_version || '*'
: u.applications.gecko
? (u.applications.gecko.strict_max_version ?? '60.999')
: '*'
versions.push({
version,
update_link,
update_hash: update_hash || undefined,
strict_min_version,
strict_max_version,
})
}
return versions
}