Source: xxe/res/RemoteFiles.js

/**
 * {@linkplain ResourceStorage Resource storage} for remote, 
 * that is, XXE server-side, resources.
 */
export class RemoteFiles extends ResourceStorage {
    /**
     * Constructs an XXE server-side resource storage for use by specified
     * XML Editor.
     */
    constructor(xmlEditor) {
        super(xmlEditor);
    }

    loadResource(uri) {
        return this._xmlEditor.sendRequest("loadResource", uri)
            .then((data) => {
                      if (data) {
                          return new RemoteFile(uri, data);
                      } else {
                          // Unknown URI.
                          return null;
                      }
                  },
                  (error) => {
                      throw new Error(
                          `Cannot load resource "${uri}": ${error}`);
                  });
    }
    
    storeResource(data, uri) {
        return this._xmlEditor.sendRequest("storeResource", data, uri)
            .then((done) => {
                      if (done) {
                          return new RemoteFile(uri, data);
                      } else {
                          // Unknown URI.
                          return null;
                      }
                  },
                  (error) => {
                      throw new Error(
                          `Cannot store resource '${uri}': ${error}`);
                  });
    }
    
    openResource(options) {
        let uri = [ "???" ];
        
        return RemoteFileDialog.showDialog(this._xmlEditor, options)
            .then((choice) => {
                if (choice === null) {
                    // Canceled by user.
                    return null;
                } else {
                    uri[0] = choice.uri;
                    return this._xmlEditor.sendRequest("loadResource", uri[0]);
                }
            })
            .then((data) => {
                if (data === null) {
                    // Canceled by user.
                    return null;
                } else {
                    return new RemoteFile(uri[0], data);
                }
            })
            .catch((error) => {
                throw new Error(`Cannot load resource "${uri[0]}": ${error}`);
            });
    }
}