@capgo/capacitor-uploader 8.0.9 → 8.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -7
- package/android/src/main/java/ee/forgr/capacitor/uploader/UploaderPlugin.java +1 -1
- package/dist/esm/PathHelper.d.ts +8 -0
- package/dist/esm/PathHelper.js +21 -0
- package/dist/esm/PathHelper.js.map +1 -0
- package/dist/esm/web.d.ts +2 -0
- package/dist/esm/web.js +41 -3
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +61 -3
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +62 -5
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/UploaderPlugin/UploaderPlugin.swift +1 -1
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
# @capgo/capacitor-uploader
|
|
2
|
+
Upload files in the background with progress tracking, resumable uploads, and network-aware handling for Capacitor apps.
|
|
3
|
+
|
|
4
|
+
|
|
2
5
|
<a href="https://capgo.app/"><img src='https://raw.githubusercontent.com/Cap-go/capgo/main/assets/capgo_banner.png' alt='Capgo - Instant updates for capacitor'/></a>
|
|
3
6
|
|
|
4
7
|
<div align="center">
|
|
@@ -12,10 +15,25 @@ This plugin provides a flexible way to upload natively files to various servers,
|
|
|
12
15
|
|
|
13
16
|
Can be used in combination with the [Capacitor Camera preview](https://github.com/Cap-go/camera-preview) To upload file in reliable manner instead of reading them in buffer of webview and then upload in JS.
|
|
14
17
|
|
|
18
|
+
On the web, file paths support IndexedDB (IDB) semantic paths using the following format:
|
|
19
|
+
`idb://[database-name]/[collection-name]/[key]`
|
|
20
|
+
This allows seamless integration with IndexedDB for storing and retrieving files.
|
|
21
|
+
|
|
15
22
|
## Documentation
|
|
16
23
|
|
|
17
24
|
The most complete doc is available here: https://capgo.app/docs/plugins/uploader/
|
|
18
25
|
|
|
26
|
+
## Compatibility
|
|
27
|
+
|
|
28
|
+
| Plugin version | Capacitor compatibility | Maintained |
|
|
29
|
+
| -------------- | ----------------------- | ---------- |
|
|
30
|
+
| v8.\*.\* | v8.\*.\* | ✅ |
|
|
31
|
+
| v7.\*.\* | v7.\*.\* | On demand |
|
|
32
|
+
| v6.\*.\* | v6.\*.\* | ❌ |
|
|
33
|
+
| v5.\*.\* | v5.\*.\* | ❌ |
|
|
34
|
+
|
|
35
|
+
> **Note:** The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v8 for Capacitor 8). Only the latest major version is actively maintained.
|
|
36
|
+
|
|
19
37
|
## Install
|
|
20
38
|
|
|
21
39
|
```bash
|
|
@@ -23,7 +41,7 @@ npm install @capgo/capacitor-uploader
|
|
|
23
41
|
npx cap sync
|
|
24
42
|
```
|
|
25
43
|
|
|
26
|
-
## Android
|
|
44
|
+
## Android
|
|
27
45
|
|
|
28
46
|
Add the following to your `AndroidManifest.xml` file:
|
|
29
47
|
|
|
@@ -33,10 +51,7 @@ Add the following to your `AndroidManifest.xml` file:
|
|
|
33
51
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
|
34
52
|
```
|
|
35
53
|
|
|
36
|
-
## Example S3 upload
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
## Example S3 upload:
|
|
54
|
+
## Example S3 upload
|
|
40
55
|
|
|
41
56
|
```typescript
|
|
42
57
|
import { Uploader } from '@capgo/capacitor-uploader';
|
|
@@ -71,7 +86,7 @@ async function uploadToS3(filePath: string, presignedUrl: string, fields: Record
|
|
|
71
86
|
|
|
72
87
|
```
|
|
73
88
|
|
|
74
|
-
### Example upload to a custom server
|
|
89
|
+
### Example upload to a custom server
|
|
75
90
|
|
|
76
91
|
```typescript
|
|
77
92
|
import { Uploader } from '@capgo/capacitor-uploader';
|
|
@@ -127,7 +142,7 @@ uploadToCustomServer(filePath, serverUrl);
|
|
|
127
142
|
|
|
128
143
|
```
|
|
129
144
|
|
|
130
|
-
### Example with Capacitor Camera preview
|
|
145
|
+
### Example with Capacitor Camera preview
|
|
131
146
|
|
|
132
147
|
Documentation for the [Capacitor Camera preview](https://github.com/Cap-go/camera-preview)
|
|
133
148
|
|
|
@@ -21,7 +21,7 @@ import net.gotev.uploadservice.observer.request.RequestObserverDelegate;
|
|
|
21
21
|
@CapacitorPlugin(name = "Uploader")
|
|
22
22
|
public class UploaderPlugin extends Plugin {
|
|
23
23
|
|
|
24
|
-
private final String pluginVersion = "8.
|
|
24
|
+
private final String pluginVersion = "8.1.1";
|
|
25
25
|
|
|
26
26
|
private Uploader implementation;
|
|
27
27
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class PathHelper {
|
|
2
|
+
// Check if the path follows the idb://[databaseName]/[storeName]/[key] format
|
|
3
|
+
static isIndexedDBPath(path) {
|
|
4
|
+
const regex = /^idb:\/\/([^/]+)\/([^/]+)\/(.+)$/;
|
|
5
|
+
return regex.test(path);
|
|
6
|
+
}
|
|
7
|
+
// Parse the path to extract database, storeName, and key
|
|
8
|
+
static parseIndexedDBPath(path) {
|
|
9
|
+
const regex = /^idb:\/\/([^/]+)\/([^/]+)\/(.+)$/;
|
|
10
|
+
const match = path.match(regex);
|
|
11
|
+
if (!match) {
|
|
12
|
+
throw new Error('Invalid IndexedDB path format');
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
database: match[1],
|
|
16
|
+
storeName: match[2],
|
|
17
|
+
key: match[3],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=PathHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PathHelper.js","sourceRoot":"","sources":["../../src/PathHelper.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAU;IACrB,8EAA8E;IAC9E,MAAM,CAAC,eAAe,CAAC,IAAY;QACjC,MAAM,KAAK,GAAG,kCAAkC,CAAC;QACjD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED,yDAAyD;IACzD,MAAM,CAAC,kBAAkB,CAAC,IAAY;QACpC,MAAM,KAAK,GAAG,kCAAkC,CAAC;QACjD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAEhC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACnD,CAAC;QAED,OAAO;YACL,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;YAClB,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;YACnB,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;SACd,CAAC;IACJ,CAAC;CACF","sourcesContent":["export class PathHelper {\n // Check if the path follows the idb://[databaseName]/[storeName]/[key] format\n static isIndexedDBPath(path: string): boolean {\n const regex = /^idb:\\/\\/([^/]+)\\/([^/]+)\\/(.+)$/;\n return regex.test(path);\n }\n\n // Parse the path to extract database, storeName, and key\n static parseIndexedDBPath(path: string): { database: string; storeName: string; key: string } {\n const regex = /^idb:\\/\\/([^/]+)\\/([^/]+)\\/(.+)$/;\n const match = path.match(regex);\n\n if (!match) {\n throw new Error('Invalid IndexedDB path format');\n }\n\n return {\n database: match[1],\n storeName: match[2],\n key: match[3],\n };\n }\n}\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export declare class UploaderWeb extends WebPlugin implements UploaderPlugin {
|
|
|
10
10
|
}): Promise<void>;
|
|
11
11
|
private doUpload;
|
|
12
12
|
private getFileFromPath;
|
|
13
|
+
private getFileFromIndexedDB;
|
|
14
|
+
private getFileFromSystem;
|
|
13
15
|
getPluginVersion(): Promise<{
|
|
14
16
|
version: string;
|
|
15
17
|
}>;
|
package/dist/esm/web.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import { openDB } from 'idb';
|
|
3
|
+
import { PathHelper } from './PathHelper';
|
|
2
4
|
export class UploaderWeb extends WebPlugin {
|
|
3
5
|
constructor() {
|
|
4
6
|
super(...arguments);
|
|
@@ -74,9 +76,45 @@ export class UploaderWeb extends WebPlugin {
|
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
async getFileFromPath(filePath) {
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
+
// Check if the path is an IndexedDB path
|
|
80
|
+
if (PathHelper.isIndexedDBPath(filePath)) {
|
|
81
|
+
return this.getFileFromIndexedDB(filePath);
|
|
82
|
+
}
|
|
83
|
+
// Otherwise, treat it as a file path from the system
|
|
84
|
+
return this.getFileFromSystem(filePath);
|
|
85
|
+
}
|
|
86
|
+
// Retrieve the file from IndexedDB
|
|
87
|
+
async getFileFromIndexedDB(filePath) {
|
|
88
|
+
// Parse the path to get the database, store name, and key
|
|
89
|
+
const { database, storeName, key } = PathHelper.parseIndexedDBPath(filePath);
|
|
90
|
+
try {
|
|
91
|
+
// Open the IndexedDB database and access the object store
|
|
92
|
+
const db = await openDB(database, 1, {
|
|
93
|
+
upgrade(db) {
|
|
94
|
+
if (!db.objectStoreNames.contains(storeName)) {
|
|
95
|
+
db.createObjectStore(storeName);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
// Get the blob from the store
|
|
100
|
+
const blob = await db.get(storeName, key);
|
|
101
|
+
if (!blob) {
|
|
102
|
+
console.error(`File with key "${key}" not found in store "${storeName}" in database "${database}"`);
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
// Convert the Blob to a File object
|
|
106
|
+
return new File([blob], key, { type: blob.type });
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
console.error('Error retrieving file from IndexedDB:', error);
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Retrieve the file from the system (local file)
|
|
114
|
+
async getFileFromSystem(filePath) {
|
|
79
115
|
try {
|
|
116
|
+
// This is a simplified version. In a real-world scenario,
|
|
117
|
+
// you might need to handle different types of paths or use a file system API.
|
|
80
118
|
const response = await fetch(filePath);
|
|
81
119
|
const blob = await response.blob();
|
|
82
120
|
return new File([blob], filePath.split('/').pop() || 'file', {
|
|
@@ -84,7 +122,7 @@ export class UploaderWeb extends WebPlugin {
|
|
|
84
122
|
});
|
|
85
123
|
}
|
|
86
124
|
catch (error) {
|
|
87
|
-
console.error('Error getting file:', error);
|
|
125
|
+
console.error('Error getting file from system:', error);
|
|
88
126
|
return null;
|
|
89
127
|
}
|
|
90
128
|
}
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,MAAM,OAAO,WAAY,SAAQ,SAAS;IAA1C;;QACU,YAAO,GAAkE,IAAI,GAAG,EAAE,CAAC;IA2I7F,CAAC;IAzIC,KAAK,CAAC,WAAW,CAAC,OAAqB;QACrC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QAEpC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACvD,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;QAC3C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,UAA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IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACpD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;YAC9D,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,iDAAiD;IACzC,KAAK,CAAC,iBAAiB,CAAC,QAAgB;QAC9C,IAAI,CAAC;YACH,0DAA0D;YAC1D,8EAA8E;YAC9E,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC;YACvC,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,OAAO,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,MAAM,EAAE;gBAC3D,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;YACxD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\nimport { openDB } from 'idb';\n\nimport { PathHelper } from './PathHelper';\nimport type { UploaderPlugin, uploadOption } from './definitions';\n\nexport class UploaderWeb extends WebPlugin implements UploaderPlugin {\n private uploads: Map<string, { controller: AbortController; retries: number }> = new Map();\n\n async startUpload(options: uploadOption): Promise<{ id: string }> {\n console.log('startUpload', options);\n\n const id = Math.random().toString(36).substring(2, 15);\n const controller = new AbortController();\n const maxRetries = options.maxRetries || 3;\n this.uploads.set(id, { controller, retries: maxRetries });\n\n this.doUpload(id, options);\n\n return { id };\n }\n\n async removeUpload(options: { id: string }): Promise<void> {\n console.log('removeUpload', options);\n const upload = this.uploads.get(options.id);\n if (upload) {\n upload.controller.abort();\n this.uploads.delete(options.id);\n this.notifyListeners('events', {\n name: 'cancelled',\n id: options.id,\n payload: {},\n });\n }\n }\n\n private async doUpload(id: string, options: uploadOption) {\n const { filePath, serverUrl, headers = {}, method = 'POST', parameters = {} } = options;\n const upload = this.uploads.get(id);\n\n if (!upload) return;\n\n try {\n const file = await this.getFileFromPath(filePath);\n if (!file) throw new Error('File not found');\n\n const formData = new FormData();\n formData.append('file', file);\n\n for (const [key, value] of Object.entries(parameters)) {\n formData.append(key, value);\n }\n\n const response = await fetch(serverUrl, {\n method,\n headers,\n body: method === 'PUT' ? file : formData,\n signal: upload.controller.signal,\n });\n\n if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);\n\n this.notifyListeners('events', {\n name: 'completed',\n id,\n payload: { statusCode: response.status },\n });\n\n this.uploads.delete(id);\n } catch (error) {\n if ((error as Error).name === 'AbortError') return;\n\n if (upload.retries > 0) {\n upload.retries--;\n console.log(`Retrying upload (retries left: ${upload.retries})`);\n setTimeout(() => this.doUpload(id, options), 1000);\n } else {\n this.notifyListeners('events', {\n name: 'failed',\n id,\n payload: { error: (error as Error).message },\n });\n this.uploads.delete(id);\n }\n }\n }\n\n private async getFileFromPath(filePath: string): Promise<File | null> {\n // Check if the path is an IndexedDB path\n if (PathHelper.isIndexedDBPath(filePath)) {\n return this.getFileFromIndexedDB(filePath);\n }\n\n // Otherwise, treat it as a file path from the system\n return this.getFileFromSystem(filePath);\n }\n\n // Retrieve the file from IndexedDB\n private async getFileFromIndexedDB(filePath: string): Promise<File | null> {\n // Parse the path to get the database, store name, and key\n const { database, storeName, key } = PathHelper.parseIndexedDBPath(filePath);\n\n try {\n // Open the IndexedDB database and access the object store\n const db = await openDB(database, 1, {\n upgrade(db) {\n if (!db.objectStoreNames.contains(storeName)) {\n db.createObjectStore(storeName);\n }\n },\n });\n\n // Get the blob from the store\n const blob = await db.get(storeName, key);\n if (!blob) {\n console.error(`File with key \"${key}\" not found in store \"${storeName}\" in database \"${database}\"`);\n return null;\n }\n\n // Convert the Blob to a File object\n return new File([blob], key, { type: blob.type });\n } catch (error) {\n console.error('Error retrieving file from IndexedDB:', error);\n return null;\n }\n }\n\n // Retrieve the file from the system (local file)\n private async getFileFromSystem(filePath: string): Promise<File | null> {\n try {\n // This is a simplified version. In a real-world scenario,\n // you might need to handle different types of paths or use a file system API.\n const response = await fetch(filePath);\n const blob = await response.blob();\n return new File([blob], filePath.split('/').pop() || 'file', {\n type: blob.type,\n });\n } catch (error) {\n console.error('Error getting file from system:', error);\n return null;\n }\n }\n\n async getPluginVersion(): Promise<{ version: string }> {\n return { version: 'web' };\n }\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -1,11 +1,33 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var core = require('@capacitor/core');
|
|
4
|
+
var idb = require('idb');
|
|
4
5
|
|
|
5
6
|
const Uploader = core.registerPlugin('Uploader', {
|
|
6
7
|
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.UploaderWeb()),
|
|
7
8
|
});
|
|
8
9
|
|
|
10
|
+
class PathHelper {
|
|
11
|
+
// Check if the path follows the idb://[databaseName]/[storeName]/[key] format
|
|
12
|
+
static isIndexedDBPath(path) {
|
|
13
|
+
const regex = /^idb:\/\/([^/]+)\/([^/]+)\/(.+)$/;
|
|
14
|
+
return regex.test(path);
|
|
15
|
+
}
|
|
16
|
+
// Parse the path to extract database, storeName, and key
|
|
17
|
+
static parseIndexedDBPath(path) {
|
|
18
|
+
const regex = /^idb:\/\/([^/]+)\/([^/]+)\/(.+)$/;
|
|
19
|
+
const match = path.match(regex);
|
|
20
|
+
if (!match) {
|
|
21
|
+
throw new Error('Invalid IndexedDB path format');
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
database: match[1],
|
|
25
|
+
storeName: match[2],
|
|
26
|
+
key: match[3],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
9
31
|
class UploaderWeb extends core.WebPlugin {
|
|
10
32
|
constructor() {
|
|
11
33
|
super(...arguments);
|
|
@@ -81,9 +103,45 @@ class UploaderWeb extends core.WebPlugin {
|
|
|
81
103
|
}
|
|
82
104
|
}
|
|
83
105
|
async getFileFromPath(filePath) {
|
|
84
|
-
//
|
|
85
|
-
|
|
106
|
+
// Check if the path is an IndexedDB path
|
|
107
|
+
if (PathHelper.isIndexedDBPath(filePath)) {
|
|
108
|
+
return this.getFileFromIndexedDB(filePath);
|
|
109
|
+
}
|
|
110
|
+
// Otherwise, treat it as a file path from the system
|
|
111
|
+
return this.getFileFromSystem(filePath);
|
|
112
|
+
}
|
|
113
|
+
// Retrieve the file from IndexedDB
|
|
114
|
+
async getFileFromIndexedDB(filePath) {
|
|
115
|
+
// Parse the path to get the database, store name, and key
|
|
116
|
+
const { database, storeName, key } = PathHelper.parseIndexedDBPath(filePath);
|
|
117
|
+
try {
|
|
118
|
+
// Open the IndexedDB database and access the object store
|
|
119
|
+
const db = await idb.openDB(database, 1, {
|
|
120
|
+
upgrade(db) {
|
|
121
|
+
if (!db.objectStoreNames.contains(storeName)) {
|
|
122
|
+
db.createObjectStore(storeName);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
// Get the blob from the store
|
|
127
|
+
const blob = await db.get(storeName, key);
|
|
128
|
+
if (!blob) {
|
|
129
|
+
console.error(`File with key "${key}" not found in store "${storeName}" in database "${database}"`);
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
// Convert the Blob to a File object
|
|
133
|
+
return new File([blob], key, { type: blob.type });
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
console.error('Error retrieving file from IndexedDB:', error);
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Retrieve the file from the system (local file)
|
|
141
|
+
async getFileFromSystem(filePath) {
|
|
86
142
|
try {
|
|
143
|
+
// This is a simplified version. In a real-world scenario,
|
|
144
|
+
// you might need to handle different types of paths or use a file system API.
|
|
87
145
|
const response = await fetch(filePath);
|
|
88
146
|
const blob = await response.blob();
|
|
89
147
|
return new File([blob], filePath.split('/').pop() || 'file', {
|
|
@@ -91,7 +149,7 @@ class UploaderWeb extends core.WebPlugin {
|
|
|
91
149
|
});
|
|
92
150
|
}
|
|
93
151
|
catch (error) {
|
|
94
|
-
console.error('Error getting file:', error);
|
|
152
|
+
console.error('Error getting file from system:', error);
|
|
95
153
|
return null;
|
|
96
154
|
}
|
|
97
155
|
}
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Uploader = registerPlugin('Uploader', {\n web: () => import('./web').then((m) => new m.UploaderWeb()),\n});\nexport * from './definitions';\nexport { Uploader };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class UploaderWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.uploads = new Map();\n }\n async startUpload(options) {\n console.log('startUpload', options);\n const id = Math.random().toString(36).substring(2, 15);\n const controller = new AbortController();\n const maxRetries = options.maxRetries || 3;\n this.uploads.set(id, { controller, retries: maxRetries });\n this.doUpload(id, options);\n return { id };\n }\n async removeUpload(options) {\n console.log('removeUpload', options);\n const upload = this.uploads.get(options.id);\n if (upload) {\n upload.controller.abort();\n this.uploads.delete(options.id);\n this.notifyListeners('events', {\n name: 'cancelled',\n id: options.id,\n payload: {},\n });\n }\n }\n async doUpload(id, options) {\n const { filePath, serverUrl, headers = {}, method = 'POST', parameters = {} } = options;\n const upload = this.uploads.get(id);\n if (!upload)\n return;\n try {\n const file = await this.getFileFromPath(filePath);\n if (!file)\n throw new Error('File not found');\n const formData = new FormData();\n formData.append('file', file);\n for (const [key, value] of Object.entries(parameters)) {\n formData.append(key, value);\n }\n const response = await fetch(serverUrl, {\n method,\n headers,\n body: method === 'PUT' ? file : formData,\n signal: upload.controller.signal,\n });\n if (!response.ok)\n throw new Error(`HTTP error! status: ${response.status}`);\n this.notifyListeners('events', {\n name: 'completed',\n id,\n payload: { statusCode: response.status },\n });\n this.uploads.delete(id);\n }\n catch (error) {\n if (error.name === 'AbortError')\n return;\n if (upload.retries > 0) {\n upload.retries--;\n console.log(`Retrying upload (retries left: ${upload.retries})`);\n setTimeout(() => this.doUpload(id, options), 1000);\n }\n else {\n this.notifyListeners('events', {\n name: 'failed',\n id,\n payload: { error: error.message },\n });\n this.uploads.delete(id);\n }\n }\n }\n async getFileFromPath(filePath) {\n // This is a simplified version. In a real-world scenario,\n // you might need to handle different types of paths or use a file system API.\n try {\n const response = await fetch(filePath);\n const blob = await response.blob();\n return new File([blob], filePath.split('/').pop() || 'file', {\n type: blob.type,\n });\n }\n catch (error) {\n console.error('Error getting file:', error);\n return null;\n }\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,QAAQ,GAAGA,mBAAc,CAAC,UAAU,EAAE;AAC5C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;AAC/D,CAAC;;ACFM,MAAM,WAAW,SAASC,cAAS,CAAC;AAC3C,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;AAC3B,QAAQ,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE;AAChC,IAAI;AACJ,IAAI,MAAM,WAAW,CAAC,OAAO,EAAE;AAC/B,QAAQ,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,OAAO,CAAC;AAC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IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;AACjC,IAAI;AACJ;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/PathHelper.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Uploader = registerPlugin('Uploader', {\n web: () => import('./web').then((m) => new m.UploaderWeb()),\n});\nexport * from './definitions';\nexport { Uploader };\n//# sourceMappingURL=index.js.map","export class PathHelper {\n // Check if the path follows the idb://[databaseName]/[storeName]/[key] format\n static isIndexedDBPath(path) {\n const regex = /^idb:\\/\\/([^/]+)\\/([^/]+)\\/(.+)$/;\n return regex.test(path);\n }\n // Parse the path to extract database, storeName, and key\n static parseIndexedDBPath(path) {\n const regex = /^idb:\\/\\/([^/]+)\\/([^/]+)\\/(.+)$/;\n const match = path.match(regex);\n if (!match) {\n throw new Error('Invalid IndexedDB path format');\n }\n return {\n database: match[1],\n storeName: match[2],\n key: match[3],\n };\n }\n}\n//# sourceMappingURL=PathHelper.js.map","import { WebPlugin } from '@capacitor/core';\nimport { openDB } from 'idb';\nimport { PathHelper } from './PathHelper';\nexport class UploaderWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.uploads = new Map();\n }\n async startUpload(options) {\n console.log('startUpload', options);\n const id = Math.random().toString(36).substring(2, 15);\n const controller = new AbortController();\n const maxRetries = options.maxRetries || 3;\n this.uploads.set(id, { controller, retries: maxRetries });\n this.doUpload(id, options);\n return { id };\n }\n async removeUpload(options) {\n console.log('removeUpload', options);\n const upload = this.uploads.get(options.id);\n if (upload) {\n upload.controller.abort();\n this.uploads.delete(options.id);\n this.notifyListeners('events', {\n name: 'cancelled',\n id: options.id,\n payload: {},\n });\n }\n }\n async doUpload(id, options) {\n const { filePath, serverUrl, headers = {}, method = 'POST', parameters = {} } = options;\n const upload = this.uploads.get(id);\n if (!upload)\n return;\n try {\n const file = await this.getFileFromPath(filePath);\n if (!file)\n throw new Error('File not found');\n const formData = new FormData();\n formData.append('file', file);\n for (const [key, value] of Object.entries(parameters)) {\n formData.append(key, value);\n }\n const response = await fetch(serverUrl, {\n method,\n headers,\n body: method === 'PUT' ? file : formData,\n signal: upload.controller.signal,\n });\n if (!response.ok)\n throw new Error(`HTTP error! status: ${response.status}`);\n this.notifyListeners('events', {\n name: 'completed',\n id,\n payload: { statusCode: response.status },\n });\n this.uploads.delete(id);\n }\n catch (error) {\n if (error.name === 'AbortError')\n return;\n if (upload.retries > 0) {\n upload.retries--;\n console.log(`Retrying upload (retries left: ${upload.retries})`);\n setTimeout(() => this.doUpload(id, options), 1000);\n }\n else {\n this.notifyListeners('events', {\n name: 'failed',\n id,\n payload: { error: error.message },\n });\n this.uploads.delete(id);\n }\n }\n }\n async getFileFromPath(filePath) {\n // Check if the path is an IndexedDB path\n if (PathHelper.isIndexedDBPath(filePath)) {\n return this.getFileFromIndexedDB(filePath);\n }\n // Otherwise, treat it as a file path from the system\n return this.getFileFromSystem(filePath);\n }\n // Retrieve the file from IndexedDB\n async getFileFromIndexedDB(filePath) {\n // Parse the path to get the database, store name, and key\n const { database, storeName, key } = PathHelper.parseIndexedDBPath(filePath);\n try {\n // Open the IndexedDB database and access the object store\n const db = await openDB(database, 1, {\n upgrade(db) {\n if (!db.objectStoreNames.contains(storeName)) {\n db.createObjectStore(storeName);\n }\n },\n });\n // Get the blob from the store\n const blob = await db.get(storeName, key);\n if (!blob) {\n console.error(`File with key \"${key}\" not found in store \"${storeName}\" in database \"${database}\"`);\n return null;\n }\n // Convert the Blob to a File object\n return new File([blob], key, { type: blob.type });\n }\n catch (error) {\n console.error('Error retrieving file from IndexedDB:', error);\n return null;\n }\n }\n // Retrieve the file from the system (local file)\n async getFileFromSystem(filePath) {\n try {\n // This is a simplified version. In a real-world scenario,\n // you might need to handle different types of paths or use a file system API.\n const response = await fetch(filePath);\n const blob = await response.blob();\n return new File([blob], filePath.split('/').pop() || 'file', {\n type: blob.type,\n });\n }\n catch (error) {\n console.error('Error getting file from system:', error);\n return null;\n }\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","openDB"],"mappings":";;;;;AACK,MAAC,QAAQ,GAAGA,mBAAc,CAAC,UAAU,EAAE;AAC5C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;AAC/D,CAAC;;ACHM,MAAM,UAAU,CAAC;AACxB;AACA,IAAI,OAAO,eAAe,CAAC,IAAI,EAAE;AACjC,QAAQ,MAAM,KAAK,GAAG,kCAAkC;AACxD,QAAQ,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;AAC/B,IAAI;AACJ;AACA,IAAI,OAAO,kBAAkB,CAAC,IAAI,EAAE;AACpC,QAAQ,MAAM,KAAK,GAAG,kCAAkC;AACxD,QAAQ,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;AACvC,QAAQ,IAAI,CAAC,KAAK,EAAE;AACpB,YAAY,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC;AAC5D,QAAQ;AACR,QAAQ,OAAO;AACf,YAAY,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;AAC9B,YAAY,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;AAC/B,YAAY,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;AACzB,SAAS;AACT,IAAI;AACJ;;AChBO,MAAM,WAAW,SAASC,cAAS,CAAC;AAC3C,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;AAC3B,QAAQ,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE;AAChC,IAAI;AACJ,IAAI,MAAM,WAAW,CAAC,OAAO,EAAE;AAC/B,QAAQ,OAAO,CAAC,GAAG,CAAC,aAAa,EA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Q,OAAO,KAAK,EAAE;AACtB,YAAY,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC;AACnE,YAAY,OAAO,IAAI;AACvB,QAAQ;AACR,IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;AACjC,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,10 +1,31 @@
|
|
|
1
|
-
var capacitorCapacitorUpdater = (function (exports, core) {
|
|
1
|
+
var capacitorCapacitorUpdater = (function (exports, core, idb) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const Uploader = core.registerPlugin('Uploader', {
|
|
5
5
|
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.UploaderWeb()),
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
+
class PathHelper {
|
|
9
|
+
// Check if the path follows the idb://[databaseName]/[storeName]/[key] format
|
|
10
|
+
static isIndexedDBPath(path) {
|
|
11
|
+
const regex = /^idb:\/\/([^/]+)\/([^/]+)\/(.+)$/;
|
|
12
|
+
return regex.test(path);
|
|
13
|
+
}
|
|
14
|
+
// Parse the path to extract database, storeName, and key
|
|
15
|
+
static parseIndexedDBPath(path) {
|
|
16
|
+
const regex = /^idb:\/\/([^/]+)\/([^/]+)\/(.+)$/;
|
|
17
|
+
const match = path.match(regex);
|
|
18
|
+
if (!match) {
|
|
19
|
+
throw new Error('Invalid IndexedDB path format');
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
database: match[1],
|
|
23
|
+
storeName: match[2],
|
|
24
|
+
key: match[3],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
8
29
|
class UploaderWeb extends core.WebPlugin {
|
|
9
30
|
constructor() {
|
|
10
31
|
super(...arguments);
|
|
@@ -80,9 +101,45 @@ var capacitorCapacitorUpdater = (function (exports, core) {
|
|
|
80
101
|
}
|
|
81
102
|
}
|
|
82
103
|
async getFileFromPath(filePath) {
|
|
83
|
-
//
|
|
84
|
-
|
|
104
|
+
// Check if the path is an IndexedDB path
|
|
105
|
+
if (PathHelper.isIndexedDBPath(filePath)) {
|
|
106
|
+
return this.getFileFromIndexedDB(filePath);
|
|
107
|
+
}
|
|
108
|
+
// Otherwise, treat it as a file path from the system
|
|
109
|
+
return this.getFileFromSystem(filePath);
|
|
110
|
+
}
|
|
111
|
+
// Retrieve the file from IndexedDB
|
|
112
|
+
async getFileFromIndexedDB(filePath) {
|
|
113
|
+
// Parse the path to get the database, store name, and key
|
|
114
|
+
const { database, storeName, key } = PathHelper.parseIndexedDBPath(filePath);
|
|
115
|
+
try {
|
|
116
|
+
// Open the IndexedDB database and access the object store
|
|
117
|
+
const db = await idb.openDB(database, 1, {
|
|
118
|
+
upgrade(db) {
|
|
119
|
+
if (!db.objectStoreNames.contains(storeName)) {
|
|
120
|
+
db.createObjectStore(storeName);
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
// Get the blob from the store
|
|
125
|
+
const blob = await db.get(storeName, key);
|
|
126
|
+
if (!blob) {
|
|
127
|
+
console.error(`File with key "${key}" not found in store "${storeName}" in database "${database}"`);
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
// Convert the Blob to a File object
|
|
131
|
+
return new File([blob], key, { type: blob.type });
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
console.error('Error retrieving file from IndexedDB:', error);
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Retrieve the file from the system (local file)
|
|
139
|
+
async getFileFromSystem(filePath) {
|
|
85
140
|
try {
|
|
141
|
+
// This is a simplified version. In a real-world scenario,
|
|
142
|
+
// you might need to handle different types of paths or use a file system API.
|
|
86
143
|
const response = await fetch(filePath);
|
|
87
144
|
const blob = await response.blob();
|
|
88
145
|
return new File([blob], filePath.split('/').pop() || 'file', {
|
|
@@ -90,7 +147,7 @@ var capacitorCapacitorUpdater = (function (exports, core) {
|
|
|
90
147
|
});
|
|
91
148
|
}
|
|
92
149
|
catch (error) {
|
|
93
|
-
console.error('Error getting file:', error);
|
|
150
|
+
console.error('Error getting file from system:', error);
|
|
94
151
|
return null;
|
|
95
152
|
}
|
|
96
153
|
}
|
|
@@ -108,5 +165,5 @@ var capacitorCapacitorUpdater = (function (exports, core) {
|
|
|
108
165
|
|
|
109
166
|
return exports;
|
|
110
167
|
|
|
111
|
-
})({}, capacitorExports);
|
|
168
|
+
})({}, capacitorExports, idb);
|
|
112
169
|
//# sourceMappingURL=plugin.js.map
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Uploader = registerPlugin('Uploader', {\n web: () => import('./web').then((m) => new m.UploaderWeb()),\n});\nexport * from './definitions';\nexport { Uploader };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class UploaderWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.uploads = new Map();\n }\n async startUpload(options) {\n console.log('startUpload', options);\n const id = Math.random().toString(36).substring(2, 15);\n const controller = new AbortController();\n const maxRetries = options.maxRetries || 3;\n this.uploads.set(id, { controller, retries: maxRetries });\n this.doUpload(id, options);\n return { id };\n }\n async removeUpload(options) {\n console.log('removeUpload', options);\n const upload = this.uploads.get(options.id);\n if (upload) {\n upload.controller.abort();\n this.uploads.delete(options.id);\n this.notifyListeners('events', {\n name: 'cancelled',\n id: options.id,\n payload: {},\n });\n }\n }\n async doUpload(id, options) {\n const { filePath, serverUrl, headers = {}, method = 'POST', parameters = {} } = options;\n const upload = this.uploads.get(id);\n if (!upload)\n return;\n try {\n const file = await this.getFileFromPath(filePath);\n if (!file)\n throw new Error('File not found');\n const formData = new FormData();\n formData.append('file', file);\n for (const [key, value] of Object.entries(parameters)) {\n formData.append(key, value);\n }\n const response = await fetch(serverUrl, {\n method,\n headers,\n body: method === 'PUT' ? file : formData,\n signal: upload.controller.signal,\n });\n if (!response.ok)\n throw new Error(`HTTP error! status: ${response.status}`);\n this.notifyListeners('events', {\n name: 'completed',\n id,\n payload: { statusCode: response.status },\n });\n this.uploads.delete(id);\n }\n catch (error) {\n if (error.name === 'AbortError')\n return;\n if (upload.retries > 0) {\n upload.retries--;\n console.log(`Retrying upload (retries left: ${upload.retries})`);\n setTimeout(() => this.doUpload(id, options), 1000);\n }\n else {\n this.notifyListeners('events', {\n name: 'failed',\n id,\n payload: { error: error.message },\n });\n this.uploads.delete(id);\n }\n }\n }\n async getFileFromPath(filePath) {\n // This is a simplified version. In a real-world scenario,\n // you might need to handle different types of paths or use a file system API.\n try {\n const response = await fetch(filePath);\n const blob = await response.blob();\n return new File([blob], filePath.split('/').pop() || 'file', {\n type: blob.type,\n });\n }\n catch (error) {\n console.error('Error getting file:', error);\n return null;\n }\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,QAAQ,GAAGA,mBAAc,CAAC,UAAU,EAAE;IAC5C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/D,CAAC;;ICFM,MAAM,WAAW,SAASC,cAAS,CAAC;IAC3C,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;IAC3B,QAAQ,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE;IAChC,IAAI;IACJ,IAAI,MAAM,WAAW,CAAC,OAAO,EAAE;IAC/B,QAAQ,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,OAAO,CAAC;IAC3C,QAAQ,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC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EAAE,KAAK,EAAE;IACjC,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/PathHelper.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Uploader = registerPlugin('Uploader', {\n web: () => import('./web').then((m) => new m.UploaderWeb()),\n});\nexport * from './definitions';\nexport { Uploader };\n//# sourceMappingURL=index.js.map","export class PathHelper {\n // Check if the path follows the idb://[databaseName]/[storeName]/[key] format\n static isIndexedDBPath(path) {\n const regex = /^idb:\\/\\/([^/]+)\\/([^/]+)\\/(.+)$/;\n return regex.test(path);\n }\n // Parse the path to extract database, storeName, and key\n static parseIndexedDBPath(path) {\n const regex = /^idb:\\/\\/([^/]+)\\/([^/]+)\\/(.+)$/;\n const match = path.match(regex);\n if (!match) {\n throw new Error('Invalid IndexedDB path format');\n }\n return {\n database: match[1],\n storeName: match[2],\n key: match[3],\n };\n }\n}\n//# sourceMappingURL=PathHelper.js.map","import { WebPlugin } from '@capacitor/core';\nimport { openDB } from 'idb';\nimport { PathHelper } from './PathHelper';\nexport class UploaderWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.uploads = new Map();\n }\n async startUpload(options) {\n console.log('startUpload', options);\n const id = Math.random().toString(36).substring(2, 15);\n const controller = new AbortController();\n const maxRetries = options.maxRetries || 3;\n this.uploads.set(id, { controller, retries: maxRetries });\n this.doUpload(id, options);\n return { id };\n }\n async removeUpload(options) {\n console.log('removeUpload', options);\n const upload = this.uploads.get(options.id);\n if (upload) {\n upload.controller.abort();\n this.uploads.delete(options.id);\n this.notifyListeners('events', {\n name: 'cancelled',\n id: options.id,\n payload: {},\n });\n }\n }\n async doUpload(id, options) {\n const { filePath, serverUrl, headers = {}, method = 'POST', parameters = {} } = options;\n const upload = this.uploads.get(id);\n if (!upload)\n return;\n try {\n const file = await this.getFileFromPath(filePath);\n if (!file)\n throw new Error('File not found');\n const formData = new FormData();\n formData.append('file', file);\n for (const [key, value] of Object.entries(parameters)) {\n formData.append(key, value);\n }\n const response = await fetch(serverUrl, {\n method,\n headers,\n body: method === 'PUT' ? file : formData,\n signal: upload.controller.signal,\n });\n if (!response.ok)\n throw new Error(`HTTP error! status: ${response.status}`);\n this.notifyListeners('events', {\n name: 'completed',\n id,\n payload: { statusCode: response.status },\n });\n this.uploads.delete(id);\n }\n catch (error) {\n if (error.name === 'AbortError')\n return;\n if (upload.retries > 0) {\n upload.retries--;\n console.log(`Retrying upload (retries left: ${upload.retries})`);\n setTimeout(() => this.doUpload(id, options), 1000);\n }\n else {\n this.notifyListeners('events', {\n name: 'failed',\n id,\n payload: { error: error.message },\n });\n this.uploads.delete(id);\n }\n }\n }\n async getFileFromPath(filePath) {\n // Check if the path is an IndexedDB path\n if (PathHelper.isIndexedDBPath(filePath)) {\n return this.getFileFromIndexedDB(filePath);\n }\n // Otherwise, treat it as a file path from the system\n return this.getFileFromSystem(filePath);\n }\n // Retrieve the file from IndexedDB\n async getFileFromIndexedDB(filePath) {\n // Parse the path to get the database, store name, and key\n const { database, storeName, key } = PathHelper.parseIndexedDBPath(filePath);\n try {\n // Open the IndexedDB database and access the object store\n const db = await openDB(database, 1, {\n upgrade(db) {\n if (!db.objectStoreNames.contains(storeName)) {\n db.createObjectStore(storeName);\n }\n },\n });\n // Get the blob from the store\n const blob = await db.get(storeName, key);\n if (!blob) {\n console.error(`File with key \"${key}\" not found in store \"${storeName}\" in database \"${database}\"`);\n return null;\n }\n // Convert the Blob to a File object\n return new File([blob], key, { type: blob.type });\n }\n catch (error) {\n console.error('Error retrieving file from IndexedDB:', error);\n return null;\n }\n }\n // Retrieve the file from the system (local file)\n async getFileFromSystem(filePath) {\n try {\n // This is a simplified version. In a real-world scenario,\n // you might need to handle different types of paths or use a file system API.\n const response = await fetch(filePath);\n const blob = await response.blob();\n return new File([blob], filePath.split('/').pop() || 'file', {\n type: blob.type,\n });\n }\n catch (error) {\n console.error('Error getting file from system:', error);\n return null;\n }\n }\n async getP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,KAAK,CAAC;IACnE,YAAY,OAAO,IAAI;IACvB,QAAQ;IACR,IAAI;IACJ,IAAI,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;IACjC,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -3,7 +3,7 @@ import Capacitor
|
|
|
3
3
|
|
|
4
4
|
@objc(UploaderPlugin)
|
|
5
5
|
public class UploaderPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
6
|
-
private let pluginVersion: String = "8.
|
|
6
|
+
private let pluginVersion: String = "8.1.1"
|
|
7
7
|
public let identifier = "UploaderPlugin"
|
|
8
8
|
public let jsName = "Uploader"
|
|
9
9
|
public let pluginMethods: [CAPPluginMethod] = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/capacitor-uploader",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.1.1",
|
|
4
4
|
"description": "Upload file natively",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -61,7 +61,8 @@
|
|
|
61
61
|
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
62
62
|
"clean": "rimraf ./dist",
|
|
63
63
|
"watch": "tsc --watch",
|
|
64
|
-
"prepublishOnly": "npm run build"
|
|
64
|
+
"prepublishOnly": "npm run build",
|
|
65
|
+
"check:wiring": "node scripts/check-capacitor-plugin-wiring.mjs"
|
|
65
66
|
},
|
|
66
67
|
"devDependencies": {
|
|
67
68
|
"@capacitor/android": "^8.0.0",
|
|
@@ -99,5 +100,8 @@
|
|
|
99
100
|
"android": {
|
|
100
101
|
"src": "android"
|
|
101
102
|
}
|
|
103
|
+
},
|
|
104
|
+
"dependencies": {
|
|
105
|
+
"idb": "^8.0.2"
|
|
102
106
|
}
|
|
103
107
|
}
|