Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix download url #285

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions web/src/views/DandisetLandingView/DownloadDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@
label="Draft"
value="draft"
/>
<v-radio
label="Latest version"
value="latest"
/>
<v-radio
label="Other version"
value="other"
Expand Down Expand Up @@ -96,16 +92,16 @@
</v-expansion-panel>
<v-expansion-panel>
<v-expansion-panel-header>
Don't have DANDI CLI?
Don't have the DANDI CLI?
</v-expansion-panel-header>
<v-expansion-panel-content>
<v-list>
<v-list-item>
Install the Python client (DANDI CLI)
in a Python 3.8+ environment using command:
in a Python 3.9+ environment using command:
</v-list-item>
<v-list-item>
<kbd>pip install "dandi>=0.60.0"</kbd>
<kbd>pip install dandi</kbd>
</v-list-item>
</v-list>
</v-expansion-panel-content>
Expand All @@ -120,18 +116,23 @@ import { computed, ref } from 'vue';
import { useDandisetStore } from '@/stores/dandiset';
import CopyText from '@/components/CopyText.vue';

function downloadCommand(identifier: string, version: string): string {
// Use the special 'DANDI:' url prefix if appropriate.
const generalUrl = `${window.location.origin}/dandiset/${identifier}`;
const dandiUrl = `DANDI:${identifier}`;
const url = window.location.origin == 'https://dandiarchive.org' ? dandiUrl : generalUrl;
function formatDownloadCommand(identifier: string, version: string): string {
const baseUrl = import.meta.env.VITE_APP_DANDI_API_ROOT === 'https://staging-api.lincbrain.org/api/'
? 'https://staging.lincbrain.org/dandiset/'
: 'https://lincbrain.org/dandiset/';

if (version === 'draft') {
return `dandi download ${baseUrl}${identifier}/draft`;
}

// Prepare a url suffix to specify a specific version (or not).
const versionPath = version ? `/${version}` : '';
if (!version) {
return `dandi download ${baseUrl}${identifier}`;
}

return `dandi download ${url}${versionPath}`;
return `dandi download ${baseUrl}${identifier}/${version}`;
}


const store = useDandisetStore();

const currentDandiset = computed(() => store.dandiset);
Expand All @@ -149,23 +150,23 @@ const availableVersions = computed(
);

const defaultDownloadText = computed(
() => (identifier.value ? downloadCommand(identifier.value, currentVersion.value) : ''),
() => (identifier.value ? formatDownloadCommand(identifier.value, currentVersion.value) : ''),
);

const customDownloadText = computed(() => {
if (!identifier.value) {
return '';
}
if (selectedDownloadOption.value === 'draft') {
return downloadCommand(identifier.value, 'draft');
return formatDownloadCommand(identifier.value, 'draft');
} if (selectedDownloadOption.value === 'latest') {
return downloadCommand(identifier.value, '');
return formatDownloadCommand(identifier.value, '');
} if (selectedDownloadOption.value === 'other') {
return downloadCommand(
return formatDownloadCommand(
identifier.value,
availableVersions.value[selectedVersion.value].version,
);
}
return '';
});
</script>
</script>
Loading