feat: 上架视频剪辑固定材料与作者契约

This commit is contained in:
yige committed 2026-11-02 21:52:36 +08:00
1 parent 9577e9a411
commit eef65008eb
18 files changed
+5658 -198

No files matched your search

+32 -1
View File
@@ -1,7 +1,32 @@
import { isApplicationEntry, isAuthoredRegistryEntry } from './entry-schema.mjs'
/** 发布者关系声明的跨字段检查;不推导安装、权限或运行时健康。 */
export function validateApplicationContract(manifest) {
if (!['docker-app', 'native-app', 'artifact'].includes(manifest.type)) return []
if (!isApplicationEntry(manifest) && !isAuthoredRegistryEntry(manifest)) return []
const errors = []
if (isAuthoredRegistryEntry(manifest)) {
if (!['web-bundle', 'native-app', 'docker-app'].includes(manifest.type)) errors.push('appRelease: unsupported delivery type')
const required = manifest.appRelease?.requiredCapabilities
if (!Array.isArray(required) || !required.includes('release') || (manifest.type === 'web-bundle' && !required.includes('web-bundle'))) {
errors.push('appRelease: delivery capability handshake required')
}
const images = manifest.appRelease?.imageRefs
// 镜像语法由严格 Schema 校验;端口范围属于同一跨字段合同。
if (manifest.type === 'docker-app' && (!Array.isArray(images) || images.length === 0 || images.some(image =>
typeof image !== 'string' || Number(image.split('/')[0].split(':')[1] ?? 0) > 65535))) errors.push('appRelease: Docker images must be pinned by digest')
if (manifest.type !== 'docker-app' && images !== undefined) errors.push('appRelease: imageRefs belongs only to Docker release')
const source = manifest.source
if (!source || !['git', 'release'].includes(source.kind) ||
typeof source.ref !== 'string' || !/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(source.ref) ||
typeof source.sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(source.sha256)) {
errors.push('source: authored release requires immutable commit and archive sha256')
}
try {
const url = new URL(String(source?.url))
if (url.protocol !== 'https:' || url.username || url.password || url.hash || url.search) errors.push('source: credential-free fixed HTTPS URL required')
} catch { errors.push('source: invalid URL') }
if (source?.kind === 'git' && (typeof source.path !== 'string' || !isPortablePath(source.path))) errors.push('source: git archive path must be canonical and relative')
}
const ids = new Set()
for (const entrypoint of Array.isArray(manifest.entrypoints) ? manifest.entrypoints : []) {
if (!entrypoint || typeof entrypoint !== 'object') continue
@@ -18,3 +43,9 @@ export function validateApplicationContract(manifest) {
}
return errors
}
function isPortablePath(value) {
return value.length > 0 && value.length <= 512 &&
!/[\\\x00-\x1f?#:]/.test(value) && !value.startsWith('/') &&
value.split('/').every(part => part.length > 0 && part !== '.' && part !== '..')
}