Skip to content

Commit d60e76c

Browse files
committed
fix: add options_schema url check
1 parent c2e2f80 commit d60e76c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

scripts/build.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ const downloadFile = async (url: string): Promise<Buffer> => {
5454
return Buffer.from(response.data)
5555
}
5656

57+
// Request document headers
58+
const requestHead = async (url: string) => {
59+
const response = await axios.head(url)
60+
return response.headers
61+
}
62+
5763
// Function to generate SRI hash
5864
const generateSRI = (content: Buffer, algorithm: string = 'sha512'): string => {
5965
const hash = crypto.createHash(algorithm).update(content).digest('base64')
@@ -141,14 +147,21 @@ const buildRegistryEntry = async (
141147
const integrity = await generateSRIFromURL(source)
142148
if (!integrity) return null
143149

150+
let optionsSchema = `${cdnBase}/${path.dirname(mainFile)}/artalk-plugin-options.schema.json`
151+
try {
152+
await requestHead(optionsSchema)
153+
} catch {
154+
optionsSchema = '' // unset if returns 404
155+
}
156+
144157
distEntry = {
145158
...distEntry,
146159
version,
147160
source,
148161
integrity,
149162
updated_at: npmInfo['time'][version],
150163
min_artalk_version: extractMinArtalkClientVersion(npmPkgData),
151-
options_schema: `${cdnBase}/${path.dirname(mainFile)}/artalk-plugin-options.schema.json`,
164+
options_schema: optionsSchema,
152165
}
153166
}
154167

0 commit comments

Comments
 (0)