@capacitor/filesystem 1.1.0 → 4.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/CapacitorFilesystem.podspec +1 -1
- package/README.md +32 -11
- package/android/build.gradle +9 -10
- package/android/src/main/java/com/capacitorjs/plugins/filesystem/Filesystem.java +7 -6
- package/android/src/main/java/com/capacitorjs/plugins/filesystem/FilesystemPlugin.java +39 -4
- package/dist/docs.json +106 -6
- package/dist/esm/definitions.d.ts +51 -5
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +3 -2
- package/dist/esm/web.js +46 -13
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +46 -13
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +46 -13
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/Filesystem.swift +9 -0
- package/ios/Plugin/FilesystemPlugin.swift +26 -6
- package/package.json +7 -7
package/dist/esm/web.js
CHANGED
|
@@ -124,12 +124,12 @@ export class FilesystemWeb extends WebPlugin {
|
|
|
124
124
|
*/
|
|
125
125
|
async writeFile(options) {
|
|
126
126
|
const path = this.getPath(options.directory, options.path);
|
|
127
|
-
|
|
127
|
+
let data = options.data;
|
|
128
|
+
const encoding = options.encoding;
|
|
128
129
|
const doRecursive = options.recursive;
|
|
129
130
|
const occupiedEntry = (await this.dbRequest('get', [path]));
|
|
130
131
|
if (occupiedEntry && occupiedEntry.type === 'directory')
|
|
131
132
|
throw Error('The supplied path is a directory.');
|
|
132
|
-
const encoding = options.encoding;
|
|
133
133
|
const parentPath = path.substr(0, path.lastIndexOf('/'));
|
|
134
134
|
const parentEntry = (await this.dbRequest('get', [parentPath]));
|
|
135
135
|
if (parentEntry === undefined) {
|
|
@@ -143,6 +143,11 @@ export class FilesystemWeb extends WebPlugin {
|
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
|
+
if (!encoding) {
|
|
147
|
+
data = data.indexOf(',') >= 0 ? data.split(',')[1] : data;
|
|
148
|
+
if (!this.isBase64String(data))
|
|
149
|
+
throw Error('The supplied data is not valid base64 content.');
|
|
150
|
+
}
|
|
146
151
|
const now = Date.now();
|
|
147
152
|
const pathObj = {
|
|
148
153
|
path: path,
|
|
@@ -151,7 +156,7 @@ export class FilesystemWeb extends WebPlugin {
|
|
|
151
156
|
size: data.length,
|
|
152
157
|
ctime: now,
|
|
153
158
|
mtime: now,
|
|
154
|
-
content:
|
|
159
|
+
content: data,
|
|
155
160
|
};
|
|
156
161
|
await this.dbRequest('put', [pathObj]);
|
|
157
162
|
return {
|
|
@@ -166,7 +171,7 @@ export class FilesystemWeb extends WebPlugin {
|
|
|
166
171
|
async appendFile(options) {
|
|
167
172
|
const path = this.getPath(options.directory, options.path);
|
|
168
173
|
let data = options.data;
|
|
169
|
-
|
|
174
|
+
const encoding = options.encoding;
|
|
170
175
|
const parentPath = path.substr(0, path.lastIndexOf('/'));
|
|
171
176
|
const now = Date.now();
|
|
172
177
|
let ctime = now;
|
|
@@ -185,8 +190,15 @@ export class FilesystemWeb extends WebPlugin {
|
|
|
185
190
|
});
|
|
186
191
|
}
|
|
187
192
|
}
|
|
193
|
+
if (!encoding && !this.isBase64String(data))
|
|
194
|
+
throw Error('The supplied data is not valid base64 content.');
|
|
188
195
|
if (occupiedEntry !== undefined) {
|
|
189
|
-
|
|
196
|
+
if (occupiedEntry.content !== undefined && !encoding) {
|
|
197
|
+
data = btoa(atob(occupiedEntry.content) + atob(data));
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
data = occupiedEntry.content + data;
|
|
201
|
+
}
|
|
190
202
|
ctime = occupiedEntry.ctime;
|
|
191
203
|
}
|
|
192
204
|
const pathObj = {
|
|
@@ -292,10 +304,21 @@ export class FilesystemWeb extends WebPlugin {
|
|
|
292
304
|
if (options.path !== '' && entry === undefined)
|
|
293
305
|
throw Error('Folder does not exist.');
|
|
294
306
|
const entries = await this.dbIndexRequest('by_folder', 'getAllKeys', [IDBKeyRange.only(path)]);
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
307
|
+
const files = await Promise.all(entries.map(async (e) => {
|
|
308
|
+
let subEntry = (await this.dbRequest('get', [e]));
|
|
309
|
+
if (subEntry === undefined) {
|
|
310
|
+
subEntry = (await this.dbRequest('get', [e + '/']));
|
|
311
|
+
}
|
|
312
|
+
return {
|
|
313
|
+
name: e.substring(path.length + 1),
|
|
314
|
+
type: subEntry.type,
|
|
315
|
+
size: subEntry.size,
|
|
316
|
+
ctime: subEntry.ctime,
|
|
317
|
+
mtime: subEntry.mtime,
|
|
318
|
+
uri: subEntry.path,
|
|
319
|
+
};
|
|
320
|
+
}));
|
|
321
|
+
return { files: files };
|
|
299
322
|
}
|
|
300
323
|
/**
|
|
301
324
|
* Return full File URI for a path and directory
|
|
@@ -339,7 +362,8 @@ export class FilesystemWeb extends WebPlugin {
|
|
|
339
362
|
* @return a promise that resolves with the rename result
|
|
340
363
|
*/
|
|
341
364
|
async rename(options) {
|
|
342
|
-
|
|
365
|
+
await this._copy(options, true);
|
|
366
|
+
return;
|
|
343
367
|
}
|
|
344
368
|
/**
|
|
345
369
|
* Copy a file or directory
|
|
@@ -375,7 +399,9 @@ export class FilesystemWeb extends WebPlugin {
|
|
|
375
399
|
const toPath = this.getPath(toDirectory, to);
|
|
376
400
|
// Test that the "to" and "from" locations are different
|
|
377
401
|
if (fromPath === toPath) {
|
|
378
|
-
return
|
|
402
|
+
return {
|
|
403
|
+
uri: toPath,
|
|
404
|
+
};
|
|
379
405
|
}
|
|
380
406
|
if (isPathParent(fromPath, toPath)) {
|
|
381
407
|
throw Error('To path cannot contain the from path');
|
|
@@ -438,7 +464,7 @@ export class FilesystemWeb extends WebPlugin {
|
|
|
438
464
|
});
|
|
439
465
|
}
|
|
440
466
|
// Write the file to the new location
|
|
441
|
-
await this.writeFile({
|
|
467
|
+
const writeResult = await this.writeFile({
|
|
442
468
|
path: to,
|
|
443
469
|
directory: toDirectory,
|
|
444
470
|
data: file.data,
|
|
@@ -448,7 +474,7 @@ export class FilesystemWeb extends WebPlugin {
|
|
|
448
474
|
await updateTime(to, ctime, fromObj.mtime);
|
|
449
475
|
}
|
|
450
476
|
// Resolve promise
|
|
451
|
-
return;
|
|
477
|
+
return writeResult;
|
|
452
478
|
}
|
|
453
479
|
case 'directory': {
|
|
454
480
|
if (toObj) {
|
|
@@ -492,6 +518,13 @@ export class FilesystemWeb extends WebPlugin {
|
|
|
492
518
|
}
|
|
493
519
|
}
|
|
494
520
|
}
|
|
521
|
+
return {
|
|
522
|
+
uri: toPath,
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
isBase64String(str) {
|
|
526
|
+
const base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
527
|
+
return base64regex.test(str);
|
|
495
528
|
}
|
|
496
529
|
}
|
|
497
530
|
FilesystemWeb._debug = true;
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAwB5C,SAAS,OAAO,CAAC,IAAY;IAC3B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;IAC3D,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACnB,IACE,IAAI,KAAK,IAAI;YACb,QAAQ,CAAC,MAAM,GAAG,CAAC;YACnB,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI,EACtC;YACA,QAAQ,CAAC,G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aACR;YACD,KAAK,WAAW,CAAC,CAAC;gBAChB,IAAI,KAAK,EAAE;oBACT,MAAM,KAAK,CAAC,iDAAiD,CAAC,CAAC;iBAChE;gBAED,IAAI;oBACF,0BAA0B;oBAC1B,MAAM,IAAI,CAAC,KAAK,CAAC;wBACf,IAAI,EAAE,EAAE;wBACR,SAAS,EAAE,WAAW;wBACtB,SAAS,EAAE,KAAK;qBACjB,CAAC,CAAC;oBAEH,8CAA8C;oBAC9C,IAAI,QAAQ,EAAE;wBACZ,MAAM,UAAU,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;qBAC5C;iBACF;gBAAC,OAAO,CAAC,EAAE;oBACV,SAAS;iBACV;gBAED,iDAAiD;gBACjD,MAAM,QAAQ,GAAG,CACf,MAAM,IAAI,CAAC,OAAO,CAAC;oBACjB,IAAI,EAAE,IAAI;oBACV,SAAS,EAAE,aAAa;iBACzB,CAAC,CACH,CAAC,KAAK,CAAC;gBAER,KAAK,MAAM,QAAQ,IAAI,QAAQ,EAAE;oBAC/B,wDAAwD;oBACxD,MAAM,IAAI,CAAC,KAAK,CACd;wBACE,IAAI,EAAE,GAAG,IAAI,IAAI,QAAQ,EAAE;wBAC3B,EAAE,EAAE,GAAG,EAAE,IAAI,QAAQ,EAAE;wBACvB,SAAS,EAAE,aAAa;wBACxB,WAAW;qBACZ,EACD,QAAQ,CACT,CAAC;iBACH;gBAED,gDAAgD;gBAChD,IAAI,QAAQ,EAAE;oBACZ,MAAM,IAAI,CAAC,KAAK,CAAC;wBACf,IAAI,EAAE,IAAI;wBACV,SAAS,EAAE,aAAa;qBACzB,CAAC,CAAC;iBACJ;aACF;SACF;IACH,CAAC;;AA1hBM,oBAAM,GAAG,IAAI,CAAC","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n AppendFileOptions,\n CopyOptions,\n DeleteFileOptions,\n FilesystemPlugin,\n GetUriOptions,\n GetUriResult,\n MkdirOptions,\n PermissionStatus,\n ReadFileOptions,\n ReadFileResult,\n ReaddirOptions,\n ReaddirResult,\n RenameOptions,\n RmdirOptions,\n StatOptions,\n StatResult,\n WriteFileOptions,\n WriteFileResult,\n Directory,\n} from './definitions';\n\nfunction resolve(path: string): string {\n const posix = path.split('/').filter(item => item !== '.');\n const newPosix: string[] = [];\n\n posix.forEach(item => {\n if (\n item === '..' &&\n newPosix.length > 0 &&\n newPosix[newPosix.length - 1] !== '..'\n ) {\n newPosix.pop();\n } else {\n newPosix.push(item);\n }\n });\n\n return newPosix.join('/');\n}\nfunction isPathParent(parent: string, children: string): boolean {\n parent = resolve(parent);\n children = resolve(children);\n const pathsA = parent.split('/');\n const pathsB = children.split('/');\n\n return (\n parent !== children &&\n pathsA.every((value, index) => value === pathsB[index])\n );\n}\n\nexport class FilesystemWeb extends WebPlugin implements FilesystemPlugin {\n DB_VERSION = 1;\n DB_NAME = 'Disc';\n\n private _writeCmds: string[] = ['add', 'put', 'delete'];\n private _db?: IDBDatabase;\n static _debug = true;\n async initDb(): Promise<IDBDatabase> {\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\n return new Promise<IDBDatabase>((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: IDBVersionChangeEvent): void {\n const eventTarget = event.target as IDBOpenDBRequest;\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\n async dbRequest(cmd: string, args: any[]): Promise<any> {\n const readFlag =\n this._writeCmds.indexOf(cmd) !== -1 ? 'readwrite' : 'readonly';\n return this.initDb().then((conn: IDBDatabase) => {\n return new Promise<IDBObjectStore>((resolve, reject) => {\n const tx: IDBTransaction = conn.transaction(['FileStorage'], readFlag);\n const store: any = 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 async dbIndexRequest(\n indexName: string,\n cmd: string,\n args: [any],\n ): Promise<any> {\n const readFlag =\n this._writeCmds.indexOf(cmd) !== -1 ? 'readwrite' : 'readonly';\n return this.initDb().then((conn: IDBDatabase) => {\n return new Promise<IDBObjectStore>((resolve, reject) => {\n const tx: IDBTransaction = conn.transaction(['FileStorage'], readFlag);\n const store: IDBObjectStore = tx.objectStore('FileStorage');\n const index: any = store.index(indexName);\n const req = index[cmd](...args) as any;\n req.onsuccess = () => resolve(req.result);\n req.onerror = () => reject(req.error);\n });\n });\n }\n\n private getPath(\n directory: Directory | undefined,\n uriPath: string | undefined,\n ): string {\n const cleanedUriPath =\n uriPath !== undefined ? uriPath.replace(/^[/]+|[/]+$/g, '') : '';\n let fsPath = '';\n if (directory !== undefined) fsPath += '/' + directory;\n if (uriPath !== '') fsPath += '/' + cleanedUriPath;\n return fsPath;\n }\n\n async clear(): Promise<void> {\n const conn: IDBDatabase = await this.initDb();\n const tx: IDBTransaction = conn.transaction(['FileStorage'], 'readwrite');\n const store: IDBObjectStore = tx.objectStore('FileStorage');\n store.clear();\n }\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: ReadFileOptions): Promise<ReadFileResult> {\n const path: string = this.getPath(options.directory, options.path);\n // const encoding = options.encoding;\n\n const entry = (await this.dbRequest('get', [path])) as EntryObj;\n if (entry === undefined) throw Error('File does not exist.');\n return { data: entry.content ? entry.content : '' };\n }\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: WriteFileOptions): Promise<WriteFileResult> {\n const path: string = this.getPath(options.directory, options.path);\n const data = options.data;\n const doRecursive = options.recursive;\n\n const occupiedEntry = (await this.dbRequest('get', [path])) as EntryObj;\n if (occupiedEntry && occupiedEntry.type === 'directory')\n throw Error('The supplied path is a directory.');\n\n const encoding = options.encoding;\n const parentPath = path.substr(0, path.lastIndexOf('/'));\n\n const parentEntry = (await this.dbRequest('get', [parentPath])) as EntryObj;\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 const now = Date.now();\n const pathObj: EntryObj = {\n path: path,\n folder: parentPath,\n type: 'file',\n size: data.length,\n ctime: now,\n mtime: now,\n content: !encoding && data.indexOf(',') >= 0 ? data.split(',')[1] : data,\n };\n await this.dbRequest('put', [pathObj]);\n return {\n uri: pathObj.path,\n };\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: AppendFileOptions): Promise<void> {\n const path: string = 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\n const now = Date.now();\n let ctime = now;\n\n const occupiedEntry = (await this.dbRequest('get', [path])) as EntryObj;\n if (occupiedEntry && occupiedEntry.type === 'directory')\n throw Error('The supplied path is a directory.');\n\n const parentEntry = (await this.dbRequest('get', [parentPath])) as EntryObj;\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\n if (occupiedEntry !== undefined) {\n data = occupiedEntry.content + data;\n ctime = occupiedEntry.ctime;\n }\n const pathObj: EntryObj = {\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 /**\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: DeleteFileOptions): Promise<void> {\n const path: string = this.getPath(options.directory, options.path);\n\n const entry = (await this.dbRequest('get', [path])) as EntryObj;\n if (entry === undefined) 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) throw Error('Folder is not empty.');\n\n await this.dbRequest('delete', [path]);\n }\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: MkdirOptions): Promise<void> {\n const path: string = this.getPath(options.directory, options.path);\n const doRecursive = options.recursive;\n const parentPath = path.substr(0, path.lastIndexOf('/'));\n\n const depth = (path.match(/\\//g) || []).length;\n const parentEntry = (await this.dbRequest('get', [parentPath])) as EntryObj;\n const occupiedEntry = (await this.dbRequest('get', [path])) as EntryObj;\n if (depth === 1) 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\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: EntryObj = {\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 /**\n * Remove a directory\n * @param options the options for the directory remove\n */\n async rmdir(options: RmdirOptions): Promise<void> {\n const { path, directory, recursive } = options;\n const fullPath: string = this.getPath(directory, path);\n\n const entry = (await this.dbRequest('get', [fullPath])) as EntryObj;\n\n if (entry === undefined) throw Error('Folder does not exist.');\n\n if (entry.type !== 'directory')\n throw Error('Requested path is not a directory');\n\n const readDirResult = await this.readdir({ path, directory });\n\n if (readDirResult.files.length !== 0 && !recursive)\n throw Error('Folder is not empty');\n\n for (const entry of readDirResult.files) {\n const entryPath = `${path}/${entry}`;\n const entryObj = await this.stat({ path: entryPath, directory });\n if (entryObj.type === 'file') {\n await this.deleteFile({ path: entryPath, directory });\n } else {\n await this.rmdir({ path: entryPath, directory, recursive });\n }\n }\n\n await this.dbRequest('delete', [fullPath]);\n }\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: ReaddirOptions): Promise<ReaddirResult> {\n const path: string = this.getPath(options.directory, options.path);\n\n const entry = (await this.dbRequest('get', [path])) as EntryObj;\n if (options.path !== '' && entry === undefined)\n throw Error('Folder does not exist.');\n\n const entries: string[] = await this.dbIndexRequest(\n 'by_folder',\n 'getAllKeys',\n [IDBKeyRange.only(path)],\n );\n const names = entries.map(e => {\n return e.substring(path.length + 1);\n });\n return { files: names };\n }\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: GetUriOptions): Promise<GetUriResult> {\n const path: string = this.getPath(options.directory, options.path);\n\n let entry = (await this.dbRequest('get', [path])) as EntryObj;\n if (entry === undefined) {\n entry = (await this.dbRequest('get', [path + '/'])) as EntryObj;\n }\n return {\n uri: entry?.path || path,\n };\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: StatOptions): Promise<StatResult> {\n const path: string = this.getPath(options.directory, options.path);\n\n let entry = (await this.dbRequest('get', [path])) as EntryObj;\n if (entry === undefined) {\n entry = (await this.dbRequest('get', [path + '/'])) as EntryObj;\n }\n if (entry === undefined) throw Error('Entry does not exist.');\n\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 /**\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: RenameOptions): Promise<void> {\n return this._copy(options, true);\n }\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: CopyOptions): Promise<void> {\n return this._copy(options, false);\n }\n\n async requestPermissions(): Promise<PermissionStatus> {\n return { publicStorage: 'granted' };\n }\n\n async checkPermissions(): Promise<PermissionStatus> {\n return { publicStorage: 'granted' };\n }\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 private async _copy(options: CopyOptions, doRename = false): Promise<void> {\n let { toDirectory } = options;\n const { to, from, directory: fromDirectory } = options;\n\n if (!to || !from) {\n throw Error('Both to and from must be provided');\n }\n\n // If no \"to\" directory is provided, use the \"from\" directory\n if (!toDirectory) {\n toDirectory = fromDirectory;\n }\n\n const fromPath = this.getPath(fromDirectory, from);\n const toPath = this.getPath(toDirectory, to);\n\n // Test that the \"to\" and \"from\" locations are different\n if (fromPath === toPath) {\n return;\n }\n\n if (isPathParent(fromPath, toPath)) {\n throw Error('To path cannot contain the from path');\n }\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 } 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\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\n if (toParentDirectory.type !== 'directory') {\n throw new Error('Parent directory of the to path is a file');\n }\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\n // Ensure the \"from\" object exists\n const fromObj = await this.stat({\n path: from,\n directory: fromDirectory,\n });\n\n // Set the mtime/ctime of the supplied path\n const updateTime = async (path: string, ctime: number, mtime: number) => {\n const fullPath: string = this.getPath(toDirectory, path);\n const entry = (await this.dbRequest('get', [fullPath])) as EntryObj;\n entry.ctime = ctime;\n entry.mtime = mtime;\n await this.dbRequest('put', [entry]);\n };\n\n const ctime = fromObj.ctime ? fromObj.ctime : Date.now();\n\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\n // Optionally remove the file\n if (doRename) {\n await this.deleteFile({\n path: from,\n directory: fromDirectory,\n });\n }\n\n // Write the file to the new location\n await this.writeFile({\n path: to,\n directory: toDirectory,\n data: file.data,\n });\n\n // Copy the mtime/ctime of a renamed file\n if (doRename) {\n await updateTime(to, ctime, fromObj.mtime);\n }\n\n // Resolve promise\n return;\n }\n case 'directory': {\n if (toObj) {\n throw Error('Cannot move a directory over an existing object');\n }\n\n try {\n // Create the to directory\n await this.mkdir({\n path: to,\n directory: toDirectory,\n recursive: false,\n });\n\n // Copy the mtime/ctime of a renamed directory\n if (doRename) {\n await updateTime(to, ctime, fromObj.mtime);\n }\n } catch (e) {\n // ignore\n }\n\n // Iterate over the contents of the from location\n const contents = (\n await this.readdir({\n path: from,\n directory: fromDirectory,\n })\n ).files;\n\n for (const filename of contents) {\n // Move item from the from directory to the to directory\n await this._copy(\n {\n from: `${from}/${filename}`,\n to: `${to}/${filename}`,\n directory: fromDirectory,\n toDirectory,\n },\n doRename,\n );\n }\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 }\n}\n\ninterface EntryObj {\n path: string;\n folder: string;\n type: string;\n size: number;\n ctime: number;\n mtime: number;\n uri?: string;\n content?: string;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SA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Q,EAAE;oBACZ,MAAM,IAAI,CAAC,KAAK,CAAC;wBACf,IAAI,EAAE,IAAI;wBACV,SAAS,EAAE,aAAa;qBACzB,CAAC,CAAC;iBACJ;aACF;SACF;QACD,OAAO;YACL,GAAG,EAAE,MAAM;SACZ,CAAC;IACJ,CAAC;IAEO,cAAc,CAAC,GAAW;QAChC,MAAM,WAAW,GACf,kEAAkE,CAAC;QACrE,OAAO,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;;AApkBM,oBAAM,GAAG,IAAI,CAAC","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n AppendFileOptions,\n CopyOptions,\n CopyResult,\n DeleteFileOptions,\n FilesystemPlugin,\n GetUriOptions,\n GetUriResult,\n MkdirOptions,\n PermissionStatus,\n ReadFileOptions,\n ReadFileResult,\n ReaddirOptions,\n ReaddirResult,\n RenameOptions,\n RmdirOptions,\n StatOptions,\n StatResult,\n WriteFileOptions,\n WriteFileResult,\n Directory,\n} from './definitions';\n\nfunction resolve(path: string): string {\n const posix = path.split('/').filter(item => item !== '.');\n const newPosix: string[] = [];\n\n posix.forEach(item => {\n if (\n item === '..' &&\n newPosix.length > 0 &&\n newPosix[newPosix.length - 1] !== '..'\n ) {\n newPosix.pop();\n } else {\n newPosix.push(item);\n }\n });\n\n return newPosix.join('/');\n}\nfunction isPathParent(parent: string, children: string): boolean {\n parent = resolve(parent);\n children = resolve(children);\n const pathsA = parent.split('/');\n const pathsB = children.split('/');\n\n return (\n parent !== children &&\n pathsA.every((value, index) => value === pathsB[index])\n );\n}\n\nexport class FilesystemWeb extends WebPlugin implements FilesystemPlugin {\n DB_VERSION = 1;\n DB_NAME = 'Disc';\n\n private _writeCmds: string[] = ['add', 'put', 'delete'];\n private _db?: IDBDatabase;\n static _debug = true;\n async initDb(): Promise<IDBDatabase> {\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\n return new Promise<IDBDatabase>((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: IDBVersionChangeEvent): void {\n const eventTarget = event.target as IDBOpenDBRequest;\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\n async dbRequest(cmd: string, args: any[]): Promise<any> {\n const readFlag =\n this._writeCmds.indexOf(cmd) !== -1 ? 'readwrite' : 'readonly';\n return this.initDb().then((conn: IDBDatabase) => {\n return new Promise<IDBObjectStore>((resolve, reject) => {\n const tx: IDBTransaction = conn.transaction(['FileStorage'], readFlag);\n const store: any = 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 async dbIndexRequest(\n indexName: string,\n cmd: string,\n args: [any],\n ): Promise<any> {\n const readFlag =\n this._writeCmds.indexOf(cmd) !== -1 ? 'readwrite' : 'readonly';\n return this.initDb().then((conn: IDBDatabase) => {\n return new Promise<IDBObjectStore>((resolve, reject) => {\n const tx: IDBTransaction = conn.transaction(['FileStorage'], readFlag);\n const store: IDBObjectStore = tx.objectStore('FileStorage');\n const index: any = store.index(indexName);\n const req = index[cmd](...args) as any;\n req.onsuccess = () => resolve(req.result);\n req.onerror = () => reject(req.error);\n });\n });\n }\n\n private getPath(\n directory: Directory | undefined,\n uriPath: string | undefined,\n ): string {\n const cleanedUriPath =\n uriPath !== undefined ? uriPath.replace(/^[/]+|[/]+$/g, '') : '';\n let fsPath = '';\n if (directory !== undefined) fsPath += '/' + directory;\n if (uriPath !== '') fsPath += '/' + cleanedUriPath;\n return fsPath;\n }\n\n async clear(): Promise<void> {\n const conn: IDBDatabase = await this.initDb();\n const tx: IDBTransaction = conn.transaction(['FileStorage'], 'readwrite');\n const store: IDBObjectStore = tx.objectStore('FileStorage');\n store.clear();\n }\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: ReadFileOptions): Promise<ReadFileResult> {\n const path: string = this.getPath(options.directory, options.path);\n // const encoding = options.encoding;\n\n const entry = (await this.dbRequest('get', [path])) as EntryObj;\n if (entry === undefined) throw Error('File does not exist.');\n return { data: entry.content ? entry.content : '' };\n }\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: WriteFileOptions): Promise<WriteFileResult> {\n const path: string = this.getPath(options.directory, options.path);\n let data = options.data;\n const encoding = options.encoding;\n const doRecursive = options.recursive;\n\n const occupiedEntry = (await this.dbRequest('get', [path])) as EntryObj;\n if (occupiedEntry && occupiedEntry.type === 'directory')\n throw Error('The supplied path is a directory.');\n\n const parentPath = path.substr(0, path.lastIndexOf('/'));\n\n const parentEntry = (await this.dbRequest('get', [parentPath])) as EntryObj;\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\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\n const now = Date.now();\n const pathObj: EntryObj = {\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 /**\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: AppendFileOptions): Promise<void> {\n const path: string = 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\n const now = Date.now();\n let ctime = now;\n\n const occupiedEntry = (await this.dbRequest('get', [path])) as EntryObj;\n if (occupiedEntry && occupiedEntry.type === 'directory')\n throw Error('The supplied path is a directory.');\n\n const parentEntry = (await this.dbRequest('get', [parentPath])) as EntryObj;\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\n if (!encoding && !this.isBase64String(data))\n throw Error('The supplied data is not valid base64 content.');\n\n if (occupiedEntry !== undefined) {\n if (occupiedEntry.content !== undefined && !encoding) {\n data = btoa(atob(occupiedEntry.content) + atob(data));\n } else {\n data = occupiedEntry.content + data;\n }\n ctime = occupiedEntry.ctime;\n }\n const pathObj: EntryObj = {\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 /**\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: DeleteFileOptions): Promise<void> {\n const path: string = this.getPath(options.directory, options.path);\n\n const entry = (await this.dbRequest('get', [path])) as EntryObj;\n if (entry === undefined) 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) throw Error('Folder is not empty.');\n\n await this.dbRequest('delete', [path]);\n }\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: MkdirOptions): Promise<void> {\n const path: string = this.getPath(options.directory, options.path);\n const doRecursive = options.recursive;\n const parentPath = path.substr(0, path.lastIndexOf('/'));\n\n const depth = (path.match(/\\//g) || []).length;\n const parentEntry = (await this.dbRequest('get', [parentPath])) as EntryObj;\n const occupiedEntry = (await this.dbRequest('get', [path])) as EntryObj;\n if (depth === 1) 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\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: EntryObj = {\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 /**\n * Remove a directory\n * @param options the options for the directory remove\n */\n async rmdir(options: RmdirOptions): Promise<void> {\n const { path, directory, recursive } = options;\n const fullPath: string = this.getPath(directory, path);\n\n const entry = (await this.dbRequest('get', [fullPath])) as EntryObj;\n\n if (entry === undefined) throw Error('Folder does not exist.');\n\n if (entry.type !== 'directory')\n throw Error('Requested path is not a directory');\n\n const readDirResult = await this.readdir({ path, directory });\n\n if (readDirResult.files.length !== 0 && !recursive)\n throw Error('Folder is not empty');\n\n for (const entry of readDirResult.files) {\n const entryPath = `${path}/${entry}`;\n const entryObj = await this.stat({ path: entryPath, directory });\n if (entryObj.type === 'file') {\n await this.deleteFile({ path: entryPath, directory });\n } else {\n await this.rmdir({ path: entryPath, directory, recursive });\n }\n }\n\n await this.dbRequest('delete', [fullPath]);\n }\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: ReaddirOptions): Promise<ReaddirResult> {\n const path: string = this.getPath(options.directory, options.path);\n\n const entry = (await this.dbRequest('get', [path])) as EntryObj;\n if (options.path !== '' && entry === undefined)\n throw Error('Folder does not exist.');\n\n const entries: string[] = await this.dbIndexRequest(\n 'by_folder',\n 'getAllKeys',\n [IDBKeyRange.only(path)],\n );\n const files = await Promise.all(\n entries.map(async e => {\n let subEntry = (await this.dbRequest('get', [e])) as EntryObj;\n if (subEntry === undefined) {\n subEntry = (await this.dbRequest('get', [e + '/'])) as EntryObj;\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 );\n return { files: files };\n }\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: GetUriOptions): Promise<GetUriResult> {\n const path: string = this.getPath(options.directory, options.path);\n\n let entry = (await this.dbRequest('get', [path])) as EntryObj;\n if (entry === undefined) {\n entry = (await this.dbRequest('get', [path + '/'])) as EntryObj;\n }\n return {\n uri: entry?.path || path,\n };\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: StatOptions): Promise<StatResult> {\n const path: string = this.getPath(options.directory, options.path);\n\n let entry = (await this.dbRequest('get', [path])) as EntryObj;\n if (entry === undefined) {\n entry = (await this.dbRequest('get', [path + '/'])) as EntryObj;\n }\n if (entry === undefined) throw Error('Entry does not exist.');\n\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 /**\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: RenameOptions): Promise<void> {\n await this._copy(options, true);\n return;\n }\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: CopyOptions): Promise<CopyResult> {\n return this._copy(options, false);\n }\n\n async requestPermissions(): Promise<PermissionStatus> {\n return { publicStorage: 'granted' };\n }\n\n async checkPermissions(): Promise<PermissionStatus> {\n return { publicStorage: 'granted' };\n }\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 private async _copy(\n options: CopyOptions,\n doRename = false,\n ): Promise<CopyResult> {\n let { toDirectory } = options;\n const { to, from, directory: fromDirectory } = options;\n\n if (!to || !from) {\n throw Error('Both to and from must be provided');\n }\n\n // If no \"to\" directory is provided, use the \"from\" directory\n if (!toDirectory) {\n toDirectory = fromDirectory;\n }\n\n const fromPath = this.getPath(fromDirectory, from);\n const toPath = this.getPath(toDirectory, to);\n\n // Test that the \"to\" and \"from\" locations are different\n if (fromPath === toPath) {\n return {\n uri: toPath,\n };\n }\n\n if (isPathParent(fromPath, toPath)) {\n throw Error('To path cannot contain the from path');\n }\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 } 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\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\n if (toParentDirectory.type !== 'directory') {\n throw new Error('Parent directory of the to path is a file');\n }\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\n // Ensure the \"from\" object exists\n const fromObj = await this.stat({\n path: from,\n directory: fromDirectory,\n });\n\n // Set the mtime/ctime of the supplied path\n const updateTime = async (path: string, ctime: number, mtime: number) => {\n const fullPath: string = this.getPath(toDirectory, path);\n const entry = (await this.dbRequest('get', [fullPath])) as EntryObj;\n entry.ctime = ctime;\n entry.mtime = mtime;\n await this.dbRequest('put', [entry]);\n };\n\n const ctime = fromObj.ctime ? fromObj.ctime : Date.now();\n\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\n // Optionally remove the file\n if (doRename) {\n await this.deleteFile({\n path: from,\n directory: fromDirectory,\n });\n }\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 });\n\n // Copy the mtime/ctime of a renamed file\n if (doRename) {\n await updateTime(to, ctime, fromObj.mtime);\n }\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\n try {\n // Create the to directory\n await this.mkdir({\n path: to,\n directory: toDirectory,\n recursive: false,\n });\n\n // Copy the mtime/ctime of a renamed directory\n if (doRename) {\n await updateTime(to, ctime, fromObj.mtime);\n }\n } catch (e) {\n // ignore\n }\n\n // Iterate over the contents of the from location\n const contents = (\n await this.readdir({\n path: from,\n directory: fromDirectory,\n })\n ).files;\n\n for (const filename of contents) {\n // Move item from the from directory to the to directory\n await this._copy(\n {\n from: `${from}/${filename}`,\n to: `${to}/${filename}`,\n directory: fromDirectory,\n toDirectory,\n },\n doRename,\n );\n }\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\n private isBase64String(str: string): boolean {\n const base64regex =\n /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;\n return base64regex.test(str);\n }\n}\n\ninterface EntryObj {\n path: string;\n folder: string;\n type: 'directory' | 'file';\n size: number;\n ctime: number;\n mtime: number;\n uri?: string;\n content?: string;\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -235,12 +235,12 @@ class FilesystemWeb extends core.WebPlugin {
|
|
|
235
235
|
*/
|
|
236
236
|
async writeFile(options) {
|
|
237
237
|
const path = this.getPath(options.directory, options.path);
|
|
238
|
-
|
|
238
|
+
let data = options.data;
|
|
239
|
+
const encoding = options.encoding;
|
|
239
240
|
const doRecursive = options.recursive;
|
|
240
241
|
const occupiedEntry = (await this.dbRequest('get', [path]));
|
|
241
242
|
if (occupiedEntry && occupiedEntry.type === 'directory')
|
|
242
243
|
throw Error('The supplied path is a directory.');
|
|
243
|
-
const encoding = options.encoding;
|
|
244
244
|
const parentPath = path.substr(0, path.lastIndexOf('/'));
|
|
245
245
|
const parentEntry = (await this.dbRequest('get', [parentPath]));
|
|
246
246
|
if (parentEntry === undefined) {
|
|
@@ -254,6 +254,11 @@ class FilesystemWeb extends core.WebPlugin {
|
|
|
254
254
|
});
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
|
+
if (!encoding) {
|
|
258
|
+
data = data.indexOf(',') >= 0 ? data.split(',')[1] : data;
|
|
259
|
+
if (!this.isBase64String(data))
|
|
260
|
+
throw Error('The supplied data is not valid base64 content.');
|
|
261
|
+
}
|
|
257
262
|
const now = Date.now();
|
|
258
263
|
const pathObj = {
|
|
259
264
|
path: path,
|
|
@@ -262,7 +267,7 @@ class FilesystemWeb extends core.WebPlugin {
|
|
|
262
267
|
size: data.length,
|
|
263
268
|
ctime: now,
|
|
264
269
|
mtime: now,
|
|
265
|
-
content:
|
|
270
|
+
content: data,
|
|
266
271
|
};
|
|
267
272
|
await this.dbRequest('put', [pathObj]);
|
|
268
273
|
return {
|
|
@@ -277,7 +282,7 @@ class FilesystemWeb extends core.WebPlugin {
|
|
|
277
282
|
async appendFile(options) {
|
|
278
283
|
const path = this.getPath(options.directory, options.path);
|
|
279
284
|
let data = options.data;
|
|
280
|
-
|
|
285
|
+
const encoding = options.encoding;
|
|
281
286
|
const parentPath = path.substr(0, path.lastIndexOf('/'));
|
|
282
287
|
const now = Date.now();
|
|
283
288
|
let ctime = now;
|
|
@@ -296,8 +301,15 @@ class FilesystemWeb extends core.WebPlugin {
|
|
|
296
301
|
});
|
|
297
302
|
}
|
|
298
303
|
}
|
|
304
|
+
if (!encoding && !this.isBase64String(data))
|
|
305
|
+
throw Error('The supplied data is not valid base64 content.');
|
|
299
306
|
if (occupiedEntry !== undefined) {
|
|
300
|
-
|
|
307
|
+
if (occupiedEntry.content !== undefined && !encoding) {
|
|
308
|
+
data = btoa(atob(occupiedEntry.content) + atob(data));
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
data = occupiedEntry.content + data;
|
|
312
|
+
}
|
|
301
313
|
ctime = occupiedEntry.ctime;
|
|
302
314
|
}
|
|
303
315
|
const pathObj = {
|
|
@@ -403,10 +415,21 @@ class FilesystemWeb extends core.WebPlugin {
|
|
|
403
415
|
if (options.path !== '' && entry === undefined)
|
|
404
416
|
throw Error('Folder does not exist.');
|
|
405
417
|
const entries = await this.dbIndexRequest('by_folder', 'getAllKeys', [IDBKeyRange.only(path)]);
|
|
406
|
-
const
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
418
|
+
const files = await Promise.all(entries.map(async (e) => {
|
|
419
|
+
let subEntry = (await this.dbRequest('get', [e]));
|
|
420
|
+
if (subEntry === undefined) {
|
|
421
|
+
subEntry = (await this.dbRequest('get', [e + '/']));
|
|
422
|
+
}
|
|
423
|
+
return {
|
|
424
|
+
name: e.substring(path.length + 1),
|
|
425
|
+
type: subEntry.type,
|
|
426
|
+
size: subEntry.size,
|
|
427
|
+
ctime: subEntry.ctime,
|
|
428
|
+
mtime: subEntry.mtime,
|
|
429
|
+
uri: subEntry.path,
|
|
430
|
+
};
|
|
431
|
+
}));
|
|
432
|
+
return { files: files };
|
|
410
433
|
}
|
|
411
434
|
/**
|
|
412
435
|
* Return full File URI for a path and directory
|
|
@@ -450,7 +473,8 @@ class FilesystemWeb extends core.WebPlugin {
|
|
|
450
473
|
* @return a promise that resolves with the rename result
|
|
451
474
|
*/
|
|
452
475
|
async rename(options) {
|
|
453
|
-
|
|
476
|
+
await this._copy(options, true);
|
|
477
|
+
return;
|
|
454
478
|
}
|
|
455
479
|
/**
|
|
456
480
|
* Copy a file or directory
|
|
@@ -486,7 +510,9 @@ class FilesystemWeb extends core.WebPlugin {
|
|
|
486
510
|
const toPath = this.getPath(toDirectory, to);
|
|
487
511
|
// Test that the "to" and "from" locations are different
|
|
488
512
|
if (fromPath === toPath) {
|
|
489
|
-
return
|
|
513
|
+
return {
|
|
514
|
+
uri: toPath,
|
|
515
|
+
};
|
|
490
516
|
}
|
|
491
517
|
if (isPathParent(fromPath, toPath)) {
|
|
492
518
|
throw Error('To path cannot contain the from path');
|
|
@@ -549,7 +575,7 @@ class FilesystemWeb extends core.WebPlugin {
|
|
|
549
575
|
});
|
|
550
576
|
}
|
|
551
577
|
// Write the file to the new location
|
|
552
|
-
await this.writeFile({
|
|
578
|
+
const writeResult = await this.writeFile({
|
|
553
579
|
path: to,
|
|
554
580
|
directory: toDirectory,
|
|
555
581
|
data: file.data,
|
|
@@ -559,7 +585,7 @@ class FilesystemWeb extends core.WebPlugin {
|
|
|
559
585
|
await updateTime(to, ctime, fromObj.mtime);
|
|
560
586
|
}
|
|
561
587
|
// Resolve promise
|
|
562
|
-
return;
|
|
588
|
+
return writeResult;
|
|
563
589
|
}
|
|
564
590
|
case 'directory': {
|
|
565
591
|
if (toObj) {
|
|
@@ -603,6 +629,13 @@ class FilesystemWeb extends core.WebPlugin {
|
|
|
603
629
|
}
|
|
604
630
|
}
|
|
605
631
|
}
|
|
632
|
+
return {
|
|
633
|
+
uri: toPath,
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
isBase64String(str) {
|
|
637
|
+
const base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
638
|
+
return base64regex.test(str);
|
|
606
639
|
}
|
|
607
640
|
}
|
|
608
641
|
FilesystemWeb._debug = true;
|