Skip to content

Commit

Permalink
Replace fetcher in shortTermStorage composable
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Jul 26, 2024
1 parent 91390bc commit e2a1c11
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions client/src/composables/shortTermStorage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { readonly, ref, watch } from "vue";

import { type StoreExportPayload } from "@/api";
import { fetcher } from "@/api/schema";
import { client } from "@/api";
import { type ExportParams } from "@/components/Common/models/exportRecordModel";
import { withPrefix } from "@/utils/redirect";
import { rethrowSimple } from "@/utils/simple-error";

import { useShortTermStorageMonitor } from "./shortTermStorageMonitor";

Expand All @@ -28,15 +29,6 @@ type StartPreparingDownloadCallback = (objectId: string, params: StoreExportPayl
const DEFAULT_POLL_DELAY = 3000;
const DEFAULT_OPTIONS: Options = { exportParams: DEFAULT_EXPORT_PARAMS, pollDelayInMs: DEFAULT_POLL_DELAY };

const startPreparingHistoryDownload = fetcher
.path("/api/histories/{history_id}/prepare_store_download")
.method("post")
.create();
const startPreparingInvocationDownload = fetcher
.path("/api/invocations/{invocation_id}/prepare_store_download")
.method("post")
.create();

/**
* Composable to simplify and reuse the logic for downloading objects using Galaxy's Short Term Storage system.
*/
Expand All @@ -52,12 +44,30 @@ export function useShortTermStorage() {
});

const forHistory: StartPreparingDownloadCallback = async (id: string, params: StoreExportPayload) => {
const { data } = await startPreparingHistoryDownload({ history_id: id, ...params });
const { data, error } = await client.POST("/api/histories/{history_id}/prepare_store_download", {
params: { path: { history_id: id } },
body: params,
});

if (error) {
rethrowSimple(error);
}
return data;
};

const forInvocation: StartPreparingDownloadCallback = async (id: string, params: StoreExportPayload) => {
const { data } = await startPreparingInvocationDownload({ invocation_id: id, ...params });
const { data, error } = await client.POST("/api/invocations/{invocation_id}/prepare_store_download", {
params: { path: { invocation_id: id } },
body: {
...params,
bco_merge_history_metadata: false,
},
});

if (error) {
rethrowSimple(error);
}

return data;
};

Expand Down

0 comments on commit e2a1c11

Please sign in to comment.