|
39 | 39 | * [.getPluginFolder()](#module-storage-filesystemprovider-getpluginfolder) ⇒ `Promise.<Folder>`
|
40 | 40 | * [.getFsUrl(entry)](#module-storage-filesystemprovider-getfsurl) ⇒ `URL`
|
41 | 41 | * [.getNativePath(entry)](#module-storage-filesystemprovider-getnativepath) ⇒ `string`
|
| 42 | + * [.createSessionToken(entry)](#module-storage-filesystemprovider-createsessiontoken) ⇒ `string` |
| 43 | + * [.getEntryForSessionToken(token)](#module-storage-filesystemprovider-getentryforsessiontoken) ⇒ `Entry` |
| 44 | + * [.createPersistentToken(entry)](#module-storage-filesystemprovider-createpersistenttoken) ⇒ `Promise<string>` |
| 45 | + * [.getEntryForPersistentToken(token)](#module-storage-filesystemprovider-getentryforpersistenttoken) ⇒ `Promise<Entry>` |
42 | 46 | * [.Folder](#module-storage-folder) ⇐ `Entry`
|
43 | 47 | * [.getEntries()](#module-storage-folder-getentries) ⇒ `Promise.<Array.<Entry>>`
|
44 | 48 | * [.createFile(name, options)](#module-storage-folder-createfile) ⇒ `Promise.<File>`
|
@@ -638,6 +642,109 @@ Returns the platform native file system path of given entry.
|
638 | 642 | | --- | --- |
|
639 | 643 | | entry | `Entry` |
|
640 | 644 |
|
| 645 | +<a name="module-storage-filesystemprovider-createsessiontoken" id="module-storage-filesystemprovider-createsessiontoken"></a> |
| 646 | +
|
| 647 | +### createSessionToken(entry) |
| 648 | +Returns a token suitable for use with certain host-specific APIs. This |
| 649 | +token is valid only for the current plugin session. As such, it is of no use if you |
| 650 | +serialize the token to persistent storage, as the token will be invalid in the future. |
| 651 | +
|
| 652 | +**Returns**: `string` - the session token for the given entry |
| 653 | +
|
| 654 | +| Param | Type | |
| 655 | +| --- | --- | |
| 656 | +| entry | `Entry` | |
| 657 | +
|
| 658 | +**Example** |
| 659 | +```js |
| 660 | +const fs = require('uxp').storage.localFileSystem; |
| 661 | +let entry = await fs.getFileForOpening(); |
| 662 | +let token = fs.createSessionToken(entry); |
| 663 | +``` |
| 664 | +
|
| 665 | +
|
| 666 | +<a name="module-storage-filesystemprovider-getentryforsessiontoken" id="module-storage-filesystemprovider-getentryforsessiontoken"></a> |
| 667 | +
|
| 668 | +### getEntryForSessionToken(token) |
| 669 | +Returns the file system Entry that corresponds to the session token obtained from |
| 670 | +`createSessionToken`. If an entry cannot be found that matches the token, then a |
| 671 | +`Reference Error: token is not defined` error is thrown. |
| 672 | +
|
| 673 | +**Returns**: `Entry` - the corresponding entry for the session token |
| 674 | +
|
| 675 | +| Param | Type | |
| 676 | +| --- | --- | |
| 677 | +| token | `string` | |
| 678 | +
|
| 679 | +
|
| 680 | +
|
| 681 | +<a name="module-storage-filesystemprovider-createpersistenttoken" id="module-storage-filesystemprovider-createpersistenttoken"></a> |
| 682 | +
|
| 683 | +### createPersistentToken(entry) |
| 684 | +Returns a token suitable for use with host-specific APIs (such as Xd), or |
| 685 | +for storing a persistent reference to an entry (useful if you want to only ask for |
| 686 | +permission to access a file or folder once). A persistent token is not guaranteed |
| 687 | +to last forever -- certain scenarios can cause the token to longer work (including |
| 688 | +moving files, changing permissions, or OS-specific limitations). If a persistent |
| 689 | +token cannot be reused, you'll get an error at the time of use. |
| 690 | +
|
| 691 | +**Returns**: `string` - the persistent token for the given entry |
| 692 | +
|
| 693 | +| Param | Type | |
| 694 | +| --- | --- | |
| 695 | +| entry | `Entry` | |
| 696 | +
|
| 697 | +**Example** |
| 698 | +```js |
| 699 | +const fs = require('uxp').storage.localFileSystem; |
| 700 | +let entry = await fs.getFileForOpening(); |
| 701 | +let token = fs.createPersistentToken(entry); |
| 702 | +localStorage.setItem("persistent-file", token); |
| 703 | +``` |
| 704 | +
|
| 705 | +
|
| 706 | +<a name="module-storage-filesystemprovider-getentryforpersistenttoken" id="module-storage-filesystemprovider-getentryforpersistenttoken"></a> |
| 707 | +
|
| 708 | +### getEntryForPersistentToken(token) |
| 709 | +Returns the file system Entry that corresponds to the persistent token obtained from |
| 710 | +`createPersistentToken`. If an entry cannot be found that matches the token, then a |
| 711 | +`Reference Error: token is not defined` error is thrown. |
| 712 | +
|
| 713 | +> Retrieving an entry for a persistent token does _not_ guarantee that the |
| 714 | +entry is valid for use. You'll need to properly handle the case where the entry no |
| 715 | +longer exists on the disk, or the permissions have changed by catching the appropriate |
| 716 | +errors. If that occurs, the suggested practice is to prompt the user for the entry |
| 717 | +again and store the new token. |
| 718 | +
|
| 719 | +**Returns**: `Entry` - the corresponding entry for the persistent token |
| 720 | +
|
| 721 | +| Param | Type | |
| 722 | +| --- | --- | |
| 723 | +| token | `string` | |
| 724 | +
|
| 725 | +**Example** |
| 726 | +```js |
| 727 | +const fs = require('uxp').storage.localFileSystem; |
| 728 | +let entry, contents, tries = 3, success = false; |
| 729 | +while (tries > 0) { |
| 730 | + try { |
| 731 | + entry = await fs.getEntryForPersistentToken(localStorage.getItem("persistent-file")); |
| 732 | + contents = await entry.read(); |
| 733 | + tries = 0; |
| 734 | + success = true; |
| 735 | + } catch (err) { |
| 736 | + entry = await fs.getFileForOpening(); |
| 737 | + localStorage.setItem("persistent-token", await fs.createPersistentToken(entry)); |
| 738 | + tries--; |
| 739 | + } |
| 740 | +} |
| 741 | +if (!success) { |
| 742 | + // fail gracefully somehow |
| 743 | +} |
| 744 | +``` |
| 745 | +
|
| 746 | +
|
| 747 | +
|
641 | 748 |
|
642 | 749 | <a name="module-storage-folder" id="module-storage-folder"></a>
|
643 | 750 |
|
|
0 commit comments