From c69f52581683d887b05863c94ad79ef8382fb157 Mon Sep 17 00:00:00 2001 From: sverhoeven Date: Thu, 31 Oct 2024 13:28:54 +0100 Subject: [PATCH 1/2] When downloading zip files use nice filenames --- app/bartender-client/bartenderschema.d.ts | 11 +++++++++++ app/models/job.server.ts | 14 +++++++++++++- app/routes/jobs.$id.archive.$.ts | 3 ++- deploy/Dockerfile.bartenderhaddock3 | 2 +- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/bartender-client/bartenderschema.d.ts b/app/bartender-client/bartenderschema.d.ts index 12c4447e..95208f04 100644 --- a/app/bartender-client/bartenderschema.d.ts +++ b/app/bartender-client/bartenderschema.d.ts @@ -106,6 +106,11 @@ export interface paths { * job_dir: The job directory. * destination: The destination of the job. * job_root_dir: The root directory of all jobs. + * + * Raises: + * HTTPException: When job is not found. + * Or when user is not owner of job. + * Or when job is in state that cannot be deleted. */ delete: operations["delete_job"]; options?: never; @@ -269,6 +274,8 @@ export interface paths { * '.tar.xz', '.tar.gz', '.tar.bz2' * exclude: list of filename patterns that should be excluded from archive. * exclude_dirs: list of directory patterns that should be excluded from archive. + * filename: Name of the archive file to be returned. + * If not provided, uses id of the job. * * Returns: * FileResponse: Archive containing the content of job_dir @@ -301,6 +308,8 @@ export interface paths { * '.tar', '.tar.xz', '.tar.gz', '.tar.bz2' * exclude: list of filename patterns that should be excluded from archive. * exclude_dirs: list of directory patterns that should be excluded from archive. + * filename: Name of the archive file to be returned. + * If not provided, uses id of the job. * * Returns: * FileResponse: Archive containing the output of job_dir @@ -853,6 +862,7 @@ export interface operations { archive_format?: ".zip" | ".tar" | ".tar.xz" | ".tar.gz" | ".tar.bz2"; exclude?: string[]; exclude_dirs?: string[]; + filename?: string; }; header?: never; path: { @@ -888,6 +898,7 @@ export interface operations { archive_format?: ".zip" | ".tar" | ".tar.xz" | ".tar.gz" | ".tar.bz2"; exclude?: string[]; exclude_dirs?: string[]; + filename?: string; }; header?: never; path: { diff --git a/app/models/job.server.ts b/app/models/job.server.ts index ff92e943..5c484de0 100644 --- a/app/models/job.server.ts +++ b/app/models/job.server.ts @@ -194,6 +194,7 @@ export async function listInputFiles(jobid: number, bartenderToken: string) { export async function getArchive(jobid: number, bartenderToken: string) { const client = createClient(bartenderToken); + const filename = `haddock3-${jobid}.zip`; const { response } = await client.GET("/api/job/{jobid}/archive", { params: { path: { @@ -201,6 +202,7 @@ export async function getArchive(jobid: number, bartenderToken: string) { }, query: { archive_format: ".zip", + filename, }, }, parseAs: "stream", @@ -210,6 +212,7 @@ export async function getArchive(jobid: number, bartenderToken: string) { export async function getInputArchive(jobid: number, bartenderToken: string) { const client = createClient(bartenderToken); + const filename = `haddock3-input-${jobid}.zip`; const { response } = await client.GET("/api/job/{jobid}/archive", { params: { path: { @@ -219,6 +222,7 @@ export async function getInputArchive(jobid: number, bartenderToken: string) { archive_format: ".zip", exclude: BOOK_KEEPING_FILES, exclude_dirs: [JOB_OUTPUT_DIR], + filename: filename, }, }, parseAs: "stream", @@ -227,13 +231,20 @@ export async function getInputArchive(jobid: number, bartenderToken: string) { } export async function getOutputArchive(jobid: number, bartenderToken: string) { - return await getSubDirectoryAsArchive(jobid, JOB_OUTPUT_DIR, bartenderToken); + const filename = `haddock3-output-${jobid}.zip`; + return await getSubDirectoryAsArchive( + jobid, + JOB_OUTPUT_DIR, + bartenderToken, + filename, + ); } export async function getSubDirectoryAsArchive( jobid: number, path: string, bartenderToken: string, + filename: string = "", ) { const client = createClient(bartenderToken); const { response } = await client.GET("/api/job/{jobid}/archive/{path}", { @@ -244,6 +255,7 @@ export async function getSubDirectoryAsArchive( }, query: { archive_format: ".zip", + filename: filename, }, }, parseAs: "stream", diff --git a/app/routes/jobs.$id.archive.$.ts b/app/routes/jobs.$id.archive.$.ts index 035691dd..fcf1997a 100644 --- a/app/routes/jobs.$id.archive.$.ts +++ b/app/routes/jobs.$id.archive.$.ts @@ -7,5 +7,6 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => { const id = jobIdFromParams(params); const path = params["*"] || ""; const token = await getBartenderToken(request); - return await getSubDirectoryAsArchive(id, path, token); + const filename = `haddock3-output-${id}-${path.replace(/\//g, "-")}.zip`; + return await getSubDirectoryAsArchive(id, path, token, filename); }; diff --git a/deploy/Dockerfile.bartenderhaddock3 b/deploy/Dockerfile.bartenderhaddock3 index a8893356..accd43aa 100644 --- a/deploy/Dockerfile.bartenderhaddock3 +++ b/deploy/Dockerfile.bartenderhaddock3 @@ -6,7 +6,7 @@ LABEL org.opencontainers.image.description="bartender web service with haddock3, ARG HADDOCK3_GHORG=haddocking ARG HADDOCK3_VERSION=main -ARG BARTENDER_VERSION=v0.5.1 +ARG BARTENDER_VERSION=v0.5.3 ARG GDOCK_VERSION=main ARG LIGHTDOCK_VERSION=0.9.4 ARG OPENMM_VERSION=8.2.0beta From 7a3306839e3dd9bdbd3087948a262d9cf508d93f Mon Sep 17 00:00:00 2001 From: sverhoeven Date: Thu, 31 Oct 2024 15:37:21 +0100 Subject: [PATCH 2/2] Make module output archive filename nicer --- app/browse/OutputReport.tsx | 2 -- app/routes/jobs.$id.archive.$.ts | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/browse/OutputReport.tsx b/app/browse/OutputReport.tsx index 23d0454f..d2db9e70 100644 --- a/app/browse/OutputReport.tsx +++ b/app/browse/OutputReport.tsx @@ -139,8 +139,6 @@ export const OutputReport = ({ )} diff --git a/app/routes/jobs.$id.archive.$.ts b/app/routes/jobs.$id.archive.$.ts index fcf1997a..5459fe36 100644 --- a/app/routes/jobs.$id.archive.$.ts +++ b/app/routes/jobs.$id.archive.$.ts @@ -7,6 +7,6 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => { const id = jobIdFromParams(params); const path = params["*"] || ""; const token = await getBartenderToken(request); - const filename = `haddock3-output-${id}-${path.replace(/\//g, "-")}.zip`; + const filename = `haddock3-${id}-${path.replace(/\//g, "-")}.zip`; return await getSubDirectoryAsArchive(id, path, token, filename); };