跳过内容

更新API端点

GitHub

以下是 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 可用于下载的捆绑包

要了解如何创建兼容的捆绑包并生成校验和,请参阅 自动更新文档.

有关加密捆绑包的文档,请参阅 该文档解释了加密工作流程的全部内容。 从更新__CAPGO_KEEP_0__终点继续

关于从更新API终点继续的部分

Section titled “Keep going from Update API Endpoint”

If you are using 更新API端点 为CI/CD自动化做好准备,连接它 使用@capgo/capacitor-updater 使用@capgo/capacitor-updater中的本机功能 Capgo CI/CD Capgo CI/CD中的产品工作流 Capgo 本机构建 Capgo 本机构建中的产品工作流 Capgo 集成 Capgo 集成中的产品工作流 CI/CD集成 CI/CD集成中的实现细节