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

Fixes Static URL Fix Auth Headers #189

Open
wants to merge 3 commits into
base: cosign/dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
33 changes: 32 additions & 1 deletion src/api/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import {CONFIG }from '../config/config';
import axiosInstance from './axiosInstance';

export default {
async saveAsFile(data, filename, filetype) {
let blob = new Blob([data], { type: filetype });
Expand All @@ -23,5 +26,33 @@ export default {
}

return str;
}
},
async downloadFileURL(name, asset, url) {
const fullUrl = `${url}api/info/download?challenge=${name}&asset=${asset}`;

try {
const response = await axiosInstance({
method: 'get',
url: fullUrl,
responseType: 'blob', // Ensure binary data is handled properly
});

const blob = new Blob([response.data]);
const downloadUrl = window.URL.createObjectURL(blob);

// Create a link element and trigger the download
const link = document.createElement('a');
link.href = downloadUrl;
link.setAttribute('download', asset); // Set the filename
document.body.appendChild(link);
link.click();
link.remove();

return downloadUrl;
} catch (error) {
console.error('There has been a problem with your axios operation:', error);
}
}

};

6 changes: 4 additions & 2 deletions src/components/ChallCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
import FlagService from "../api/userAPI";
import Button from "@/components/Button.vue";
import HintsService from "../api/admin/hintsAPI";
import Utils from "../api/utils";
import { CONFIG } from "@/config/config";

export default {
Expand Down Expand Up @@ -265,8 +266,9 @@ export default {
}
},
getStaticUrl(name, asset) {
let url = CONFIG.staticRoot;
return `${url}api/info/download?challenge=${name}&asset=${asset}`;
const url = CONFIG.staticRoot;
const downloadUrl = Utils.downloadFileURL(name, asset, url);
return downloadUrl;
},
getFileFromAsset(asset) {
let paths = asset.split("/");
Expand Down
6 changes: 4 additions & 2 deletions src/views/AdminChallenge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ import { play, purge, undeploy, edit } from "../constants/images";
import SpinLoader from "../components/spinLoader.vue";
import { CONFIG } from "@/config/config";
import EditChallModal from "../components/EditChallModal.vue";
import Utils from "../api/utils"
export default {
components: { BarGraphVertical, AdminTable, SpinLoader, EditChallModal },
name: "AdminChallenge",
Expand Down Expand Up @@ -248,8 +249,9 @@ export default {
return `${CONFIG.webRoot}:${port}`;
},
getStaticUrl(name, asset) {
let url = CONFIG.staticRoot;
return `${url}api/info/download?challenge=${name}&asset=${asset}`;
const url = CONFIG.staticRoot;
const downloadUrl = Utils.downloadFileURL(name, asset,url);
return downloadUrl;
},
getFileFromAsset(asset) {
let paths = asset.split("/");
Expand Down