Files
doneit-web/.angular/cache/14.2.12/babel-webpack/54f54fe1978d39cddc02355e7ef86b8a.json
T

1 line
60 KiB
JSON
Raw Normal View History

2023-06-30 09:54:21 +01:00
{"ast":null,"code":"import _asyncToGenerator from \"C:/Users/eudes.inacio/GabineteDigital/gabinete-digital-fo/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js\";\nimport { WebPlugin } from '@capacitor/core';\nfunction resolve(path) {\n const posix = path.split('/').filter(item => item !== '.');\n const newPosix = [];\n posix.forEach(item => {\n if (item === '..' && newPosix.length > 0 && newPosix[newPosix.length - 1] !== '..') {\n newPosix.pop();\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 && 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 initDb() {\n var _this = this;\n return _asyncToGenerator(function* () {\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 }\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 {\n if (db.objectStoreNames.contains('FileStorage')) {\n db.deleteObjectStore('FileStorage');\n }\n const store = db.createObjectStore('FileStorage', {\n keyPath: 'path'\n });\n store.createIndex('by_folder', 'folder');\n }\n }\n }\n dbRequest(cmd, args) {\n var _this2 = this;\n return _asyncToGenerator(function* () {\n const readFlag = _this2._writeCmds.indexOf(cmd) !== -1 ? 'readwrite' : 'readonly';\n return _this2.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 }\n dbIndexRequest(indexName, cmd, args) {\n var _this3 = this;\n return _asyncToGenerator(function* () {\n const readFlag = _this3._writeCmds.indexOf(cmd) !== -1 ? 'readwrite' : 'readonly';\n return _this3.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 }\n getPath(directory, uriPath) {\n const cleanedUriPath = uriPath !== undefined ? uriPath.replace(/^[/]+|[/]+$/g, '') : '';\n let fsPath = '';\n if (directory !== undefined) fsPath += '/' + directory;\n if (uriPath !== '') fsPath += '/' + cleanedUriPath;\n return fsPath;\n }\n clear() {\n var _this4 = this;\n return _asyncToGenerator(function* () {\n const conn = yield _this4.initDb();\n const tx = conn.transaction(['FileStorage'], 'readwrite');\n const store = tx.objectStore('FileStorage');\n store