Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from bcgov/feature/urlLink
Browse files Browse the repository at this point in the history
direct link
  • Loading branch information
TimCsaky authored Sep 1, 2022
2 parents a5367f5 + 5f07a3c commit 45a7033
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions app/frontend/src/services/comsService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { comsAxios } from '@/services/interceptors';
import Vue from 'vue';

// Calls to the COMS API
export default {
Expand Down Expand Up @@ -40,7 +39,7 @@ export default {
responseType: 'blob',
params: {
versionId: versionId,
download: download
download: 'proxy'
}
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
Expand All @@ -51,24 +50,15 @@ export default {
link.click();
});
} else {
// Not sure how to do opaqueredirect with axios so leaning back to fetch for this one
// https://github.com/axios/axios/issues/932
const url = comsAxios();
const auth = `Bearer ${Vue.prototype.$keycloak.token}`;
return fetch(`${url.defaults.baseURL}/object/${objectId}`, {
redirect: 'manual',
headers: {
'Authorization': auth
}
}).then((res) => {
if (res.type === 'opaqueredirect') {
window.open(
res.url,
'_blank'
);
} else {
throw new Error(`Not a redirect. Status: ${res.status}`);
// Get just the link to the unlocked object store entity and open it
comsAxios().get(`/object/${objectId}`, {
params: {
versionId: versionId,
download: 'url'
}
}).then((response) => {
const url = response.data;
window.open(url, '_blank');
});
}
},
Expand All @@ -80,7 +70,7 @@ export default {
*/
listObjects(params = {}) {
// remove objId array if its first element is undefined
if( params.objId && params.objId[0] === undefined) delete params.objId;
if (params.objId && params.objId[0] === undefined) delete params.objId;
return comsAxios().get('/object', { params: params });
},

Expand Down

0 comments on commit 45a7033

Please sign in to comment.