@capacitor/filesystem 6.0.2-nightly-20240905T150509.0 → 6.0.3
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/Package.swift
CHANGED
|
@@ -10,7 +10,7 @@ let package = Package(
|
|
|
10
10
|
targets: ["FilesystemPlugin"])
|
|
11
11
|
],
|
|
12
12
|
dependencies: [
|
|
13
|
-
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git",
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "6.0.0")
|
|
14
14
|
],
|
|
15
15
|
targets: [
|
|
16
16
|
.target(
|
|
@@ -3,6 +3,8 @@ package com.capacitorjs.plugins.filesystem;
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
import android.net.Uri;
|
|
5
5
|
import android.os.Environment;
|
|
6
|
+
import android.os.Handler;
|
|
7
|
+
import android.os.Looper;
|
|
6
8
|
import android.util.Base64;
|
|
7
9
|
import com.capacitorjs.plugins.filesystem.exceptions.CopyFailedException;
|
|
8
10
|
import com.capacitorjs.plugins.filesystem.exceptions.DirectoryExistsException;
|
|
@@ -27,6 +29,8 @@ import java.nio.channels.FileChannel;
|
|
|
27
29
|
import java.nio.charset.Charset;
|
|
28
30
|
import java.nio.charset.StandardCharsets;
|
|
29
31
|
import java.util.Locale;
|
|
32
|
+
import java.util.concurrent.ExecutorService;
|
|
33
|
+
import java.util.concurrent.Executors;
|
|
30
34
|
import org.json.JSONException;
|
|
31
35
|
|
|
32
36
|
public class Filesystem {
|
|
@@ -303,9 +307,32 @@ public class Filesystem {
|
|
|
303
307
|
}
|
|
304
308
|
}
|
|
305
309
|
|
|
306
|
-
public
|
|
307
|
-
|
|
310
|
+
public void downloadFile(
|
|
311
|
+
PluginCall call,
|
|
312
|
+
Bridge bridge,
|
|
313
|
+
HttpRequestHandler.ProgressEmitter emitter,
|
|
314
|
+
FilesystemDownloadCallback callback
|
|
315
|
+
) {
|
|
308
316
|
String urlString = call.getString("url", "");
|
|
317
|
+
ExecutorService executor = Executors.newSingleThreadExecutor();
|
|
318
|
+
Handler handler = new Handler(Looper.getMainLooper());
|
|
319
|
+
|
|
320
|
+
executor.execute(
|
|
321
|
+
() -> {
|
|
322
|
+
try {
|
|
323
|
+
JSObject result = doDownloadInBackground(urlString, call, bridge, emitter);
|
|
324
|
+
handler.post(() -> callback.onSuccess(result));
|
|
325
|
+
} catch (Exception error) {
|
|
326
|
+
handler.post(() -> callback.onError(error));
|
|
327
|
+
} finally {
|
|
328
|
+
executor.shutdown();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
private JSObject doDownloadInBackground(String urlString, PluginCall call, Bridge bridge, HttpRequestHandler.ProgressEmitter emitter)
|
|
335
|
+
throws IOException, URISyntaxException, JSONException {
|
|
309
336
|
JSObject headers = call.getObject("headers", new JSObject());
|
|
310
337
|
JSObject params = call.getObject("params", new JSObject());
|
|
311
338
|
Integer connectTimeout = call.getInt("connectTimeout");
|
|
@@ -374,10 +401,14 @@ public class Filesystem {
|
|
|
374
401
|
connectionInputStream.close();
|
|
375
402
|
fileOutputStream.close();
|
|
376
403
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
404
|
+
JSObject ret = new JSObject();
|
|
405
|
+
ret.put("path", file.getAbsolutePath());
|
|
406
|
+
return ret;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
public interface FilesystemDownloadCallback {
|
|
410
|
+
void onSuccess(JSObject result);
|
|
411
|
+
|
|
412
|
+
void onError(Exception error);
|
|
382
413
|
}
|
|
383
414
|
}
|
|
@@ -388,23 +388,37 @@ public class FilesystemPlugin extends Plugin {
|
|
|
388
388
|
|
|
389
389
|
if (isPublicDirectory(directory) && !isStoragePermissionGranted()) {
|
|
390
390
|
requestAllPermissions(call, "permissionCallback");
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
JSObject ret = new JSObject();
|
|
394
|
-
ret.put("url", call.getString("url"));
|
|
395
|
-
ret.put("bytes", bytes);
|
|
396
|
-
ret.put("contentLength", contentLength);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
397
393
|
|
|
398
|
-
|
|
399
|
-
|
|
394
|
+
HttpRequestHandler.ProgressEmitter emitter = (bytes, contentLength) -> {
|
|
395
|
+
JSObject ret = new JSObject();
|
|
396
|
+
ret.put("url", call.getString("url"));
|
|
397
|
+
ret.put("bytes", bytes);
|
|
398
|
+
ret.put("contentLength", contentLength);
|
|
399
|
+
notifyListeners("progress", ret);
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
implementation.downloadFile(
|
|
403
|
+
call,
|
|
404
|
+
bridge,
|
|
405
|
+
emitter,
|
|
406
|
+
new Filesystem.FilesystemDownloadCallback() {
|
|
407
|
+
@Override
|
|
408
|
+
public void onSuccess(JSObject response) {
|
|
409
|
+
// update mediaStore index only if file was written to external storage
|
|
410
|
+
if (isPublicDirectory(directory)) {
|
|
411
|
+
MediaScannerConnection.scanFile(getContext(), new String[] { response.getString("path") }, null, null);
|
|
412
|
+
}
|
|
413
|
+
call.resolve(response);
|
|
414
|
+
}
|
|
400
415
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
416
|
+
@Override
|
|
417
|
+
public void onError(Exception error) {
|
|
418
|
+
call.reject("Error downloading file: " + error.getLocalizedMessage(), error);
|
|
419
|
+
}
|
|
405
420
|
}
|
|
406
|
-
|
|
407
|
-
}
|
|
421
|
+
);
|
|
408
422
|
} catch (Exception ex) {
|
|
409
423
|
call.reject("Error downloading file: " + ex.getLocalizedMessage(), ex);
|
|
410
424
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor/filesystem",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.3",
|
|
4
4
|
"description": "The Filesystem API provides a NodeJS-like API for working with files on the device.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"publishConfig": {
|
|
82
82
|
"access": "public"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "adb1bbe6a8936f8fb388252c502a1ade0d30b60f"
|
|
85
85
|
}
|