更新 API 端点
复制包含安装步骤和该插件完整 Markdown 指南的配置 prompt。
以下是使用 JavaScript 调用 code 向插件发送更新的示例
interface AppInfos { version_name: string version_build: string version_os: string custom_id?: string is_prod?: boolean is_emulator?: boolean plugin_version: string platform: string app_id: string device_id: string}
export const handler: Handler = async (event) => { const body = JSON.parse(event.body || '{}') as AppInfos const { platform, app_id, version_os, device_id, version_name, version_build, plugin_version, } = body console.log('update asked', platform, app_id, version_os, device_id, version_name, version_build, plugin_version) if (version_name === '1.0.0') { return { version: '1.0.1', url: 'https://apiurl.com/mybuild_101.zip', checksum: 'sha256_checksum_of_bundle', } } else if (version_name === '1.0.1') { return { version: '1.0.2', url: 'https://apiurl.com/mybuild_102.zip', checksum: 'sha256_checksum_of_bundle', } } else { return { message: 'Error version not found' version: '', url: '', } }}响应格式
“响应格式”章节对于 未加密的 bundle,你的端点应返回:
{ "version": "1.0.2", "url": "https://apiurl.com/mybuild_102.zip", "checksum": "sha256_checksum_of_bundle"}对于 已加密的 bundle,你还需要包含会话密钥:
{ "version": "1.0.2", "url": "https://apiurl.com/mybuild_102.zip", "checksum": "encrypted_checksum_from_encrypt_command", "session_key": "ivSessionKey_from_encrypt_command"}如果没有更新或错误,请添加 message 键,并可选择添加 error:
{ "message": "Version not found", "error": "The backend crashed", "version": "1.0.2",}字段说明
标题为“字段说明”的部分checksum: 用于完整性校验的 bundle zip 文件 SHA256 哈希值session_key: 仅加密 bundle 时必填 - 这是由ivSessionKeyencrypt 命令返回的值version: 使用 semver 格式的版本标识符url: 可下载 bundle 的 HTTPS URL
Bundle 创建
标题为“Bundle 创建”的章节欲了解如何创建兼容的 bundle 并生成校验和,请参阅 Auto Update 文档.
有关加密 bundle,请参阅 Encrypted Bundles 文档 该文档详细介绍了完整的加密工作流。
继续阅读 Update API Endpoint
标题为“继续阅读 Update API Endpoint”的章节如果你正在使用 更新 API 端点 规划 CI/CD 自动化,并将其与 使用 @capgo/capacitor-updater 用于“使用 @capgo/capacitor-updater”中的原生能力, Capgo CI/CD 用于 Capgo CI/CD 中的产品工作流, Capgo Native Build 用于 Capgo Native Builds 中的产品工作流, Capgo 集成 了解 Capgo Integrations 中的产品工作流,以及 CI/CD 集成 CI/CD Integration 中的实现细节。