You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by er...@apache.org on 2022/03/29 00:04:25 UTC

[cordova-plugin-file] branch master updated: fix(android): create toURL override to preserve other platforms (#516)

This is an automated email from the ASF dual-hosted git repository.

erisu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-file.git


The following commit(s) were added to refs/heads/master by this push:
     new 2ecccbf  fix(android): create toURL override to preserve other platforms (#516)
2ecccbf is described below

commit 2ecccbfde16ba3ec072c6249c9303896ad5ef234
Author: エリス <er...@users.noreply.github.com>
AuthorDate: Tue Mar 29 09:04:21 2022 +0900

    fix(android): create toURL override to preserve other platforms (#516)
---
 plugin.xml           |  3 +++
 www/Entry.js         | 11 +++++++----
 www/android/Entry.js | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/plugin.xml b/plugin.xml
index 0a2ee72..e8cc610 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -154,6 +154,9 @@ to config.xml in order for the application to find previously stored files.
         <framework src="androidx.webkit:webkit:$ANDROIDX_WEBKIT_VERSION" />
 
         <!-- android specific file apis -->
+        <js-module src="www/android/Entry.js" name="androidEntry">
+            <merges target="Entry" />
+        </js-module>
         <js-module src="www/android/FileSystem.js" name="androidFileSystem">
             <merges target="FileSystem" />
         </js-module>
diff --git a/www/Entry.js b/www/Entry.js
index c903537..a67be96 100644
--- a/www/Entry.js
+++ b/www/Entry.js
@@ -187,12 +187,15 @@ Entry.prototype.toInternalURL = function () {
 /**
  * Return a URL that can be used to identify this entry.
  * Use a URL that can be used to as the src attribute of a <video> or
- * <audio> tag. If that is not possible, construct a http(s)://(localhost) URL.
+ * <audio> tag. If that is not possible, construct a cdvfile:// URL.
  */
 Entry.prototype.toURL = function () {
-    return window.location.origin.includes('file://')
-        ? this.nativeURL
-        : this.toInternalURL();
+    if (this.nativeURL) {
+        return this.nativeURL;
+    }
+    // fullPath attribute may contain the full URL in the case that
+    // toInternalURL fails.
+    return this.toInternalURL() || 'file://localhost' + this.fullPath;
 };
 
 /**
diff --git a/www/android/Entry.js b/www/android/Entry.js
new file mode 100644
index 0000000..d9f180d
--- /dev/null
+++ b/www/android/Entry.js
@@ -0,0 +1,33 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+module.exports = {
+  /**
+   * Return a URL that can be used to identify this entry.
+   * Use a URL that can be used to as the src attribute of a <video> or
+   * <audio> tag. If that is not possible, construct a http(s)://(localhost) URL.
+   */
+  toURL: function () {
+    return window.location.origin.includes('file://')
+        ? this.nativeURL
+        : this.toInternalURL();
+  }
+};

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org