Skip to content

Bundle

Capgo는 앱의 콘텐츠를 구성하는 웹 자산 (HTML, CSS, JS)가 포함된 코어 업데이트 패키지입니다. API는 이러한 업데이트 패키지를 관리하는 데 사용되는 Bundles입니다. 목록 및 삭제를 포함합니다.

__CAPGO_KEEP_0__는 앱의 콘텐츠를 구성하는 웹 자산 (HTML, CSS, JS)가 포함된 코어 업데이트 패키지입니다. __CAPGO_KEEP_1__는 이러한 업데이트 패키지를 관리하는 데 사용되는 Bundles입니다. 목록 및 삭제를 포함합니다.

  • 버전 (버전): Semantic 버전 번호 버전
  • 체크섬: 버전의 무결성을 확인하기 위한 고유 해시
  • 저장 정보: 버전이 저장되는 위치와 방법에 대한 정보
  • 네이티브 요구 사항: 네이티브 앱의 최소 버전 요구 사항
  • 메타 데이터: 생성 시간, 소유권, 추적 정보 등

Capgo CLI을 사용하지 않고 수동으로 생성하고 업로드하는 방법에 대해 설명합니다.

1단계: 앱 빌드

“1단계: 앱 빌드”

앱의 웹 자산을 먼저 빌드하세요:

터미널 창
npm run build

2단계: Capgo CLI이 내부적으로 사용하는 동일한 패키지를 사용하여 번들 ZIP 생성

“2단계: Capgo CLI이 내부적으로 사용하는 동일한 패키지를 사용하여 번들 ZIP 생성”

중요: Capgo CLI이 내부적으로 사용하는 동일한 자바스크립트 패키지를 사용하여 호환성을 보장하세요.

터미널 창
npm install adm-zip @tomasklaen/checksum

자바스크립트와 동일한 Capgo CLI으로 ZIP 압축 파일을 생성하십시오

자바스크립트와 동일한 Capgo CLI으로 ZIP 압축 파일을 생성하십시오

아래 예시에서 version API이 사용하는 버전 이름을 나타냅니다.

const fs = require('node:fs');
const path = require('node:path');
const os = require('node:os');
const AdmZip = require('adm-zip');
const { checksum: getChecksum } = require('@tomasklaen/checksum');
// Exact same implementation as Capgo CLI
function zipFileUnix(filePath) {
const zip = new AdmZip();
zip.addLocalFolder(filePath);
return zip.toBuffer();
}
async function zipFileWindows(filePath) {
console.log('Zipping file windows mode');
const zip = new AdmZip();
const addToZip = (folderPath, zipPath) => {
const items = fs.readdirSync(folderPath);
for (const item of items) {
const itemPath = path.join(folderPath, item);
const stats = fs.statSync(itemPath);
if (stats.isFile()) {
const fileContent = fs.readFileSync(itemPath);
zip.addFile(path.join(zipPath, item).split(path.sep).join('/'), fileContent);
} else if (stats.isDirectory()) {
addToZip(itemPath, path.join(zipPath, item));
}
}
};
addToZip(filePath, '');
return zip.toBuffer();
}
// Main zipFile function (exact same logic as CLI)
async function zipFile(filePath) {
if (os.platform() === 'win32') {
return zipFileWindows(filePath);
} else {
return zipFileUnix(filePath);
}
}
async function createBundle(inputPath, outputPath, version) {
// Create zip using exact same method as Capgo CLI
const zipped = await zipFile(inputPath);
// Write to file
fs.writeFileSync(outputPath, zipped);
// Calculate checksum using exact same package as CLI
const checksum = await getChecksum(zipped, 'sha256');
return {
filename: path.basename(outputPath),
version: version,
size: zipped.length,
checksum: checksum
};
}
// Usage
async function main() {
try {
const result = await createBundle('./dist', './my-app-1.2.3.zip', '1.2.3');
console.log('Bundle info:', JSON.stringify(result, null, 2));
} catch (error) {
console.error('Error creating bundle:', error);
}
}
main();

3단계: CLI과 동일한 패키지를 사용하여 SHA256 체크섬을 계산하십시오

3단계: CLI과 동일한 패키지를 사용하여 SHA256 체크섬을 계산하십시오
const fs = require('node:fs');
const { checksum: getChecksum } = require('@tomasklaen/checksum');
async function calculateChecksum(filePath) {
const fileBuffer = fs.readFileSync(filePath);
// Use exact same package and method as Capgo CLI
const checksum = await getChecksum(fileBuffer, 'sha256');
return checksum;
}
// Usage
async function main() {
const checksum = await calculateChecksum('./my-app-1.2.3.zip');
console.log('Checksum:', checksum);
}
main();

4단계: ZIP 압축 파일을 저장소에 업로드하십시오

Step 4: __CAPGO_KEEP_0__ 업로드

__CAPGO_KEEP_0__에 업로드할 수 있는 웹 접근 가능한 저장소에 zip 파일을 업로드하세요:

터미널 창
# Example: Upload to your server via scp
scp my-app-1.2.3.zip user@your-server.com:/var/www/bundles/
# Example: Upload to S3 using AWS CLI
aws s3 cp my-app-1.2.3.zip s3://your-bucket/bundles/
# Example: Upload via curl to a custom endpoint
curl -X POST https://your-storage-api.com/upload \
-H "Authorization: Bearer YOUR_TOKEN" \
-F "file=@my-app-1.2.3.zip"

중요: __CAPGO_KEEP_0__의 __CAPGO_KEEP_0__은 공개적으로 접근할 수 있어야 합니다. HTTPS URL (인증이 필요하지 않음)로 접근할 수 있어야 합니다. Capgo의 서버는 이 URL에서 Capgo을 다운로드해야 합니다.

유효한 공개 URL의 예:

  • https://your-storage.com/bundles/my-app-1.2.3.zip
  • https://github.com/username/repo/releases/download/v1.2.3/bundle.zip
  • https://cdn.jsdelivr.net/gh/username/repo@v1.2.3/dist.zip

Step 5: Capgo API에 등록

Section titled “Step 5: Capgo API”

Capgo에 Capgo을 직접 호출하여 외부 API를 등록하세요:

async function registerWithCapgo(appId, version, bundleUrl, checksum, apiKey) {
const fetch = require('node-fetch');
// Create bundle (version)
const response = await fetch('https://api.capgo.app/bundle/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'authorization': apiKey
},
body: JSON.stringify({
app_id: appId,
version: version,
external_url: bundleUrl,
checksum: checksum
})
});
if (!response.ok) {
throw new Error(`Failed to create bundle: ${response.statusText}`);
}
const data = await response.json();
console.log('Bundle created:', data);
return data;
}

API 매개 변수

API 매개 변수 제목
매개 변수설명필수
app_id앱 식별자
version버전 semantic version (예: “1.2.3”)
external_url공개 가능한 HTTPS URL에서 배포할 수 있는 ZIP 파일을 다운로드할 수 있습니다 (인증이 필요하지 않습니다)
checksumZIP 파일의 SHA256 체크섬

배포 구조 요구 사항

배포 구조 요구 사항

배포할 ZIP 파일은 다음 요구 사항을 따라야 합니다:

  1. 루트 인덱스 파일: 루트 레벨에 있어야 합니다 index.html __CAPGO_KEEP_0__ 통합
  2. Capacitor Integration: __CAPGO_KEEP_0__을 호출해야 합니다. notifyAppReady() code을 앱 내에서 사용하세요.
  3. 자산 경로: 모든 자산에 대한 상대 경로를 사용하세요.

유효한 번들 구조

제목: 유효한 번들 구조
bundle.zip
├── index.html
├── assets/
│ ├── app.js
│ └── styles.css
└── images/

완전한 수동 워크플로 예제

제목: 완전한 수동 워크플로 예제

Node.js 스크립트를 사용하여 Capgo으로 압축, 체크섬, 업로드하세요.

const fs = require('node:fs');
const os = require('node:os');
const AdmZip = require('adm-zip');
const { checksum: getChecksum } = require('@tomasklaen/checksum');
const fetch = require('node-fetch');
async function deployToCapgo() {
const APP_ID = 'com.example.app';
const VERSION = '1.2.3';
const BUNDLE_URL = 'https://your-storage.com/bundles/app-1.2.3.zip';
const API_KEY = process.env.CAPGO_API_KEY;
// 1. Create zip (same as Capgo CLI)
const zip = new AdmZip();
zip.addLocalFolder('./dist');
const zipped = zip.toBuffer();
// 2. Calculate checksum (same as Capgo CLI)
const checksum = await getChecksum(zipped, 'sha256');
console.log('Checksum:', checksum);
// 3. Upload to your storage (replace with your upload logic)
// fs.writeFileSync('./bundle.zip', zipped);
// ... upload bundle.zip to your storage ...
// 4. Register with Capgo API
const response = await fetch('https://api.capgo.app/bundle/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'authorization': API_KEY
},
body: JSON.stringify({
app_id: APP_ID,
version: VERSION,
external_url: BUNDLE_URL,
checksum: checksum
})
});
if (!response.ok) {
throw new Error(`Failed: ${response.statusText}`);
}
console.log('Bundle registered with Capgo!');
}
deployToCapgo().catch(console.error);

의존성을 설치하세요: __CAPGO_KEEP_0__

터미널 창
npm install adm-zip @tomasklaen/checksum node-fetch

체크섬 검증

체크섬 검증 섹션

JavaScript 체크섬 계산 (Capgo CLI과 동일)

JavaScript 체크섬 계산 (Capgo CLI과 동일) 섹션

Capgo CLI이 내부적으로 사용하는 정확한 패키지와 메소드를 사용하십시오:

const fs = require('node:fs');
const { checksum: getChecksum } = require('@tomasklaen/checksum');
async function calculateChecksum(filePath) {
const fileBuffer = fs.readFileSync(filePath);
// Use exact same package and method as Capgo CLI
const checksum = await getChecksum(fileBuffer, 'sha256');
return checksum;
}
// Verify checksum matches
async function verifyChecksum(filePath, expectedChecksum) {
const actualChecksum = await calculateChecksum(filePath);
const isValid = actualChecksum === expectedChecksum;
console.log(`File: ${filePath}`);
console.log(`Expected: ${expectedChecksum}`);
console.log(`Actual: ${actualChecksum}`);
console.log(`Valid: ${isValid}`);
return isValid;
}
// Usage
async function main() {
const bundleChecksum = await calculateChecksum('./my-app-1.2.3.zip');
console.log('SHA256 Checksum:', bundleChecksum);
}
main();

체크섬의 중요성

체크섬의 중요성 섹션
  • 배포물의 무결성: 전송 중에 배포물이 손상되지 않았는지 확인합니다.
  • API 인증: Capgo는 체크섬을 검증하기 전에 번들을 수락합니다
  • 플러그인 인증: 모바일 플러그인은 업데이트를 적용하기 전에 체크섬을 검증합니다
  1. 번들(버전) 관리: 반드시 일관적인 저장소 최적화
  2. : 사용하지 않는 번들을 정기적으로 삭제하세요__CAPGO_KEEP_0__
  3. 버전 호환성 (Bundle): 적절한 최소 원시 버전 요구 사항을 설정하십시오
  4. 백업 전략: 중요한 버전의 배달본 (Bundle)을 백업하십시오

엔드포인트

엔드포인트

GET

GET

https://api.capgo.app/bundle/

배달본 정보를 가져옵니다. 1페이지당 50개의 배달본을 반환합니다.

쿼리 매개변수

쿼리 매개변수
  • app_id: 필수. 앱의 ID
  • page: Optional. 페이지 번호 (pagination)
interface Bundle {
app_id: string
bucket_id: string | null
checksum: string | null
created_at: string | null
deleted: boolean
external_url: string | null
id: number
minUpdateVersion: string | null
name: string
native_packages: Json[] | null
owner_org: string
r2_path: string | null
session_key: string | null
storage_provider: string
updated_at: string | null
user_id: string | null
}
터미널 창
# Get all bundles
curl -H "authorization: your-api-key" \
"https://api.capgo.app/bundle/?app_id=app_123"
# Get next page
curl -H "authorization: your-api-key" \
"https://api.capgo.app/bundle/?app_id=app_123&page=1"
{
"data": [
{
"id": 1,
"app_id": "app_123",
"name": "1.0.0",
"checksum": "abc123...",
"minUpdateVersion": "1.0.0",
"storage_provider": "r2",
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-01T00:00:00Z",
"deleted": false,
"owner_org": "org_123",
"user_id": "user_123"
}
]
}

삭제

삭제

https://api.capgo.app/bundle/

앱의 하나 이상의 패키지를 삭제합니다. 주의하십시오. 이 작업은 되돌릴 수 없습니다.

쿼리 매개변수

쿼리 매개변수

특정 패키지를 삭제하려면:

interface BundleDelete {
app_id: string
version: string
}

모든 패키지를 삭제하려면:

interface BundleDeleteAll {
app_id: string
}

예제 요청

터미널 창
클립보드에 복사
# Delete specific bundle
curl -X DELETE \
-H "authorization: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"app_id": "app_123",
"version": "1.0.0"
}' \
https://api.capgo.app/bundle/
# Delete all bundles
curl -X DELETE \
-H "authorization: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"app_id": "app_123"
}' \
https://api.capgo.app/bundle/
{
"status": "ok"
}

https://api.capgo.app/bundle/

외부 URL을 가진 새로운 번들을 생성하세요.

interface CreateBundleBody {
app_id: string
version: string
external_url: string // Must be publicly accessible HTTPS URL
checksum: string
}

예제 요청

터미널 창
터미널 창
curl -X POST \
-H "authorization: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"app_id": "com.example.app",
"version": "1.2.3",
"external_url": "https://your-storage.com/bundles/app-1.2.3.zip",
"checksum": "a1b2c3d4e5f6789abcdef123456789abcdef123456789abcdef123456789abcd"
}' \
https://api.capgo.app/bundle/
{
"status": "ok"
}

POST (메타데이터)

POST (메타데이터) 섹션

https://api.capgo.app/bundle/metadata

링크 및 댓글 정보와 같은 번들 메타데이터를 업데이트합니다.

interface UpdateMetadataBody {
app_id: string
version_id: number // bundle (version) id
link?: string
comment?: string
}
터미널 창
curl -X POST \
-H "authorization: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"app_id": "app_123",
"version_id": 456,
"link": "https://github.com/myorg/myapp/releases/tag/v1.0.0",
"comment": "Fixed critical bug in authentication"
}' \
https://api.capgo.app/bundle/metadata
{
"status": "success"
}

https://api.capgo.app/bundle/

특정 채널에 버너를 설정합니다. 이 작업은 버너(버전)를 배포에 사용할 채널과 연결합니다.

interface SetChannelBody {
app_id: string
version_id: number // bundle (version) id
channel_id: number
}
터미널 창
curl -X PUT \
-H "authorization: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"app_id": "app_123",
"version_id": 456,
"channel_id": 789
}' \
https://api.capgo.app/bundle/
{
"status": "success",
"message": "Bundle 1.0.0 set to channel production"
}

오류 시나리오 및 응답:

// Bundle not found
{
"error": "Bundle not found",
"status": "KO"
}
// Invalid bundle (version) format
{
"error": "Invalid version format",
"status": "KO"
}
// Storage error
{
"error": "Failed to delete bundle from storage",
"status": "KO"
}
// Permission denied
{
"error": "Insufficient permissions to manage bundles",
"status": "KO"
}

일반적인 사용 사례

사용 사례 섹션
  1. Cleanup Old Bundles (Versions)
// Delete outdated beta bundles (versions)
{
"app_id": "app_123",
"version": "1.0.0-beta.1"
}
  1. App Reset
// Remove all bundles to start fresh
{
"app_id": "app_123"
}

Storage Considerations

Storage Considerations
  1. Retention Policy: __CAPGO_KEEP_0__을 유지하는 기간을 정의합니다.
  2. Size Management: __CAPGO_KEEP_1__ 크기와 저장소 사용량을 모니터링합니다.
  3. Backup Strategy: __CAPGO_KEEP_2__ 중요 버전을 백업하는 것을 고려합니다.
  4. 비용 최적화: 저장 비용 최적화를 위해 불필요한 번들을 제거하세요

Capgo를 사용하는 경우 Capgo의 번들 저장 및 파일 관리를 위해 계획하고, @capgo/capacitor-data-storage-sqlite @capgo/capacitor-data-storage-sqlite의 구현 세부 사항 Capgo의 @capgo/capacitor-data-storage-sqlite Capgo의 @capgo/capacitor-data-storage-sqlite의 원시 기능 @capgo/capacitor-file 구현 세부 정보에 대한 @capgo/capacitor-파일에 대해 사용 @capgo/capacitor-파일 자연스러운 기능을 위해 @capgo/capacitor-파일을 사용하고 @capgo/capacitor-업로더 구현 세부 정보에 대한 @capgo/capacitor-업로더에 대해