__CAPGO_KEEP_0__
インストールステップとこのプラグインのフルマークダウンガイドまでの全てのステップを含むセットアップ用の質問をコピーする
Capgoのバンドルは、更新パッケージの核となるものです。各バンドルには、Webアセット(HTML、CSS、JS)が含まれます。これらは、Webアプリのコンテンツを構成します。APIのバンドルは、更新パッケージの管理を可能にし、リストや削除も行えます。
バンドルの理解
「バンドルの理解」バンドルは、Webコンテンツの特定のバージョンを表し、以下の要素を含みます。
- バンドル(バージョン): バンドルのセマンティックバージョン バンドルのバージョン
- チェックサム: バンドルの完全性を確認するためのユニークなハッシュ
- ストレージ情報: __CAPGO_KEEP_0__
- Native Requirements: __CAPGO_KEEP_1__
- Metadata: __CAPGO_KEEP_2__
Manual Bundle Creation (Without CLI)
Manual Bundle Creation (Without CLI)Here’s how to create and upload bundles manually without using the Capgo CLI:
Step 1: Build Your App
Step 1: Build Your Appまず、Web アセットをビルドしてください。
npm run buildステップ 2: Capgo CLI と同じパッケージを使用してバンドル ZIP を作成する
ステップ 2: Capgo CLI と同じパッケージを使用してバンドル ZIP を作成する重要: Capgo CLI 内部で使用する JavaScript パッケージをそのまま使用して、互換性を確保するようにしてください。
必要なパッケージをインストールする
必要なパッケージをインストールするnpm install adm-zip @tomasklaen/checksumCapgo CLI と同じ JavaScript を使用して ZIP バンドルを作成する
Capgo CLI と同じ JavaScript を使用して ZIP バンドルを作成する注: 以下の例では version refers to the bundle (version) name used by the 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 CLIfunction 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 };}
// Usageasync 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;}
// Usageasync function main() { const checksum = await calculateChecksum('./my-app-1.2.3.zip'); console.log('Checksum:', checksum);}
main();ステップ 4: バンドルを自分のストレージにアップロードする
「ステップ 4: バンドルを自分のストレージにアップロードする」のセクションあなたの zip ファイルを、Web アクセス可能なストレージにアップロードしてください。
# Example: Upload to your server via scpscp my-app-1.2.3.zip user@your-server.com:/var/www/bundles/
# Example: Upload to S3 using AWS CLIaws s3 cp my-app-1.2.3.zip s3://your-bucket/bundles/
# Example: Upload via curl to a custom endpointcurl -X POST https://your-storage-api.com/upload \ -H "Authorization: Bearer YOUR_TOKEN" \ -F "file=@my-app-1.2.3.zip"重要あなたのバンドルは 公開アクセス可能 HTTPS URL (認証なし)経由で利用可能です。 Capgoのサーバーは、このURLからバンドルをダウンロードする必要があります。
有効な公開URLの例:
https://your-storage.com/bundles/my-app-1.2.3.ziphttps://github.com/username/repo/releases/download/v1.2.3/bundle.ziphttps://cdn.jsdelivr.net/gh/username/repo@v1.2.3/dist.zip
ステップ 5: Capgo APIでバンドルを登録する
ステップ 5: Capgo APIでバンドルを登録するCapgo APIを直接呼び出して、外部のバンドルをCapgoに登録する
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 | __CAPGO_KEEP_0__ | はい |
version | バンドル (バージョン) シーケンス バージョン (例:「1.2.3」) | はい |
external_url | パブリック アクセス可能 HTTPS でダウンロード可能なバンドルの URL (認証なし) | はい |
checksum | zip ファイルの SHA256 チェックサム | はい |
バンドル構造要件
「バンドル構造要件」セクションバンドル ZIP は次の要件を満たす必要があります:
- Root Index File: 必ず
index.htmlroot レベルに - Capacitor統合: 必ず
notifyAppReady()アプリケーション内でcodeを呼び出します - アセット パス: 全てのアセットに相対パスを使用する
有効なバンドル構造
「有効なバンドル構造」セクションbundle.zip├── index.html├── assets/│ ├── app.js│ └── styles.css└── images/完全な手動ワークフロー例
「完全な手動ワークフロー例」のセクションCapgoにzip、チェックサム、そしてアップロードするためのシンプルなNode.jsスクリプト
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);依存関係をインストールする:
npm install adm-zip @tomasklaen/checksum node-fetchチェックサムの検証
「チェックサムの検証」のセクションCapgoとCLIと同じJavaScriptチェックサム計算
「CapgoとCLIと同じJavaScriptチェックサム計算」のセクション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 matchesasync 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;}
// Usageasync function main() { const bundleChecksum = await calculateChecksum('./my-app-1.2.3.zip'); console.log('SHA256 Checksum:', bundleChecksum);}
main();チェックサムの重要性
「チェックサムの重要性」のセクション- バンドルの整合性: 転送中のバンドルが破損されていないことを確認します
- API の検証: Capgo はチェックサムをバンドルを受け入れる前に検証します
- プラグイン検証: モバイル プラグインはアップデートを適用する前にチェックサムを検証します
ベスト プラクティス
「ベスト プラクティス」のセクション- バンドル (バージョン) 管理: 使用 シームレス バージョニングを使用して 一貫して
- ストレージ オプティミゼーション: 不要なバンドルを定期的に削除する
- バンドル (バージョン) 相容性: 最小のネイティブ バージョン要件を適切に設定する
- バックアップ ストラテジー: 重要なバンドル (バージョン) のバックアップを維持する
エンドポイント
「エンドポイント」セクションGET
GEThttps://api.capgo.app/bundle/
情報の取得
app_id:必須。アプリのIDpage:オプション。ページネーションのページ番号
Response Type
Section titled “Response Type”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}Example Request
Section titled “Example Request”# Get all bundlescurl -H "authorization: your-api-key" \ "https://api.capgo.app/bundle/?app_id=app_123"
# Get next pagecurl -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" } ]}DELETE
セクション「DELETE」https://api.capgo.app/bundle/
アプリのバンドルを1つまたはすべて削除します。削除は取り消すことができないため、注意してください。
クエリパラメータ
セクション「クエリパラメータ」特定のバンドルを削除する場合:
interface BundleDelete { app_id: string version: string}すべてのバンドルを削除する:
interface BundleDeleteAll { app_id: string}例のリクエスト
「例のリクエスト」のセクション# Delete specific bundlecurl -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 bundlescurl -X DELETE \ -H "authorization: your-api-key" \ -H "Content-Type: application/json" \ -d '{ "app_id": "app_123" }' \ https://api.capgo.app/bundle/成功応答
「成功応答」のセクション{ "status": "ok"}POST
「POST」のセクション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
バンドルメタデータの更新、例えばリンクやコメント情報の更新。
__CAPGO_KEEP_0__
「__CAPGO_KEEP_0__」interface UpdateMetadataBody { app_id: string version_id: number // bundle (version) id link?: string comment?: string}例: __CAPGO_KEEP_0__
「__CAPGO_KEEP_0__」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成功レスポンス
「__CAPGO_KEEP_0__」{ "status": "success"}https://api.capgo.app/bundle/
指定されたチャンネルにバンドルを設定します。このリンクはバンドル(バージョン)を配布用のチャンネルと関連付けます。
Request Body
Section titled “Request Body”interface SetChannelBody { app_id: string version_id: number // bundle (version) id channel_id: number}例:リクエスト
Section titled “例:リクエスト”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/成功レスポンス
Section titled “成功レスポンス”{ "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"}一般的な使用例
セクション: 一般的な使用例- 古いバンドル (バージョン) のクリーンアップ
// Delete outdated beta bundles (versions){ "app_id": "app_123", "version": "1.0.0-beta.1"}- アプリケーション リセット
// Remove all bundles to start fresh{ "app_id": "app_123"}ストレージに関する考慮事項
セクション: ストレージに関する考慮事項- 保有期間ポリシー: 旧バンドルを保持する期間を定義する
- サイズ管理: バンドルサイズとストレージ使用量を監視する
- バックアップ戦略: 重要なバンドルバージョンをバックアップすることを検討する
- コスト最適化: 必要ないバンドルを削除してストレージコストを最適化する
バンドルから続ける
バンドルから続けるセクションCapgoを使用している場合 バンドル データの保存とファイルの管理を計画するには、を接続してください。 @capgo/capacitor-data-storage-sqlite @capgo/capacitor-data-storage-sqliteの実装詳細については、 @capgo/capacitor-data-storage-sqliteを使用します。 @capgo/capacitor-data-storage-sqliteのネイティブ機能を使用するには、 @capgo/capacitor-file @capgo/capacitor-fileの実装詳細については、 @capgo/capacitor-fileを使用します。 @capgo/capacitor-fileのネイティブ機能を使用するには、 @capgo/capacitor-uploader @capgo/capacitor-uploaderの実装詳細については、