Skip to content

Commit

Permalink
fix: All Annotations AWS CLI command (#1593)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloster authored Feb 7, 2025
1 parent 80fbbb1 commit adea04e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,28 @@ import { DownloadConfig } from 'app/types/download'

import { SelectSaveDestination } from './SelectSaveDestination'

const AWS_S3_BASE_COMMAND = 'aws s3 --no-sign-request'

export function getAwsCommand({
s3Path,
s3Command,
isAllAnnotations = false,
}: {
s3Path: string | undefined
s3Command: 'cp' | 'sync'
isAllAnnotations?: boolean
}): string {
const destinationPath = s3Path?.replace(/\/$/, '').split('/').pop()
return `aws s3 --no-sign-request ${s3Command} ${s3Path} ${destinationPath}`
const originPath = s3Path?.replace(/\/$/, '')
const destinationPath = originPath?.split('/').pop()

if (isAllAnnotations) {
const basePathMatch = s3Path?.match(/^([^/]+\/.*?\/Reconstructions)/)
const basePath = basePathMatch ? basePathMatch[1] : ''

return `${AWS_S3_BASE_COMMAND} ${s3Command} ${basePath}/ Annotations --exclude "*" --include "*/Annotations/*"`
}

return `${AWS_S3_BASE_COMMAND} ${s3Command} ${originPath} ${destinationPath}`
}

export function AWSDownloadTab() {
Expand All @@ -28,21 +41,22 @@ export function AWSDownloadTab() {
const { logPlausibleCopyEvent } = useLogPlausibleCopyEvent()
const location = useLocation()
const { downloadConfig, fileFormat } = useDownloadModalQueryParamState()
const isAllAnnotations = downloadConfig === DownloadConfig.AllAnnotations

const s3Command = match({
pathname: location.pathname,
downloadConfig,
isAllAnnotations,
fileFormat,
})
.with(
{ pathname: P.string.includes('/datasets') },
{ downloadConfig: DownloadConfig.AllAnnotations },
{ isAllAnnotations: true },
{ fileFormat: 'zarr' },
() => 'sync' as const,
)
.otherwise(() => 'cp' as const)

const awsCommand = getAwsCommand({ s3Path, s3Command })
const awsCommand = getAwsCommand({ s3Path, s3Command, isAllAnnotations })

return (
<div className="pt-sds-xl">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ export class DownloadDialogActor {
const expectedCommand = getAwsCommand({
s3Path: s3Prefix,
s3Command: 'sync',
isAllAnnotations: true,
})
expect(clipboardValue).toBe(expectedCommand)
}
Expand Down

0 comments on commit adea04e

Please sign in to comment.