はじめに
このプラグインのインストール手順と完全なMarkdownガイドを含むセットアッププロンプトをコピー
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-downloader`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/downloader/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
インストール
「Install」セクションAIアシストセットアップを使ってプラグインをインストールできます。以下のコマンドで、お使いのAIツールに Capgo スキルを追加してください:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins次に、以下のプロンプトを使用します:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-downloader` plugin in my project.手動セットアップを希望する場合は、以下のコマンドでプラグインをインストールし、下記のプラットフォーム別の手順に従ってください:
bun add @capgo/capacitor-downloaderbunx cap syncインポート
「Import」セクションimport { CapacitorDownloader } from '@capgo/capacitor-downloader';クイックスタート
「Quick start」セクション指定したフォルダへのダウンロード、進捗の監視、およびサポートされている環境でのアプリ再起動後のレジュームに対応しています。
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const progressListener = await CapacitorDownloader.addListener('downloadProgress', (event) => { if (event.id === 'offline-pack') { console.log(event.progress); }});
const task = await CapacitorDownloader.download({ id: 'offline-pack', url: 'https://cdn.example.com/large-pack.zip', destination: 'downloads/offline-pack.zip',});例:一時停止と再開
「例:一時停止とレジューム」というタイトルのセクションawait CapacitorDownloader.pause({ id: 'offline-pack' });await CapacitorDownloader.resume({ id: 'offline-pack' });例:完了したファイルの確認
「例:完了したファイルの確認」セクションimport { Capacitor } from '@capacitor/core';import { Directory, Filesystem } from '@capacitor/filesystem';
const relativePath = 'downloads/offline-pack.zip';const path = Capacitor.getPlatform() === 'ios' ? (await Filesystem.getUri({ directory: Directory.Documents, path: relativePath })).uri : relativePath;
const info = await CapacitorDownloader.getFileInfo({ path });よくある落とし穴
「Common pitfalls」セクション- 保存先: 以下から選択
destination各プラットフォームでアプリが読み取れる場所を指定してください。 - バックグラウンド: iOSとAndroidではバックグラウンドでダウンロードを実行します。Webでは、
download()は未実装です。代わりにブラウザのダウンロードフローを使用してください。 - ステータス: 使用
checkStatusアプリのプロセスが実行されている間のみ可能です。iOSでは、アプリの再起動後にタスクIDは復元されません。
API の概要
「API 概要」セクションdownload
「download」セクション新しいダウンロードタスクを開始します。
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const task = await CapacitorDownloader.download({ id: 'my-download', url: 'https://example.com/file.pdf', destination: 'downloads/file.pdf'});pause
「pause」セクション実行中のダウンロードを一時停止します。 ダウンロードは後で同じ位置から再開できます。
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.pause({ id: 'id-123' });resume
「resume」セクション一時停止中のダウンロードを再開します。 中断した箇所から続行します。
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.resume({ id: 'id-123' });stop
「stop」セクションダウンロードを停止し、完全にキャンセルします。 ダウンロード済みのデータは削除されます。
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.stop({ id: 'id-123' });checkStatus
「checkStatus」セクションダウンロードの現在のステータスを確認します。
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const result = await CapacitorDownloader.checkStatus({ id: 'id-123' });console.log(result);getFileInfo
「getFileInfo」セクションダウンロード済みファイルの情報を取得します。
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const result = await CapacitorDownloader.getFileInfo({ path: 'path/to/file' });console.log(result);型リファレンス
「型リファレンス」セクションDownloadOptions
「DownloadOptions」セクションダウンロードを開始するための設定オプション。
export interface DownloadOptions { /** Unique identifier for this download task */ id: string; /** URL of the file to download */ url: string; /** Local file path where the download will be saved */ destination: string; /** Optional HTTP headers to include in the request */ headers?: { [key: string]: string }; /** Network type requirement for download */ network?: 'cellular' | 'wifi-only'; /** Download priority level */ priority?: 'high' | 'normal' | 'low';}DownloadTask
「DownloadTask」セクションダウンロードタスクの現在の状態と進捗を表します。
export interface DownloadTask { /** Unique identifier for the download task */ id: string; /** Download progress from 0 to 100 */ progress: number; /** Current state of the download */ state: 'PENDING' | 'RUNNING' | 'PAUSED' | 'DONE' | 'ERROR';}信頼できる情報源
「信頼できる情報源」セクションこのページはプラグインの src/definitions.tsから生成されています。上流で公開 API が変更されたら、sync を再実行してください。
Getting Started から続ける
「Getting Started からの続き」セクション以下を使用している場合: はじめに ダッシュボードと API の操作を計画するには、以下と連携してください @capgo/capacitor-downloader の使用方法 @capgo/capacitor-downloader でネイティブ機能を使用する場合、 API の概要 API Overview の実装の詳細については、 はじめに Introduction の実装の詳細については、 API キー API Keys の実装の詳細については、 デバイス Devices の実装の詳細については。