Skip to content

Commit

Permalink
fix: add options_schema url check
Browse files Browse the repository at this point in the history
  • Loading branch information
qwqcode committed Oct 22, 2024
1 parent c2e2f80 commit d60e76c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ const downloadFile = async (url: string): Promise<Buffer> => {
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')
Expand Down Expand Up @@ -141,14 +147,21 @@ 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,
source,
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,
}
}

Expand Down

0 comments on commit d60e76c

Please sign in to comment.