Skip to content

Commit

Permalink
DPO3DPKRT-769/encoding webdav uri for voyager edit (#558)
Browse files Browse the repository at this point in the history
(new) improved name sanitizing for ingest titles to avoid conflicts with
other systems (e.g. Voyager, Cook, etc.). replaces all special
characters with '-' except for -, _, and .
(new) updated name sanitizing to include all special characters

(fix) switched to encodeURIComponent to handle & correctly in JobCook
(fix) localized encodeURIComponent to right before sending to Voyager
(fix) proper use of encodeURI vs. encodeURIComponent
  • Loading branch information
EMaslowskiQ authored Dec 12, 2023
1 parent c85c581 commit 7ca9f71
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function VoyagerExplorer(props: VoyagerExplorerProps): React.ReactElement {
// this is the script required to run voyager-explorer component
useScript(Config.voyager.explorerJS);

return <voyager-explorer id='Voyager-Explorer' root={root} document={document} style={{ width: width || '300px', height: height || '300px', display: 'block', position: 'relative' }} />;
return <voyager-explorer id='Voyager-Explorer' root={root} document={encodeURIComponent(document)} style={{ width: width || '300px', height: height || '300px', display: 'block', position: 'relative' }} />;
}

export default VoyagerExplorer;
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function VoyagerStory(props: VoyagerStoryProps): React.ReactElement {
<voyager-story
id='Voyager-Story'
root={root}
document={document}
document={encodeURIComponent(document)}
mode={mode}
style={{ width: width || '300px', height: height || '300px', display: 'block', position: 'relative' }}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function DetailsThumbnail(props: DetailsThumbnailProps): React.ReactElement {
return;

const { data: { getVoyagerParams: { path, document, idSystemObjectScene } } } = await getVoyagerParams(idSystemObject);
// console.log(`getVoyagerParams path: ${path}, document: ${document}, idSystemObjectScene ${idSystemObjectScene}`);
// console.log(`getVoyagerParams (path: ${path}, document: ${document}, idSystemObjectScene ${idSystemObjectScene})`);

if (document) {
const root: string = getRootSceneDownloadUrlForVoyager(serverEndpoint, idSystemObjectScene, path, eMode);
Expand Down Expand Up @@ -95,7 +95,7 @@ function DetailsThumbnail(props: DetailsThumbnailProps): React.ReactElement {
variant='contained'
color='primary'
disableElevation
href={getVoyagerStoryUrl(serverEndpoint, idSystemObject ?? 0, documentLink, pathLink, eVoyagerStoryMode.eEdit)}
href={getVoyagerStoryUrl(serverEndpoint, idSystemObject ?? 0, encodeURIComponent(documentLink), pathLink, eVoyagerStoryMode.eEdit)}
target='_blank'
rel='noopener noreferrer'
>
Expand Down
9 changes: 6 additions & 3 deletions client/src/utils/repository.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -341,18 +341,21 @@ export function getRootSceneDownloadUrlForVoyager(serverEndPoint: string | undef
case eVoyagerStoryMode.eAuthor: dlPath='webdav'; break;
case eVoyagerStoryMode.eExpert: dlPath='webdav'; break;
}
return `${serverEndPoint}/${dlPath}/idSystemObject-${idSystemObject}/${path ? path + '/' : ''}`;
const uri: string = `${serverEndPoint}/${dlPath}/idSystemObject-${idSystemObject}/${path ? path + '/' : ''}`;
// console.log(`>>> getVoyagerStoryURL (document: ${document} | dlPath: ${dlPath} | uri: ${uri} | path: ${path})`);
return uri;
}

export function getVoyagerStoryUrl(serverEndPoint: string | undefined, idSystemObject: number,
document: string, path: string, eMode?: eVoyagerStoryMode | undefined): string {

const mode: string = getModeForVoyager(eMode);
const root: string = getRootSceneDownloadUrlForVoyager(serverEndPoint, idSystemObject, path, eMode);
return `/repository/voyager/${idSystemObject}?mode=${mode}&root=${root}&document=${document}`;
const uri: string = `/repository/voyager/${idSystemObject}?mode=${mode}&root=${root}&document=${document}`;
console.log(`>>> getVoyagerStoryURL (document: ${document} | root: ${root} | uri: ${uri} | path: ${path})`);
return uri;
}


// prettier-ignore
export function getTreeViewStyleHeight(isExpanded: boolean, isModal: boolean, breakpoint: Breakpoint): string {
const isSmallScreen: boolean = breakpoint === 'lg';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import * as DBAPI from '../../../../../db';
import * as LOG from '../../../../../utils/logger';

export default async function getIngestTitle(_: Parent, args: QueryGetIngestTitleArgs, _context: Context): Promise<GetIngestTitleResult> {

// The ingest title is tied to the MediaGroup's (item) name and is pulled from EDAN
// when first ingesting. Here we build our title and sanitize it as needed.

const { item, sourceObjects } = args.input;
if (item) {
let itemDB: DBAPI.Item | null = null;
Expand Down
5 changes: 3 additions & 2 deletions server/job/impl/Cook/CookResource.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable camelcase */
/* eslint-disable @typescript-eslint/no-explicit-any */
import axios, { AxiosResponse } from 'axios';
import * as LOG from '../../../utils/logger';
import * as DBAPI from '../../../db';
Expand Down Expand Up @@ -67,8 +68,8 @@ const getCookResourceStatus = async (address: string, port: number): Promise<Coo
};
return result;

} catch (error) {
return { success: false, error: JSON.stringify(error), address, };
} catch (error: any) {
return { success: false, error: (error.message)?error.message:JSON.stringify(error), address, };
}
};
const verifyCookResourceCapability = (job: string, resource: DBAPI.CookResource): number => {
Expand Down
8 changes: 4 additions & 4 deletions server/job/impl/Cook/JobCook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export abstract class JobCook<T> extends JobPackrat {
while (true) {
try {
LOG.info(`JobCook [${this.name()}] creating job: ${requestUrl} body ${JSON.stringify(jobCookPostBody, H.Helpers.saferStringify)}`, LOG.LS.eJOB);
const axiosResponse: AxiosResponse<any> | null = await axios.post(requestUrl, jobCookPostBody);
const axiosResponse: AxiosResponse<any> | null = await axios.post(encodeURI(requestUrl), jobCookPostBody);

if (axiosResponse?.status === 201)
break; // success, continue
Expand Down Expand Up @@ -302,7 +302,7 @@ export abstract class JobCook<T> extends JobPackrat {
while (true) {
try {
LOG.info(`JobCook [${this.name()}] running job: ${requestUrl}`, LOG.LS.eJOB);
const axiosResponse = await axios.patch(requestUrl);
const axiosResponse = await axios.patch(encodeURI(requestUrl));
if (axiosResponse.status === 202)
break; // success, continue
res = { success: false, error: `JobCook [${this.name()}] patch ${requestUrl} failed: ${JSON.stringify(axiosResponse)}` };
Expand Down Expand Up @@ -338,7 +338,7 @@ export abstract class JobCook<T> extends JobPackrat {
LOG.info(`JobCook [${this.name()}] cancelling job: ${requestUrl}`, LOG.LS.eJOB);
while (true) {
try {
const axiosResponse = await axios.patch(requestUrl);
const axiosResponse = await axios.patch(encodeURI(requestUrl));
if (axiosResponse.status !== 200)
res = { success: false, error: `JobCook [${this.name()}] patch ${requestUrl} failed: ${JSON.stringify(axiosResponse)}` };
} catch (error) {
Expand All @@ -365,7 +365,7 @@ export abstract class JobCook<T> extends JobPackrat {
// Get job report via GET to /clients/<CLIENTID>/jobs/<JOBID>/report
const requestUrl: string = this.CookServerURL() + `clients/${this._configuration.clientId}/jobs/${this._configuration.jobId}/report`;
try {
const axiosResponse = await axios.get(requestUrl);
const axiosResponse = await axios.get(encodeURI(requestUrl));
if (axiosResponse.status !== 200) {
// only log errors after first attempt, as job creation may not be complete on Cook server
const error: string = JSON.stringify(axiosResponse);
Expand Down
3 changes: 2 additions & 1 deletion server/utils/nameHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export class NameHelpers {
}

static sanitizeFileName(fileName: string): string {
return sanitize(fileName.replace(/:/g, '-').replace(/ /g, '_'), { replacement: '_' });
return sanitize(fileName.replace(/[\s,]/g, '_').replace(/[^a-zA-Z0-9\-_.]/g, '-'));
//legacy: return sanitize(fileName.replace(/:/g, '-').replace(/ /g, '_'), { replacement: '_' });
}

static computeBaseTitle(name: string, subtitle: string | undefined | null): string {
Expand Down

0 comments on commit 7ca9f71

Please sign in to comment.