Artifact download
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Armin Friedl 2020-07-21 22:01:37 +02:00
parent a07379ebad
commit 864e007cb3
Signed by: armin
GPG key ID: 48C726EEE7FBCBC8
5 changed files with 18 additions and 22 deletions

View file

@ -52,6 +52,7 @@ public class FlingWebSecurityConfigurer extends WebSecurityConfigurerAdapter {
http http
.csrf().disable() .csrf().disable()
.cors(withDefaults()) .cors(withDefaults())
.headers().frameOptions().disable().and()
/**********************************************/ /**********************************************/
/** Authentication Interceptor Configuration **/ /** Authentication Interceptor Configuration **/

View file

@ -30,7 +30,7 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException { FilterChain filterChain) throws ServletException, IOException {
String derivedToken = request.getParameter("derivedtoken"); String derivedToken = request.getParameter("derivedToken");
if (derivedToken == null) { if (derivedToken == null) {
log.info("No derived token in request for {} {}{}", request.getMethod(), log.info("No derived token in request for {} {}{}", request.getMethod(),
request.getRequestURL(), request.getRequestURL(),

View file

@ -1129,7 +1129,7 @@
"@fling/flingclient": { "@fling/flingclient": {
"version": "0.1.0-snapshot", "version": "0.1.0-snapshot",
"resolved": "https://nexus.friedl.net/repository/npm-private/@fling/flingclient/-/flingclient-0.1.0-snapshot.tgz", "resolved": "https://nexus.friedl.net/repository/npm-private/@fling/flingclient/-/flingclient-0.1.0-snapshot.tgz",
"integrity": "sha512-L7csowwIzJx6A3Jgm/ejrgoClPyTimrMGM2ezChklgV/FI/4OJAuk3eYJ8IM9rkT59/Zm4B8z6xmM4GOquuncQ==", "integrity": "sha512-P3JWlmnaYYpj5xS5EFp94OVZXSG9lJbraKlQE4SHnTctxLv3OaR4XOaO7j/FJFygJ3KhOLqVi0x8gQQEDnlMBQ==",
"requires": { "requires": {
"@babel/cli": "^7.0.0", "@babel/cli": "^7.0.0",
"superagent": "3.7.0" "superagent": "3.7.0"

View file

@ -2,36 +2,31 @@ import log from 'loglevel';
import React, { useState, useEffect, useRef } from 'react'; import React, { useState, useEffect, useRef } from 'react';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { ArtifactClient, FlingClient } from '../../util/fc'; import { ArtifactClient, FlingClient, AuthClient } from '../../util/fc';
import { prettifyTimestamp } from '../../util/fn'; import { prettifyTimestamp } from '../../util/fn';
function FlingArtifactControl(props) { function FlingArtifactControl(props) {
let iframeContainer = useRef(null); let iframeContainer = useRef(null);
const artifactClient = new ArtifactClient(); const artifactClient = new ArtifactClient();
const authClient = new AuthClient();
function handleDelete(ev) { function handleDelete(ev) {
artifactClient.deleteArtifact(props.artifact.id) artifactClient.deleteArtifact(props.artifact.id)
.then(() => props.reloadArtifactsFn()); .then(() => props.reloadArtifactsFn());
} }
function handleDownload(ev) { function handleDownload(ev) {
artifactClient.downloadArtifactWithHttpInfo(props.artifact.id) authClient.deriveToken({ singleUse: true })
.then(response => { .then(token => {
log.info(response.headers); // We need this iframe hack because with a regular href, while
var blob = new Blob([response.data], {type: response.type}); // the browser downloads the file fine, it also reloads the page, hence
if(window.navigator.msSaveOrOpenBlob) { // loosing all logs and state
window.navigator.msSaveBlob(blob, response.name); let frame = document.createElement("iframe");
} let url = `${process.env.REACT_APP_API.replace(/\/+$/, '')}/api/artifacts/${props.artifact.id}/data?derivedToken=${token}`;
else{ log.trace(`Generated download url: ${url}`);
var elem = window.document.createElement('a'); frame.src = url;
elem.href = window.URL.createObjectURL(blob); iframeContainer.current.appendChild(frame);
elem.download = response.name; })
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
}
});
} }
return ( return (

View file

@ -25,8 +25,8 @@ function ArtifactClient(token) {
return new fc.ArtifactApi(clientConfig(token)); return new fc.ArtifactApi(clientConfig(token));
} }
function AuthClient() { function AuthClient(token) {
return new fc.AuthApi(clientConfig()); return new fc.AuthApi(clientConfig(token));
} }
export {FlingClient, ArtifactClient, AuthClient, fc}; export {FlingClient, ArtifactClient, AuthClient, fc};