Panduan Memulai
Salin prompt setup yang berisi langkah install dan panduan markdown lengkap untuk plugin ini.
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.
Anda bisa menggunakan AI-Assisted Setup kami untuk menginstal plugin ini. Tambahkan skill Capgo ke tool AI Anda dengan command berikut:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsLalu gunakan prompt berikut:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-downloader` plugin in my project.Jika Anda lebih memilih Manual Setup, instal plugin dengan menjalankan perintah berikut dan ikuti petunjuk khusus platform di bawah ini:
bun add @capgo/capacitor-downloaderbunx cap syncimport { CapacitorDownloader } from '@capgo/capacitor-downloader';Mulai cepat
Bagian berjudul “Mulai cepat”Download ke folder tertentu, pantau progresnya, dan lanjutkan kembali setelah aplikasi restart jika didukung.
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',});Contoh: pause dan resume
Bagian berjudul “Contoh: pause dan resume”await CapacitorDownloader.pause({ id: 'offline-pack' });await CapacitorDownloader.resume({ id: 'offline-pack' });Contoh: inspeksi file yang selesai
Bagian berjudul “Contoh: inspeksi file yang selesai”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 });Kesalahan umum
Bagian berjudul “Kesalahan umum”- Lokasi penyimpanan: pilih satu
destinationaplikasi Anda dapat baca di setiap platform. - Background: download berjalan di background pada iOS dan Android. Pada Web,
download()belum diimplementasikan; gunakan alur download browser sebagai gantinya. - Status: gunakan
checkStatusselama proses aplikasi masih berjalan. Di iOS, task ID tidak dipulihkan setelah relaunch.
Ringkasan API
Bagian berjudul “API Overview”download
Bagian berjudul “download”Mulai task download baru.
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const task = await CapacitorDownloader.download({ id: 'my-download', url: 'https://example.com/file.pdf', destination: 'downloads/file.pdf'});Jeda download yang sedang aktif. Download dapat dilanjutkan nanti dari posisi yang sama.
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.pause({ id: 'id-123' });resume
Bagian berjudul “resume”Lanjutkan download yang tertunda. Melanjutkan dari titik terakhir saat dijeda.
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.resume({ id: 'id-123' });Hentikan dan batalkan download secara permanen. Data yang sudah di-download akan dihapus.
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.stop({ id: 'id-123' });checkStatus
Bagian berjudul “checkStatus”Cek status download saat ini.
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const result = await CapacitorDownloader.checkStatus({ id: 'id-123' });console.log(result);getFileInfo
Bagian berjudul “getFileInfo”Dapatkan informasi tentang file yang di-download.
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const result = await CapacitorDownloader.getFileInfo({ path: 'path/to/file' });console.log(result);Referensi Tipe
Bagian berjudul “Referensi Tipe”DownloadOptions
Bagian berjudul “DownloadOptions”Opsi konfigurasi untuk memulai download.
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
Bagian berjudul “DownloadTask”Merepresentasikan status dan progres saat ini dari sebuah download task.
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';}Sumber Kebenaran
Bagian berjudul “Sumber Kebenaran”Halaman ini dibuat dari plugin src/definitions.ts. Jalankan ulang sync saat API publik berubah di upstream.
Lanjutkan dari Getting Started
Bagian berjudul “Lanjutkan dari Getting Started”Jika Anda menggunakan Panduan Memulai untuk merencanakan dashboard dan operasi API, hubungkan dengan Menggunakan @capgo/capacitor-downloader untuk kapabilitas native saat Menggunakan @capgo/capacitor-downloader, Ringkasan API untuk detail implementasi di API Overview, Pendahuluan untuk detail implementasi di Introduction, Kunci API untuk detail implementasi di API Keys, dan Perangkat untuk detail implementasi di Devices.