Browse Source

mol-plugin: support request body in Download(Blob) transforms

David Sehnal 5 years ago
parent
commit
5bcca99f60
2 changed files with 6 additions and 4 deletions
  1. 4 2
      src/mol-plugin-state/transforms/data.ts
  2. 2 2
      src/mol-util/data-source.ts

+ 4 - 2
src/mol-plugin-state/transforms/data.ts

@@ -29,12 +29,13 @@ const Download = PluginStateTransform.BuiltIn({
     params: {
         url: PD.Text('https://www.ebi.ac.uk/pdbe/static/entry/1cbs_updated.cif', { description: 'Resource URL. Must be the same domain or support CORS.' }),
         label: PD.Optional(PD.Text('')),
-        isBinary: PD.Optional(PD.Boolean(false, { description: 'If true, download data as binary (string otherwise)' }))
+        isBinary: PD.Optional(PD.Boolean(false, { description: 'If true, download data as binary (string otherwise)' })),
+        body: PD.Optional(PD.Text(''))
     }
 })({
     apply({ params: p }, globalCtx: PluginContext) {
         return Task.create('Download', async ctx => {
-            const data = await globalCtx.fetch({ url: p.url, type: p.isBinary ? 'binary' : 'string' }).runInContext(ctx);
+            const data = await globalCtx.fetch({ url: p.url, type: p.isBinary ? 'binary' : 'string', body: p.body }).runInContext(ctx);
             return p.isBinary
                 ? new SO.Data.Binary(data as Uint8Array, { label: p.label ? p.label : p.url })
                 : new SO.Data.String(data as string, { label: p.label ? p.label : p.url });
@@ -62,6 +63,7 @@ const DownloadBlob = PluginStateTransform.BuiltIn({
             id: PD.Text('', { label: 'Unique ID' }),
             url: PD.Text('https://www.ebi.ac.uk/pdbe/static/entry/1cbs_updated.cif', { description: 'Resource URL. Must be the same domain or support CORS.' }),
             isBinary: PD.Optional(PD.Boolean(false, { description: 'If true, download data as binary (string otherwise)' })),
+            body: PD.Optional(PD.Text('')),
             canFail: PD.Optional(PD.Boolean(false, { description: 'Indicate whether the download can fail and not be included in the blob as a result.' }))
         }, e => `${e.id}: ${e.url}`),
         maxConcurrency: PD.Optional(PD.Numeric(4, { min: 1, max: 12, step: 1 }, { description: 'The maximum number of concurrent downloads.' }))

+ 2 - 2
src/mol-util/data-source.ts

@@ -276,7 +276,7 @@ function ajaxGetInternal<T extends DataType>(title: string | undefined, url: str
 }
 
 export type AjaxGetManyEntry<T> = { kind: 'ok', id: string, result: T } | { kind: 'error', id: string, error: any }
-export async function ajaxGetMany(ctx: RuntimeContext, sources: { id: string, url: string, isBinary?: boolean, canFail?: boolean }[], maxConcurrency: number) {
+export async function ajaxGetMany(ctx: RuntimeContext, sources: { id: string, url: string, isBinary?: boolean, body?: string, canFail?: boolean }[], maxConcurrency: number) {
     const len = sources.length;
     const slots: AjaxGetManyEntry<string | Uint8Array>[] = new Array(sources.length);
 
@@ -307,7 +307,7 @@ export async function ajaxGetMany(ctx: RuntimeContext, sources: { id: string, ur
         promiseKeys = promiseKeys.filter(_filterRemoveIndex, idx);
         if (currentSrc < len) {
             const current = sources[currentSrc];
-            promises.push(wrapPromise(currentSrc, current.id, ajaxGet({ url: current.url, type: current.isBinary ? 'binary' : 'string' }).runAsChild(ctx)));
+            promises.push(wrapPromise(currentSrc, current.id, ajaxGet({ url: current.url, type: current.isBinary ? 'binary' : 'string', body: current.body }).runAsChild(ctx)));
             promiseKeys.push(currentSrc);
             currentSrc++;
         }