更新API端点
复制一个包含安装步骤和此插件的完整 Markdown 指南的设置提示。
以下是 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: '', } }}响应格式
标题为“响应格式”对于 非加密包您的端点应返回:
{ "version": "1.0.2", "url": "https://apiurl.com/mybuild_102.zip", "checksum": "sha256_checksum_of_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:捆绑包 zip 文件的 SHA256 散列值,用于完整性验证session_key:仅加密捆绑包需要 - 这是ivSessionKey由加密命令返回的内容version: 版本标识符 : semver 格式url: 可以下载包的 HTTPS URL
包创建
关于包创建的部分要了解如何创建兼容包并生成校验和,请参阅 关于自动更新的文档.
对于加密包,请参阅 加密包文档 它解释了加密工作流程的全部内容。
继续从更新 API 端点
Keep going from Update API Endpoint如果您正在使用 Update API Endpoint 来规划CI/CD自动化,连接它与 使用@capgo/capacitor-updater 为native能力在使用@capgo/capacitor-updater Capgo CI/CD 为产品工作流程在Capgo CI/CD Capgo Native Builds 为产品工作流程在Capgo Native Builds Capgo Integrations 为产品工作流程在Capgo Integrations, CI/CD 集成 CI/CD 集成的实现细节。