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 3 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
37 changes: 30 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,41 @@ 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;
}

const isStaging = process.env.VUE_APP_SENTRY_ENVIRONMENT === 'staging';

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 = isStaging
? 'https://api-staging.dandiarchive.org'
: 'https://api.dandiarchive.org';
yarikoptic marked this conversation as resolved.
Show resolved Hide resolved
const substitutions = path.asset ? {
$asset_s3_download_url$: trimEnd(path.asset.url, '/'),
$asset_api_download_url$: `${baseApiUrl}/api/assets/${path.asset.asset_id}/download/`,
yarikoptic marked this conversation as resolved.
Show resolved Hide resolved
$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