import { withStyles, WithStyles } from '@material-ui/core';
import { FileTreeData } from '~/components/file-tree/file-tree-data';
import { CollectionFileType } from '~/models/collection-file';
-import { sanitizeToken } from "~/views-components/context-menu/actions/helpers";
+import { getInlineFileUrl, sanitizeToken } from "~/views-components/context-menu/actions/helpers";
+import { connect } from "react-redux";
+import { RootState } from "~/store/store";
export interface FileThumbnailProps {
file: FileTreeData;
}
}));
-const ImageFileThumbnail = imageFileThumbnailStyle(
- ({ classes, file }: WithStyles<ImageFileThumbnailCssRules> & FileThumbnailProps) =>
+interface ImageFileThumbnailProps {
+ keepWebServiceUrl: string;
+ keepWebInlineServiceUrl: string;
+}
+
+const mapStateToProps = ({ auth }: RootState): ImageFileThumbnailProps => ({
+ keepWebServiceUrl: auth.config.keepWebServiceUrl,
+ keepWebInlineServiceUrl: auth.config.keepWebInlineServiceUrl,
+});
+
+const ImageFileThumbnail = connect(mapStateToProps)(imageFileThumbnailStyle(
+ ({ classes, file, keepWebServiceUrl, keepWebInlineServiceUrl }: WithStyles<ImageFileThumbnailCssRules> & FileThumbnailProps & ImageFileThumbnailProps) =>
<img
className={classes.thumbnail}
alt={file.name}
- src={sanitizeToken(file.url)} />
-);
+ src={sanitizeToken(getInlineFileUrl(file.url, keepWebServiceUrl, keepWebInlineServiceUrl))} />
+));
import { FileViewerAction } from '~/views-components/context-menu/actions/file-viewer-action';
import { getNodeValue } from "~/models/tree";
import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
+import { getInlineFileUrl, sanitizeToken } from "./helpers";
const mapStateToProps = (state: RootState) => {
const { resource } = state.contextMenu;
resource.menuKind === ContextMenuKind.READONLY_COLLECTION_FILES_ITEM)) {
const file = getNodeValue(resource.uuid)(state.collectionPanelFiles);
if (file) {
+ const fileUrl = sanitizeToken(getInlineFileUrl(
+ file.url,
+ state.auth.config.keepWebServiceUrl,
+ state.auth.config.keepWebInlineServiceUrl), true);
return {
- href: file.url.replace(state.auth.config.keepWebServiceUrl, state.auth.config.keepWebInlineServiceUrl),
+ href: fileUrl,
kind: 'file',
currentCollectionUuid
};
// SPDX-License-Identifier: AGPL-3.0
import * as React from "react";
-import { connect } from 'react-redux';
import { ListItemIcon, ListItemText, ListItem } from "@material-ui/core";
import { OpenIcon } from "~/components/icon/icon";
-import { sanitizeToken } from "./helpers";
-import { RootState } from "~/store/store";
export const FileViewerAction = (props: any) => {
- const {
- keepWebServiceUrl,
- keepWebInlineServiceUrl,
- } = props;
-
return props.href
? <a
style={{ textDecoration: 'none' }}
- href={sanitizeToken(props.href.replace(keepWebServiceUrl, keepWebInlineServiceUrl), true)}
+ href={props.href}
target="_blank"
onClick={props.onClick}>
<ListItem button>
</a>
: null;
};
-
-const mapStateToProps = ({ auth }: RootState): any => ({
- keepWebServiceUrl: auth.config.keepWebServiceUrl,
- keepWebInlineServiceUrl: auth.config.keepWebInlineServiceUrl,
-});
-
-
-export default connect(mapStateToProps, null)(FileViewerAction);
//
// SPDX-License-Identifier: AGPL-3.0
-import { sanitizeToken, getClipboardUrl } from "./helpers";
+import { sanitizeToken, getClipboardUrl, getInlineFileUrl } from "./helpers";
describe('helpers', () => {
// given
expect(result).toBe('http://localhost?redirectTo=https://example.com/c=zzzzz/LIMS/1.html');
});
});
+
+ describe('getInlineFileUrl', () => {
+ it('should add the collection\'s uuid to the hostname', () => {
+ // when
+ const webDavUrlA = 'https://*.collections.example.com/';
+ const webDavUrlB = 'https://*--collections.example.com/';
+ const webDavDownloadUrl = 'https://example.com/';
+
+ // then
+ expect(getInlineFileUrl(url, webDavDownloadUrl, webDavUrlA))
+ .toBe('https://zzzzz.collections.example.com/t=v2/a/b/LIMS/1.html');
+ expect(getInlineFileUrl(url, webDavDownloadUrl, webDavUrlB))
+ .toBe('https://zzzzz--collections.example.com/t=v2/a/b/LIMS/1.html');
+ });
+
+ it('should keep the url the same when no inline url available', () => {
+ // when
+ const webDavUrl = '';
+ const webDavDownloadUrl = 'https://example.com/';
+ const result = getInlineFileUrl(url, webDavDownloadUrl, webDavUrl);
+
+ // then
+ expect(result).toBe('https://example.com/c=zzzzz/t=v2/a/b/LIMS/1.html');
+ });
+
+ it('should replace the url when available', () => {
+ // when
+ const webDavUrl = 'https://download.example.com/';
+ const webDavDownloadUrl = 'https://example.com/';
+ const result = getInlineFileUrl(url, webDavDownloadUrl, webDavUrl);
+
+ // then
+ expect(result).toBe('https://download.example.com/c=zzzzz/t=v2/a/b/LIMS/1.html');
+ });
+ });
});
\ No newline at end of file
return shouldSanitizeToken ? `${origin}?redirectTo=${url}` : `${origin}${url}`;
};
+
+export const getInlineFileUrl = (url: string, keepWebSvcUrl: string, keepWebInlineSvcUrl: string): string => {
+ const collUuidMatch = url.match(/\/c=([a-z0-9-]+)\//);
+ if (collUuidMatch === null) { return ''; }
+ const collUuid = collUuidMatch[1];
+ let inlineUrl = keepWebInlineSvcUrl !== ""
+ ? url.replace(keepWebSvcUrl, keepWebInlineSvcUrl)
+ : url;
+ let uuidOnHostname = false;
+ // Inline URLs as 'https://*.collections.example.com' or
+ // 'https://*--collections.example.com' should get the uuid on their hostnames
+ // See: https://doc.arvados.org/v2.1/api/keep-web-urls.html
+ if (inlineUrl.indexOf('*.') > -1) {
+ inlineUrl = inlineUrl.replace('*.', `${collUuid}.`);
+ uuidOnHostname = true;
+ } else if (inlineUrl.indexOf('*--') > -1) {
+ inlineUrl = inlineUrl.replace('*--', `${collUuid}--`);
+ uuidOnHostname = true;
+ }
+ if (uuidOnHostname) {
+ inlineUrl = inlineUrl.replace(`/c=${collUuid}`, '');
+ }
+ return inlineUrl;
+};
\ No newline at end of file