mirror of
https://github.com/iflytek/skillhub.git
synced 2026-11-21 10:17:34 +00:00
Some checks failed
Deploy Docs / build (push) Has been cancelled
Security / Dependency Review (push) Has been cancelled
Security / CodeQL (java-kotlin) (push) Has been cancelled
Security / CodeQL (javascript-typescript) (push) Has been cancelled
Security / CodeQL (python) (push) Has been cancelled
Deploy Docs / Deploy (push) Has been cancelled
Add the native SkillHub plugin for DeepSeek Harness with a scoped skill center, conversation search/install tools, exact-version installation and protected lifecycle management. Prepare the independently versioned 0.1.0 npm candidate with an empty default Registry and documented compatibility limits. Keep formal specifications and executable regression tests; remove archived development screenshots and runtime reports from the final tree. Review fixes cover independent scopes, installed references, pre-staging recovery and idempotent discovery. Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { EXIT } from '../shared/constants.js'
|
|
import { CliError } from '../shared/errors.js'
|
|
|
|
export const MAX_PACKAGE_BYTES = 100 * 1024 * 1024
|
|
|
|
export async function readBoundedResponseBody(response: Response, maxBytes = MAX_PACKAGE_BYTES): Promise<ArrayBuffer> {
|
|
const contentLength = response.headers.get('content-length')
|
|
if (contentLength !== null) {
|
|
const declaredLength = Number(contentLength)
|
|
if (Number.isFinite(declaredLength) && declaredLength > maxBytes) {
|
|
throw new CliError('download exceeds maximum package size', EXIT.network, {
|
|
contentLength: declaredLength,
|
|
maxBytes
|
|
})
|
|
}
|
|
}
|
|
|
|
if (!response.body) {
|
|
const buffer = await response.arrayBuffer()
|
|
if (buffer.byteLength > maxBytes) {
|
|
throw new CliError('download exceeds maximum package size', EXIT.network, {
|
|
receivedBytes: buffer.byteLength,
|
|
maxBytes
|
|
})
|
|
}
|
|
return buffer
|
|
}
|
|
|
|
const reader = response.body.getReader()
|
|
const chunks: Uint8Array[] = []
|
|
let receivedBytes = 0
|
|
|
|
for (;;) {
|
|
const { done, value } = await reader.read()
|
|
if (done) {
|
|
break
|
|
}
|
|
receivedBytes += value.byteLength
|
|
if (receivedBytes > maxBytes) {
|
|
await reader.cancel()
|
|
throw new CliError('download exceeds maximum package size', EXIT.network, {
|
|
receivedBytes,
|
|
maxBytes
|
|
})
|
|
}
|
|
chunks.push(value)
|
|
}
|
|
|
|
const result = new Uint8Array(receivedBytes)
|
|
let offset = 0
|
|
for (const chunk of chunks) {
|
|
result.set(chunk, offset)
|
|
offset += chunk.byteLength
|
|
}
|
|
return result.buffer
|
|
}
|