{"version":3,"sources":["webpack:///./node_modules/@capacitor/filesystem/dist/esm/web.js"],"names":["resolve","path","posix","split","filter","item","newPosix","forEach","length","pop","push","join","isPathParent","parent","children","pathsA","pathsB","every","value","index","FilesystemWeb","super","arguments","this","DB_VERSION","DB_NAME","_writeCmds","undefined","_db","window","unavailable","Promise","reject","request","indexedDB","open","onupgradeneeded","doUpgrade","onsuccess","result","onerror","error","onblocked","console","warn","event","eventTarget","target","db","oldVersion","objectStoreNames","contains","deleteObjectStore","store","createObjectStore","keyPath","createIndex","cmd","args","readFlag","indexOf","initDb","then","conn","tx","transaction","objectStore","req","indexName","directory","uriPath","cleanedUriPath","replace","fsPath","clear","options","getPath","entry","dbRequest","Error","data","content","encoding","doRecursive","recursive","occupiedEntry","type","parentPath","substr","lastIndexOf","parentEntry","subDirIndex","parentArgPath","mkdir","isBase64String","now","Date","pathObj","folder","size","ctime","mtime","uri","btoa","atob","entries","dbIndexRequest","IDBKeyRange","only","depth","match","fullPath","readDirResult","readdir","files","entryPath","name","entryObj","stat","deleteFile","rmdir","all","map","async","e","subEntry","substring","_copy","publicStorage","doRename","toDirectory","to","from","fromDirectory","fromPath","toPath","toObj","toPathComponents","toParentDirectory","fromObj","updateTime","file","readFile","UTF8","writeResult","writeFile","contents","filename","str","err","_debug"],"mappings":"kHAAA,iFAEA,SAASA,EAAQC,GACb,MAAMC,EAAQD,EAAKE,MAAM,KAAKC,OAAOC,GAAiB,MAATA,GACvCC,EAAW,GAWjB,OAVAJ,EAAMK,QAAQF,IACG,OAATA,GACAC,EAASE,OAAS,GACgB,OAAlCF,EAASA,EAASE,OAAS,GAC3BF,EAASG,MAGTH,EAASI,KAAKL,KAGfC,EAASK,KAAK,KAEzB,SAASC,EAAaC,EAAQC,GAC1BD,EAASb,EAAQa,GACjBC,EAAWd,EAAQc,GACnB,MAAMC,EAASF,EAAOV,MAAM,KACtBa,EAASF,EAASX,MAAM,KAC9B,OAAQU,IAAWC,GACfC,EAAOE,MAAM,CAACC,EA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AAMC,QAAoBzH,KAAK0H,UAAU,CACrChJ,KAAMkI,EACN9D,UAAW6D,EACXlD,KAAM6D,EAAK7D,KACXE,SAAUA,IAOd,OAJI+C,SACMW,EAAWT,EAAI/B,EAAOuC,EAAQtC,OAGjC2C,EAEX,IAAK,YAAa,CACd,GAAIR,EACA,MAAMzD,MAAM,mDAEhB,UAEUxD,KAAKsE,MAAM,CACb5F,KAAMkI,EACN9D,UAAW6D,EACX9C,WAAW,IAGX6C,SACMW,EAAWT,EAAI/B,EAAOuC,EAAQtC,OAG5C,MAAOuB,IAIP,MAAMsB,SAAkB3H,KAAK0F,QAAQ,CACjChH,KAAMmI,EACN/D,UAAWgE,KACXnB,MACJ,IAAK,MAAMiC,KAAYD,QAEb3H,KAAKwG,MAAM,CACbK,KAAM,GAAGA,KAAQe,EAAS/B,OAC1Be,GAAI,GAAGA,KAAMgB,EAAS/B,OACtB/C,UAAWgE,EACXH,eACDD,GAGHA,SACM1G,KAAKiG,MAAM,CACbvH,KAAMmI,EACN/D,UAAWgE,KAK3B,MAAO,CACH/B,IAAKiC,GAGb,eAAea,GACX,IACI,OAAO7C,KAAKC,KAAK4C,KAASA,EAE9B,MAAOC,GACH,OAAO,IAInBjI,EAAckI,QAAS","file":"js/chunk-2d0a4885.a86f5b87.js","sourcesContent":["import { WebPlugin } from '@capacitor/core';\nimport { Encoding } from './definitions';\nfunction resolve(path) {\n const posix = path.split('/').filter(item => item !== '.');\n const newPosix = [];\n posix.forEach(item => {\n if (item === '..' &&\n newPosix.length > 0 &&\n newPosix[newPosix.length - 1] !== '..') {\n newPosix.pop();\n }\n else {\n newPosix.push(item);\n }\n });\n return newPosix.join('/');\n}\nfunction isPathParent(parent, children) {\n parent = resolve(parent);\n children = resolve(children);\n const pathsA = parent.split('/');\n const pathsB = children.split('/');\n return (parent !== children &&\n pathsA.every((value, index) => value === pathsB[index]));\n}\nexport class FilesystemWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.DB_VERSION = 1;\n this.DB_NAME = 'Disc';\n this._writeCmds = ['add', 'put', 'delete'];\n }\n async initDb() {\n if (this._db !== undefined) {\n return this._db;\n }\n if (!('indexedDB' in window)) {\n throw this.unavailable(\"This browser doesn't support IndexedDB\");\n }\n return new Promise((resolve, reject) => {\n const request = indexedDB.open(this.DB_NAME, this.DB_VERSION);\n request.onupgradeneeded = FilesystemWeb.doUpgrade;\n request.onsuccess = () => {\n this._db = request.result;\n resolve(request.result);\n };\n request.onerror = () => reject(request.error);\n request.onblocked = () => {\n console.warn('db blocked');\n };\n });\n }\n static doUpgrade(event) {\n const eventTarget = event.target;\n const db = eventTarget.result;\n switch (event.oldVersion) {\n case 0:\n case 1:\n default: {\n if (db.objectStoreNames.contains('FileStorage')) {\n db.deleteObjectStore('FileStorage');\n }\n const store = db.createObjectStore('FileStorage', { keyPath: 'path' });\n store.createIndex('by_folder', 'folder');\n }\n }\n }\n async dbRequest(cmd, args) {\n const readFlag = this._writeCmds.indexOf(cmd) !== -1 ? 'readwrite' : 'readonly';\n return this.initDb().then((conn) => {\n return new Promise((resolve, reject) => {\n const tx = conn.transaction(['FileStorage'], readFlag);\n const store = tx.objectStore('FileStorage');\n const req = store[cmd](...args);\n req.onsuccess = () => resolve(req.result);\n req.onerror = () => reject(req.error);\n });\n });\n }\n async dbIndexRequest(indexName, cmd, args) {\n const readFlag = this._writeCmds.indexOf(cmd) !== -1 ? 'readwrite' : 'readonly';\n return this.initDb().then((conn) => {\n return new Promise((resolve, reject) => {\n const tx = conn.transaction(['FileStorage'], readFlag);\n const store = tx.objectStore('FileStorage');\n const index = store.index(indexName);\n const req = index[cmd](...args);\n req.onsuccess = () => resolve(req.result);\n req.onerror = () => reject(req.error);\n });\n });\n }\n getPath(directory, uriPath) {\n const cleanedUriPath = uriPath !== undefined ? uriPath.replace(/^[/]+|[/]+$/g, '') : '';\n let fsPath = '';\n if (directory !== undefined)\n fsPath += '/' + directory;\n if (uriPath !== '')\n fsPath += '/' + cleanedUriPath;\n return fsPath;\n }\n async clear() {\n const conn = await this.initDb();\n const tx = conn.transaction(['FileStorage'], 'readwrite');\n const store = tx.objectStore('FileStorage');\n store.clear();\n }\n /**\n * Read a file from disk\n * @param options options for the file read\n * @return a promise that resolves with the read file data result\n */\n async readFile(options) {\n const path = this.getPath(options.directory, options.path);\n // const encoding = options.encoding;\n const entry = (await this.dbRequest('get', [path]));\n if (entry === undefined)\n throw Error('File does not exist.');\n return { data: entry.content ? entry.content : '' };\n }\n /**\n * Write a file to disk in the specified location on device\n * @param options options for the file write\n * @return a promise that resolves with the file write result\n */\n async writeFile(options) {\n const path = this.getPath(options.directory, options.path);\n let data = options.data;\n const encoding = options.encoding;\n const doRecursive = options.recursive;\n const occupiedEntry = (await this.dbRequest('get', [path]));\n if (occupiedEntry && occupiedEntry.type === 'directory')\n throw Error('The supplied path is a directory.');\n const parentPath = path.substr(0, path.lastIndexOf('/'));\n const parentEntry = (await this.dbRequest('get', [parentPath]));\n if (parentEntry === undefined) {\n const subDirIndex = parentPath.indexOf('/', 1);\n if (subDirIndex !== -1) {\n const parentArgPath = parentPath.substr(subDirIndex);\n await this.mkdir({\n path: parentArgPath,\n directory: options.directory,\n recursive: doRecursive,\n });\n }\n }\n if (!encoding) {\n data = data.indexOf(',') >= 0 ? data.split(',')[1] : data;\n if (!this.isBase64String(data))\n throw Error('The supplied data is not valid base64 content.');\n }\n const now = Date.now();\n const pathObj = {\n path: path,\n folder: parentPath,\n type: 'file',\n size: data.length,\n ctime: now,\n mtime: now,\n content: data,\n };\n await this.dbRequest('put', [pathObj]);\n return {\n uri: pathObj.path,\n };\n }\n /**\n * Append to a file on disk in the specified location on device\n * @param options options for the file append\n * @return a promise that resolves with the file write result\n */\n async appendFile(options) {\n const path = this.getPath(options.directory, options.path);\n let data = options.data;\n const encoding = options.encoding;\n const parentPath = path.substr(0, path.lastIndexOf('/'));\n const now = Date.now();\n let ctime = now;\n const occupiedEntry = (await this.dbRequest('get', [path]));\n if (occupiedEntry && occupiedEntry.type === 'directory')\n throw Error('The supplied path is a directory.');\n const parentEntry = (await this.dbRequest('get', [parentPath]));\n if (parentEntry === undefined) {\n const subDirIndex = parentPath.indexOf('/', 1);\n if (subDirIndex !== -1) {\n const parentArgPath = parentPath.substr(subDirIndex);\n await this.mkdir({\n path: parentArgPath,\n directory: options.directory,\n recursive: true,\n });\n }\n }\n if (!encoding && !this.isBase64String(data))\n throw Error('The supplied data is not valid base64 content.');\n if (occupiedEntry !== undefined) {\n if (occupiedEntry.content !== undefined && !encoding) {\n data = btoa(atob(occupiedEntry.content) + atob(data));\n }\n else {\n data = occupiedEntry.content + data;\n }\n ctime = occupiedEntry.ctime;\n }\n const pathObj = {\n path: path,\n folder: parentPath,\n type: 'file',\n size: data.length,\n ctime: ctime,\n mtime: now,\n content: data,\n };\n await this.dbRequest('put', [pathObj]);\n }\n /**\n * Delete a file from disk\n * @param options options for the file delete\n * @return a promise that resolves with the deleted file data result\n */\n async deleteFile(options) {\n const path = this.getPath(options.directory, options.path);\n const entry = (await this.dbRequest('get', [path]));\n if (entry === undefined)\n throw Error('File does not exist.');\n const entries = await this.dbIndexRequest('by_folder', 'getAllKeys', [\n IDBKeyRange.only(path),\n ]);\n if (entries.length !== 0)\n throw Error('Folder is not empty.');\n await this.dbRequest('delete', [path]);\n }\n /**\n * Create a directory.\n * @param options options for the mkdir\n * @return a promise that resolves with the mkdir result\n */\n async mkdir(options) {\n const path = this.getPath(options.directory, options.path);\n const doRecursive = options.recursive;\n const parentPath = path.substr(0, path.lastIndexOf('/'));\n const depth = (path.match(/\\//g) || []).length;\n const parentEntry = (await this.dbRequest('get', [parentPath]));\n const occupiedEntry = (await this.dbRequest('get', [path]));\n if (depth === 1)\n throw Error('Cannot create Root directory');\n if (occupiedEntry !== undefined)\n throw Error('Current directory does already exist.');\n if (!doRecursive && depth !== 2 && parentEntry === undefined)\n throw Error('Parent directory must exist');\n if (doRecursive && depth !== 2 && parentEntry === undefined) {\n const parentArgPath = parentPath.substr(parentPath.indexOf('/', 1));\n await this.mkdir({\n path: parentArgPath,\n directory: options.directory,\n recursive: doRecursive,\n });\n }\n const now = Date.now();\n const pathObj = {\n path: path,\n folder: parentPath,\n type: 'directory',\n size: 0,\n ctime: now,\n mtime: now,\n };\n await this.dbRequest('put', [pathObj]);\n }\n /**\n * Remove a directory\n * @param options the options for the directory remove\n */\n async rmdir(options) {\n const { path, directory, recursive } = options;\n const fullPath = this.getPath(directory, path);\n const entry = (await this.dbRequest('get', [fullPath]));\n if (entry === undefined)\n throw Error('Folder does not exist.');\n if (entry.type !== 'directory')\n throw Error('Requested path is not a directory');\n const readDirResult = await this.readdir({ path, directory });\n if (readDirResult.files.length !== 0 && !recursive)\n throw Error('Folder is not empty');\n for (const entry of readDirResult.files) {\n const entryPath = `${path}/${entry.name}`;\n const entryObj = await this.stat({ path: entryPath, directory });\n if (entryObj.type === 'file') {\n await this.deleteFile({ path: entryPath, directory });\n }\n else {\n await this.rmdir({ path: entryPath, directory, recursive });\n }\n }\n await this.dbRequest('delete', [fullPath]);\n }\n /**\n * Return a list of files from the directory (not recursive)\n * @param options the options for the readdir operation\n * @return a promise that resolves with the readdir directory listing result\n */\n async readdir(options) {\n const path = this.getPath(options.directory, options.path);\n const entry = (await this.dbRequest('get', [path]));\n if (options.path !== '' && entry === undefined)\n throw Error('Folder does not exist.');\n const entries = await this.dbIndexRequest('by_folder', 'getAllKeys', [IDBKeyRange.only(path)]);\n const files = await Promise.all(entries.map(async (e) => {\n let subEntry = (await this.dbRequest('get', [e]));\n if (subEntry === undefined) {\n subEntry = (await this.dbRequest('get', [e + '/']));\n }\n return {\n name: e.substring(path.length + 1),\n type: subEntry.type,\n size: subEntry.size,\n ctime: subEntry.ctime,\n mtime: subEntry.mtime,\n uri: subEntry.path,\n };\n }));\n return { files: files };\n }\n /**\n * Return full File URI for a path and directory\n * @param options the options for the stat operation\n * @return a promise that resolves with the file stat result\n */\n async getUri(options) {\n const path = this.getPath(options.directory, options.path);\n let entry = (await this.dbRequest('get', [path]));\n if (entry === undefined) {\n entry = (await this.dbRequest('get', [path + '/']));\n }\n return {\n uri: (entry === null || entry === void 0 ? void 0 : entry.path) || path,\n };\n }\n /**\n * Return data about a file\n * @param options the options for the stat operation\n * @return a promise that resolves with the file stat result\n */\n async stat(options) {\n const path = this.getPath(options.directory, options.path);\n let entry = (await this.dbRequest('get', [path]));\n if (entry === undefined) {\n entry = (await this.dbRequest('get', [path + '/']));\n }\n if (entry === undefined)\n throw Error('Entry does not exist.');\n return {\n type: entry.type,\n size: entry.size,\n ctime: entry.ctime,\n mtime: entry.mtime,\n uri: entry.path,\n };\n }\n /**\n * Rename a file or directory\n * @param options the options for the rename operation\n * @return a promise that resolves with the rename result\n */\n async rename(options) {\n await this._copy(options, true);\n return;\n }\n /**\n * Copy a file or directory\n * @param options the options for the copy operation\n * @return a promise that resolves with the copy result\n */\n async copy(options) {\n return this._copy(options, false);\n }\n async requestPermissions() {\n return { publicStorage: 'granted' };\n }\n async checkPermissions() {\n return { publicStorage: 'granted' };\n }\n /**\n * Function that can perform a copy or a rename\n * @param options the options for the rename operation\n * @param doRename whether to perform a rename or copy operation\n * @return a promise that resolves with the result\n */\n async _copy(options, doRename = false) {\n let { toDirectory } = options;\n const { to, from, directory: fromDirectory } = options;\n if (!to || !from) {\n throw Error('Both to and from must be provided');\n }\n // If no \"to\" directory is provided, use the \"from\" directory\n if (!toDirectory) {\n toDirectory = fromDirectory;\n }\n const fromPath = this.getPath(fromDirectory, from);\n const toPath = this.getPath(toDirectory, to);\n // Test that the \"to\" and \"from\" locations are different\n if (fromPath === toPath) {\n return {\n uri: toPath,\n };\n }\n if (isPathParent(fromPath, toPath)) {\n throw Error('To path cannot contain the from path');\n }\n // Check the state of the \"to\" location\n let toObj;\n try {\n toObj = await this.stat({\n path: to,\n directory: toDirectory,\n });\n }\n catch (e) {\n // To location does not exist, ensure the directory containing \"to\" location exists and is a directory\n const toPathComponents = to.split('/');\n toPathComponents.pop();\n const toPath = toPathComponents.join('/');\n // Check the containing directory of the \"to\" location exists\n if (toPathComponents.length > 0) {\n const toParentDirectory = await this.stat({\n path: toPath,\n directory: toDirectory,\n });\n if (toParentDirectory.type !== 'directory') {\n throw new Error('Parent directory of the to path is a file');\n }\n }\n }\n // Cannot overwrite a directory\n if (toObj && toObj.type === 'directory') {\n throw new Error('Cannot overwrite a directory with a file');\n }\n // Ensure the \"from\" object exists\n const fromObj = await this.stat({\n path: from,\n directory: fromDirectory,\n });\n // Set the mtime/ctime of the supplied path\n const updateTime = async (path, ctime, mtime) => {\n const fullPath = this.getPath(toDirectory, path);\n const entry = (await this.dbRequest('get', [fullPath]));\n entry.ctime = ctime;\n entry.mtime = mtime;\n await this.dbRequest('put', [entry]);\n };\n const ctime = fromObj.ctime ? fromObj.ctime : Date.now();\n switch (fromObj.type) {\n // The \"from\" object is a file\n case 'file': {\n // Read the file\n const file = await this.readFile({\n path: from,\n directory: fromDirectory,\n });\n // Optionally remove the file\n if (doRename) {\n await this.deleteFile({\n path: from,\n directory: fromDirectory,\n });\n }\n let encoding;\n if (!this.isBase64String(file.data)) {\n encoding = Encoding.UTF8;\n }\n // Write the file to the new location\n const writeResult = await this.writeFile({\n path: to,\n directory: toDirectory,\n data: file.data,\n encoding: encoding,\n });\n // Copy the mtime/ctime of a renamed file\n if (doRename) {\n await updateTime(to, ctime, fromObj.mtime);\n }\n // Resolve promise\n return writeResult;\n }\n case 'directory': {\n if (toObj) {\n throw Error('Cannot move a directory over an existing object');\n }\n try {\n // Create the to directory\n await this.mkdir({\n path: to,\n directory: toDirectory,\n recursive: false,\n });\n // Copy the mtime/ctime of a renamed directory\n if (doRename) {\n await updateTime(to, ctime, fromObj.mtime);\n }\n }\n catch (e) {\n // ignore\n }\n // Iterate over the contents of the from location\n const contents = (await this.readdir({\n path: from,\n directory: fromDirectory,\n })).files;\n for (const filename of contents) {\n // Move item from the from directory to the to directory\n await this._copy({\n from: `${from}/${filename.name}`,\n to: `${to}/${filename.name}`,\n directory: fromDirectory,\n toDirectory,\n }, doRename);\n }\n // Optionally remove the original from directory\n if (doRename) {\n await this.rmdir({\n path: from,\n directory: fromDirectory,\n });\n }\n }\n }\n return {\n uri: toPath,\n };\n }\n isBase64String(str) {\n try {\n return btoa(atob(str)) == str;\n }\n catch (err) {\n return false;\n }\n }\n}\nFilesystemWeb._debug = true;\n//# sourceMappingURL=web.js.map"],"sourceRoot":""}