From d60e76c974fc15bcf670000df3a7d5ad7009c938 Mon Sep 17 00:00:00 2001 From: qwqcode Date: Tue, 22 Oct 2024 21:12:33 +0800 Subject: [PATCH] fix: add `options_schema` url check --- scripts/build.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/build.ts b/scripts/build.ts index 4b25703..e500df1 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -54,6 +54,12 @@ const downloadFile = async (url: string): Promise => { return Buffer.from(response.data) } +// Request document headers +const requestHead = async (url: string) => { + const response = await axios.head(url) + return response.headers +} + // Function to generate SRI hash const generateSRI = (content: Buffer, algorithm: string = 'sha512'): string => { const hash = crypto.createHash(algorithm).update(content).digest('base64') @@ -141,6 +147,13 @@ const buildRegistryEntry = async ( const integrity = await generateSRIFromURL(source) if (!integrity) return null + let optionsSchema = `${cdnBase}/${path.dirname(mainFile)}/artalk-plugin-options.schema.json` + try { + await requestHead(optionsSchema) + } catch { + optionsSchema = '' // unset if returns 404 + } + distEntry = { ...distEntry, version, @@ -148,7 +161,7 @@ const buildRegistryEntry = async ( integrity, updated_at: npmInfo['time'][version], min_artalk_version: extractMinArtalkClientVersion(npmPkgData), - options_schema: `${cdnBase}/${path.dirname(mainFile)}/artalk-plugin-options.schema.json`, + options_schema: optionsSchema, } }