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

use substitutions for external service endpoints #1690

Closed
wants to merge 5 commits into from
Closed
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
34 changes: 27 additions & 7 deletions web/src/views/FileBrowserView/FileBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ import axios from 'axios';

import { dandiRest } from '@/rest';
import { useDandisetStore } from '@/stores/dandiset';
import type { AssetFile, AssetPath } from '@/types';
import type { AssetPath } from '@/types';
import FileBrowserPagination from '@/components/FileBrowser/FileBrowserPagination.vue';
import FileUploadInstructions from '@/components/FileBrowser/FileUploadInstructions.vue';

Expand Down Expand Up @@ -309,35 +309,35 @@ const EXTERNAL_SERVICES = [
name: 'Bioimagesuite/Viewer',
regex: /\.nii(\.gz)?$/,
maxsize: 1e9,
endpoint: 'https://bioimagesuiteweb.github.io/unstableapp/viewer.html?image=',
endpoint: 'https://bioimagesuiteweb.github.io/unstableapp/viewer.html?image=$asset_s3_download_url$',
},

{
name: 'MetaCell/NWBExplorer',
regex: /\.nwb$/,
maxsize: 1e9,
endpoint: 'http://nwbexplorer.opensourcebrain.org/nwbfile=',
endpoint: 'http://nwbexplorer.opensourcebrain.org/nwbfile=$asset_s3_download_url$',
},

{
name: 'VTK/ITK Viewer',
regex: /\.ome\.zarr$/,
maxsize: Infinity,
endpoint: 'https://kitware.github.io/itk-vtk-viewer/app/?gradientOpacity=0.3&image=',
endpoint: 'https://kitware.github.io/itk-vtk-viewer/app/?gradientOpacity=0.3&image=$asset_s3_download_url$',
},

{
name: 'OME Zarr validator',
regex: /\.ome\.zarr$/,
maxsize: Infinity,
endpoint: 'https://ome.github.io/ome-ngff-validator/?source=',
endpoint: 'https://ome.github.io/ome-ngff-validator/?source=$asset_s3_download_url$',
},

{
name: 'Neurosift',
regex: /\.nwb$/,
maxsize: Infinity,
endpoint: 'https://flatironinstitute.github.io/neurosift?p=/nwb&url=',
endpoint: 'https://flatironinstitute.github.io/neurosift?p=/nwb&url=$asset_api_download_url$',
},
];
type Service = typeof EXTERNAL_SERVICES[0];
Expand Down Expand Up @@ -377,18 +377,38 @@ const isOwner = computed(() => !!(
));
const itemsNotFound = computed(() => items.value && !items.value.length);

function replaceStringsInEndpoint(
endpoint: string,
substitutions: {[key: string]: string} | undefined,
) {
if (!substitutions) return endpoint;
let result = endpoint;
Object.entries(substitutions).forEach(([key, value]) => {
result = result.replace(key, value);
});
return result;
}

function getExternalServices(path: AssetPath) {
const servicePredicate = (service: Service, _path: AssetPath) => (
new RegExp(service.regex).test(path.path)
&& _path.asset !== null
&& _path.aggregate_size <= service.maxsize
);

const baseApiUrl = trimEnd(process.env.VUE_APP_DANDI_API_ROOT, '/');

const substitutions = path.asset ? {
$asset_s3_download_url$: trimEnd(path.asset.url, '/'),
$asset_api_download_url$: `${baseApiUrl}/assets/${path.asset.asset_id}/download/`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@waxlamp - actually one of the things i wanted in the other PR is the dandiset specific asset download url, not the general one. that would allow in essence for someone to fetch relevant dandiset info or for externallinks such as videos, the video url. also since this is clicked not from a global search but a view within the dandiset, i think it's appropriate to have the other url.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the other PR

Do you mean #1655 or #1692?

dandiset specific asset download url, not the general one

When you say "dandiset specific", do you mean the longer URL that is "nested" under a /dandisets/{dandiset_id}/... URL?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct - sorry was in meetings. yes, i would like that asset url to change to the one that is nested under /dandisets/

$asset_id$: path.asset.asset_id,
} : undefined;

return EXTERNAL_SERVICES
.filter((service) => servicePredicate(service, path))
.map((service) => ({
name: service.name,
url: `${service.endpoint}${trimEnd((path.asset as AssetFile).url, '/')}`,
url: replaceStringsInEndpoint(service.endpoint, substitutions),
}));
}

Expand Down