Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

resolveLocalFileSystemURI.js 4.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. *
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. *
  20. */
  21. (function () {
  22. // For browser platform: not all browsers use overrided `resolveLocalFileSystemURL`.
  23. function checkBrowser () {
  24. if (cordova.platformId === 'browser' && require('./isChrome')()) { // eslint-disable-line no-undef
  25. module.exports.resolveLocalFileSystemURL = window.resolveLocalFileSystemURL || window.webkitResolveLocalFileSystemURL;
  26. return true;
  27. }
  28. return false;
  29. }
  30. if (checkBrowser()) {
  31. return;
  32. }
  33. var argscheck = require('cordova/argscheck');
  34. var DirectoryEntry = require('./DirectoryEntry');
  35. var FileEntry = require('./FileEntry');
  36. var FileError = require('./FileError');
  37. var exec = require('cordova/exec');
  38. var fileSystems = require('./fileSystems');
  39. /**
  40. * Look up file system Entry referred to by local URI.
  41. * @param {DOMString} uri URI referring to a local file or directory
  42. * @param successCallback invoked with Entry object corresponding to URI
  43. * @param errorCallback invoked if error occurs retrieving file system entry
  44. */
  45. module.exports.resolveLocalFileSystemURL = module.exports.resolveLocalFileSystemURL || function (uri, successCallback, errorCallback) {
  46. argscheck.checkArgs('sFF', 'resolveLocalFileSystemURI', arguments);
  47. // error callback
  48. var fail = function (error) {
  49. if (errorCallback) {
  50. errorCallback(new FileError(error));
  51. }
  52. };
  53. // sanity check for 'not:valid:filename' or '/not:valid:filename'
  54. // file.spec.12 window.resolveLocalFileSystemURI should error (ENCODING_ERR) when resolving invalid URI with leading /.
  55. if (!uri || uri.split(':').length > 2) {
  56. setTimeout(function () {
  57. fail(FileError.ENCODING_ERR);
  58. }, 0);
  59. return;
  60. }
  61. // if successful, return either a file or directory entry
  62. var success = function (entry) {
  63. if (entry) {
  64. if (successCallback) {
  65. // create appropriate Entry object
  66. var fsName = entry.filesystemName || (entry.filesystem && entry.filesystem.name) || (entry.filesystem === window.PERSISTENT ? 'persistent' : 'temporary'); // eslint-disable-line no-undef
  67. fileSystems.getFs(fsName, function (fs) {
  68. // This should happen only on platforms that haven't implemented requestAllFileSystems (windows)
  69. if (!fs) {
  70. fs = new FileSystem(fsName, {name: '', fullPath: '/'}); // eslint-disable-line no-undef
  71. }
  72. var result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath, fs, entry.nativeURL) : new FileEntry(entry.name, entry.fullPath, fs, entry.nativeURL);
  73. successCallback(result);
  74. });
  75. }
  76. } else {
  77. // no Entry object returned
  78. fail(FileError.NOT_FOUND_ERR);
  79. }
  80. };
  81. exec(success, fail, 'File', 'resolveLocalFileSystemURI', [uri]);
  82. };
  83. module.exports.resolveLocalFileSystemURI = function () {
  84. console.log('resolveLocalFileSystemURI is deprecated. Please call resolveLocalFileSystemURL instead.');
  85. module.exports.resolveLocalFileSystemURL.apply(this, arguments);
  86. };
  87. })();