| 352 | * NOTE: You must use the v0.10 version of the [Dropbox JavaScript SDK](https://www.npmjs.com/package/dropbox). |
| 353 | */ |
| 354 | export default class DropboxFileSystem extends BaseFileSystem implements FileSystem { |
| 355 | public static readonly Name = "Dropbox"; |
| 356 | |
| 357 | public static readonly Options: FileSystemOptions = { |
| 358 | client: { |
| 359 | type: "object", |
| 360 | description: "An *authenticated* Dropbox client. Must be from the 0.10 JS SDK.", |
| 361 | validator: (opt: Dropbox.Client, cb: BFSOneArgCallback): void => { |
| 362 | if (opt.isAuthenticated && opt.isAuthenticated()) { |
| 363 | cb(); |
| 364 | } else { |
| 365 | cb(new ApiError(ErrorCode.EINVAL, `'client' option must be an authenticated Dropbox client from the v0.10 JS SDK.`)); |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | }; |
| 370 | |
| 371 | /** |
| 372 | * Creates a new DropboxFileSystem instance with the given options. |
| 373 | * Must be given an *authenticated* DropboxJS client from the old v0.10 version of the Dropbox JS SDK. |
| 374 | */ |
| 375 | public static Create(opts: DropboxFileSystemOptions, cb: BFSCallback<DropboxFileSystem>): void { |
| 376 | cb(null, new DropboxFileSystem(opts.client, false)); |
| 377 | } |
| 378 | |
| 379 | public static isAvailable(): boolean { |
| 380 | // Checks if the Dropbox library is loaded. |
| 381 | return typeof Dropbox !== 'undefined'; |
| 382 | } |
| 383 | |
| 384 | // The Dropbox client. |
| 385 | private _client: CachedDropboxClient; |
| 386 | |
| 387 | /** |
| 388 | * **Deprecated. Please use Dropbox.Create() method instead.** |
| 389 | * |
| 390 | * Constructs a Dropbox-backed file system using the *authenticated* DropboxJS client. |
| 391 | * |
| 392 | * Note that you must use the old v0.10 version of the Dropbox JavaScript SDK. |
| 393 | */ |
| 394 | constructor(client: Dropbox.Client, deprecateMsg = true) { |
| 395 | super(); |
| 396 | this._client = new CachedDropboxClient(client); |
| 397 | deprecationMessage(deprecateMsg, DropboxFileSystem.Name, { client: "authenticated dropbox client instance" }); |
| 398 | constructErrorCodeLookup(); |
| 399 | } |
| 400 | |
| 401 | public getName(): string { |
| 402 | return DropboxFileSystem.Name; |
| 403 | } |
| 404 | |
| 405 | public isReadOnly(): boolean { |
| 406 | return false; |
| 407 | } |
| 408 | |
| 409 | // Dropbox doesn't support symlinks, properties, or synchronous calls |
| 410 | |
| 411 | public supportsSymlinks(): boolean { |