From a810d0248dd9f1099ce15809f8e1e75eedbff8e6 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 21 Sep 2020 18:11:51 +0200 Subject: plugins --- .../cordova-plugin-file/www/DirectoryEntry.js | 117 ++++++++ .../cordova-plugin-file/www/DirectoryReader.js | 72 +++++ .../plugins/cordova-plugin-file/www/Entry.js | 260 +++++++++++++++++ .../plugins/cordova-plugin-file/www/File.js | 78 +++++ .../plugins/cordova-plugin-file/www/FileEntry.js | 92 ++++++ .../plugins/cordova-plugin-file/www/FileError.js | 46 +++ .../plugins/cordova-plugin-file/www/FileReader.js | 298 +++++++++++++++++++ .../plugins/cordova-plugin-file/www/FileSystem.js | 55 ++++ .../cordova-plugin-file/www/FileUploadOptions.js | 41 +++ .../cordova-plugin-file/www/FileUploadResult.js | 30 ++ .../plugins/cordova-plugin-file/www/FileWriter.js | 325 +++++++++++++++++++++ .../plugins/cordova-plugin-file/www/Flags.js | 36 +++ .../cordova-plugin-file/www/LocalFileSystem.js | 23 ++ .../plugins/cordova-plugin-file/www/Metadata.js | 40 +++ .../cordova-plugin-file/www/ProgressEvent.js | 67 +++++ .../cordova-plugin-file/www/android/FileSystem.js | 48 +++ .../cordova-plugin-file/www/browser/FileSystem.js | 30 ++ .../cordova-plugin-file/www/browser/Preparing.js | 192 ++++++++++++ .../cordova-plugin-file/www/browser/isChrome.js | 26 ++ .../cordova-plugin-file/www/fileSystemPaths.js | 62 ++++ .../cordova-plugin-file/www/fileSystems-roots.js | 46 +++ .../plugins/cordova-plugin-file/www/fileSystems.js | 25 ++ .../cordova-plugin-file/www/ios/FileSystem.js | 29 ++ .../cordova-plugin-file/www/osx/FileSystem.js | 29 ++ .../cordova-plugin-file/www/requestFileSystem.js | 81 +++++ .../www/resolveLocalFileSystemURI.js | 91 ++++++ 26 files changed, 2239 insertions(+) create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/DirectoryEntry.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/DirectoryReader.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/Entry.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/File.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/FileEntry.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/FileError.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/FileReader.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/FileSystem.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/FileUploadOptions.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/FileUploadResult.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/FileWriter.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/Flags.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/LocalFileSystem.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/Metadata.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/ProgressEvent.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/android/FileSystem.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/browser/FileSystem.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/browser/Preparing.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/browser/isChrome.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/fileSystemPaths.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/fileSystems-roots.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/fileSystems.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/ios/FileSystem.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/osx/FileSystem.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/requestFileSystem.js create mode 100644 StoneIsland/plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js (limited to 'StoneIsland/plugins/cordova-plugin-file/www') diff --git a/StoneIsland/plugins/cordova-plugin-file/www/DirectoryEntry.js b/StoneIsland/plugins/cordova-plugin-file/www/DirectoryEntry.js new file mode 100644 index 00000000..d943f6d1 --- /dev/null +++ b/StoneIsland/plugins/cordova-plugin-file/www/DirectoryEntry.js @@ -0,0 +1,117 @@ +/* + * + * 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. + * +*/ + +var argscheck = require('cordova/argscheck'); +var utils = require('cordova/utils'); +var exec = require('cordova/exec'); +var Entry = require('./Entry'); +var FileError = require('./FileError'); +var DirectoryReader = require('./DirectoryReader'); + +/** + * An interface representing a directory on the file system. + * + * {boolean} isFile always false (readonly) + * {boolean} isDirectory always true (readonly) + * {DOMString} name of the directory, excluding the path leading to it (readonly) + * {DOMString} fullPath the absolute full path to the directory (readonly) + * {FileSystem} filesystem on which the directory resides (readonly) + */ +var DirectoryEntry = function (name, fullPath, fileSystem, nativeURL) { + + // add trailing slash if it is missing + if ((fullPath) && !/\/$/.test(fullPath)) { + fullPath += '/'; + } + // add trailing slash if it is missing + if (nativeURL && !/\/$/.test(nativeURL)) { + nativeURL += '/'; + } + DirectoryEntry.__super__.constructor.call(this, false, true, name, fullPath, fileSystem, nativeURL); +}; + +utils.extend(DirectoryEntry, Entry); + +/** + * Creates a new DirectoryReader to read entries from this directory + */ +DirectoryEntry.prototype.createReader = function () { + return new DirectoryReader(this.toInternalURL()); +}; + +/** + * Creates or looks up a directory + * + * @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a directory + * @param {Flags} options to create or exclusively create the directory + * @param {Function} successCallback is called with the new entry + * @param {Function} errorCallback is called with a FileError + */ +DirectoryEntry.prototype.getDirectory = function (path, options, successCallback, errorCallback) { + argscheck.checkArgs('sOFF', 'DirectoryEntry.getDirectory', arguments); + var fs = this.filesystem; + var win = successCallback && function (result) { + var entry = new DirectoryEntry(result.name, result.fullPath, fs, result.nativeURL); + successCallback(entry); + }; + var fail = errorCallback && function (code) { + errorCallback(new FileError(code)); + }; + exec(win, fail, 'File', 'getDirectory', [this.toInternalURL(), path, options]); +}; + +/** + * Deletes a directory and all of it's contents + * + * @param {Function} successCallback is called with no parameters + * @param {Function} errorCallback is called with a FileError + */ +DirectoryEntry.prototype.removeRecursively = function (successCallback, errorCallback) { + argscheck.checkArgs('FF', 'DirectoryEntry.removeRecursively', arguments); + var fail = errorCallback && function (code) { + errorCallback(new FileError(code)); + }; + exec(successCallback, fail, 'File', 'removeRecursively', [this.toInternalURL()]); +}; + +/** + * Creates or looks up a file + * + * @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a file + * @param {Flags} options to create or exclusively create the file + * @param {Function} successCallback is called with the new entry + * @param {Function} errorCallback is called with a FileError + */ +DirectoryEntry.prototype.getFile = function (path, options, successCallback, errorCallback) { + argscheck.checkArgs('sOFF', 'DirectoryEntry.getFile', arguments); + var fs = this.filesystem; + var win = successCallback && function (result) { + var FileEntry = require('./FileEntry'); + var entry = new FileEntry(result.name, result.fullPath, fs, result.nativeURL); + successCallback(entry); + }; + var fail = errorCallback && function (code) { + errorCallback(new FileError(code)); + }; + exec(win, fail, 'File', 'getFile', [this.toInternalURL(), path, options]); +}; + +module.exports = DirectoryEntry; diff --git a/StoneIsland/plugins/cordova-plugin-file/www/DirectoryReader.js b/StoneIsland/plugins/cordova-plugin-file/www/DirectoryReader.js new file mode 100644 index 00000000..73669533 --- /dev/null +++ b/StoneIsland/plugins/cordova-plugin-file/www/DirectoryReader.js @@ -0,0 +1,72 @@ +/* + * + * 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. + * +*/ + +var exec = require('cordova/exec'); +var FileError = require('./FileError'); + +/** + * An interface that lists the files and directories in a directory. + */ +function DirectoryReader (localURL) { + this.localURL = localURL || null; + this.hasReadEntries = false; +} + +/** + * Returns a list of entries from a directory. + * + * @param {Function} successCallback is called with a list of entries + * @param {Function} errorCallback is called with a FileError + */ +DirectoryReader.prototype.readEntries = function (successCallback, errorCallback) { + // If we've already read and passed on this directory's entries, return an empty list. + if (this.hasReadEntries) { + successCallback([]); + return; + } + var reader = this; + var win = typeof successCallback !== 'function' ? null : function (result) { + var retVal = []; + for (var i = 0; i < result.length; i++) { + var entry = null; + if (result[i].isDirectory) { + entry = new (require('./DirectoryEntry'))(); + } else if (result[i].isFile) { + entry = new (require('./FileEntry'))(); + } + entry.isDirectory = result[i].isDirectory; + entry.isFile = result[i].isFile; + entry.name = result[i].name; + entry.fullPath = result[i].fullPath; + entry.filesystem = new (require('./FileSystem'))(result[i].filesystemName); + entry.nativeURL = result[i].nativeURL; + retVal.push(entry); + } + reader.hasReadEntries = true; + successCallback(retVal); + }; + var fail = typeof errorCallback !== 'function' ? null : function (code) { + errorCallback(new FileError(code)); + }; + exec(win, fail, 'File', 'readEntries', [this.localURL]); +}; + +module.exports = DirectoryReader; diff --git a/StoneIsland/plugins/cordova-plugin-file/www/Entry.js b/StoneIsland/plugins/cordova-plugin-file/www/Entry.js new file mode 100644 index 00000000..8f7a9277 --- /dev/null +++ b/StoneIsland/plugins/cordova-plugin-file/www/Entry.js @@ -0,0 +1,260 @@ +/* + * + * 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. + * +*/ + +var argscheck = require('cordova/argscheck'); +var exec = require('cordova/exec'); +var FileError = require('./FileError'); +var Metadata = require('./Metadata'); + +/** + * Represents a file or directory on the local file system. + * + * @param isFile + * {boolean} true if Entry is a file (readonly) + * @param isDirectory + * {boolean} true if Entry is a directory (readonly) + * @param name + * {DOMString} name of the file or directory, excluding the path + * leading to it (readonly) + * @param fullPath + * {DOMString} the absolute full path to the file or directory + * (readonly) + * @param fileSystem + * {FileSystem} the filesystem on which this entry resides + * (readonly) + * @param nativeURL + * {DOMString} an alternate URL which can be used by native + * webview controls, for example media players. + * (optional, readonly) + */ +function Entry (isFile, isDirectory, name, fullPath, fileSystem, nativeURL) { + this.isFile = !!isFile; + this.isDirectory = !!isDirectory; + this.name = name || ''; + this.fullPath = fullPath || ''; + this.filesystem = fileSystem || null; + this.nativeURL = nativeURL || null; +} + +/** + * Look up the metadata of the entry. + * + * @param successCallback + * {Function} is called with a Metadata object + * @param errorCallback + * {Function} is called with a FileError + */ +Entry.prototype.getMetadata = function (successCallback, errorCallback) { + argscheck.checkArgs('FF', 'Entry.getMetadata', arguments); + var success = successCallback && function (entryMetadata) { + var metadata = new Metadata({ + size: entryMetadata.size, + modificationTime: entryMetadata.lastModifiedDate + }); + successCallback(metadata); + }; + var fail = errorCallback && function (code) { + errorCallback(new FileError(code)); + }; + exec(success, fail, 'File', 'getFileMetadata', [this.toInternalURL()]); +}; + +/** + * Set the metadata of the entry. + * + * @param successCallback + * {Function} is called with a Metadata object + * @param errorCallback + * {Function} is called with a FileError + * @param metadataObject + * {Object} keys and values to set + */ +Entry.prototype.setMetadata = function (successCallback, errorCallback, metadataObject) { + argscheck.checkArgs('FFO', 'Entry.setMetadata', arguments); + exec(successCallback, errorCallback, 'File', 'setMetadata', [this.toInternalURL(), metadataObject]); +}; + +/** + * Move a file or directory to a new location. + * + * @param parent + * {DirectoryEntry} the directory to which to move this entry + * @param newName + * {DOMString} new name of the entry, defaults to the current name + * @param successCallback + * {Function} called with the new DirectoryEntry object + * @param errorCallback + * {Function} called with a FileError + */ +Entry.prototype.moveTo = function (parent, newName, successCallback, errorCallback) { + argscheck.checkArgs('oSFF', 'Entry.moveTo', arguments); + var fail = errorCallback && function (code) { + errorCallback(new FileError(code)); + }; + var srcURL = this.toInternalURL(); + // entry name + var name = newName || this.name; + var success = function (entry) { + if (entry) { + if (successCallback) { + // create appropriate Entry object + var newFSName = entry.filesystemName || (entry.filesystem && entry.filesystem.name); + var fs = newFSName ? new FileSystem(newFSName, { name: '', fullPath: '/' }) : new FileSystem(parent.filesystem.name, { name: '', fullPath: '/' }); // eslint-disable-line no-undef + var result = (entry.isDirectory) ? new (require('./DirectoryEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL) : new (require('cordova-plugin-file.FileEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL); + successCallback(result); + } + } else { + // no Entry object returned + if (fail) { + fail(FileError.NOT_FOUND_ERR); + } + } + }; + + // copy + exec(success, fail, 'File', 'moveTo', [srcURL, parent.toInternalURL(), name]); +}; + +/** + * Copy a directory to a different location. + * + * @param parent + * {DirectoryEntry} the directory to which to copy the entry + * @param newName + * {DOMString} new name of the entry, defaults to the current name + * @param successCallback + * {Function} called with the new Entry object + * @param errorCallback + * {Function} called with a FileError + */ +Entry.prototype.copyTo = function (parent, newName, successCallback, errorCallback) { + argscheck.checkArgs('oSFF', 'Entry.copyTo', arguments); + var fail = errorCallback && function (code) { + errorCallback(new FileError(code)); + }; + var srcURL = this.toInternalURL(); + // entry name + var name = newName || this.name; + // success callback + var success = function (entry) { + if (entry) { + if (successCallback) { + // create appropriate Entry object + var newFSName = entry.filesystemName || (entry.filesystem && entry.filesystem.name); + var fs = newFSName ? new FileSystem(newFSName, { name: '', fullPath: '/' }) : new FileSystem(parent.filesystem.name, { name: '', fullPath: '/' }); // eslint-disable-line no-undef + var result = (entry.isDirectory) ? new (require('./DirectoryEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL) : new (require('cordova-plugin-file.FileEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL); + successCallback(result); + } + } else { + // no Entry object returned + if (fail) { + fail(FileError.NOT_FOUND_ERR); + } + } + }; + + // copy + exec(success, fail, 'File', 'copyTo', [srcURL, parent.toInternalURL(), name]); +}; + +/** + * Return a URL that can be passed across the bridge to identify this entry. + */ +Entry.prototype.toInternalURL = function () { + if (this.filesystem && this.filesystem.__format__) { + return this.filesystem.__format__(this.fullPath, this.nativeURL); + } +}; + +/** + * 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