Skip to content

Commit

Permalink
Merge pull request #169 from i-VRESSE/named-archives
Browse files Browse the repository at this point in the history
When downloading zip files use nice filenames
  • Loading branch information
sverhoeven authored Oct 31, 2024
2 parents 5547c90 + ddb51d8 commit 8009daf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
11 changes: 11 additions & 0 deletions app/bartender-client/bartenderschema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down
2 changes: 0 additions & 2 deletions app/browse/OutputReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ export const OutputReport = ({
</>
)}
<a
target="_blank"
rel="noreferrer"
title="Archive of module output"
href={`${prefix}jobs/${jobid}/archive/${module.output.path}`}
>
Expand Down
14 changes: 13 additions & 1 deletion app/models/job.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,15 @@ 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: {
jobid,
},
query: {
archive_format: ".zip",
filename,
},
},
parseAs: "stream",
Expand All @@ -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: {
Expand All @@ -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",
Expand All @@ -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}", {
Expand All @@ -244,6 +255,7 @@ export async function getSubDirectoryAsArchive(
},
query: {
archive_format: ".zip",
filename: filename,
},
},
parseAs: "stream",
Expand Down
3 changes: 2 additions & 1 deletion app/routes/jobs.$id.archive.$.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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-${id}-${path.replace(/\//g, "-")}.zip`;
return await getSubDirectoryAsArchive(id, path, token, filename);
};
2 changes: 1 addition & 1 deletion deploy/Dockerfile.bartenderhaddock3
Original file line number Diff line number Diff line change
Expand Up @@ -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.2
ARG BARTENDER_VERSION=v0.5.3
ARG GDOCK_VERSION=main
ARG LIGHTDOCK_VERSION=0.9.4
ARG OPENMM_VERSION=8.2.0beta
Expand Down

0 comments on commit 8009daf

Please sign in to comment.