Add API_HOST to upload/download

This commit is contained in:
Kieran 2022-02-26 12:44:29 +00:00
parent d82c43bb3e
commit bd2464bd47
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
4 changed files with 9 additions and 5 deletions

View File

@ -1,7 +1,5 @@
import {useSelector} from "react-redux"; import {useSelector} from "react-redux";
import preval from "preval.macro"; import {ApiHost} from "./Const";
const ApiHost = preval`module.exports = process.env.API_HOST || '';`;
export function useApi() { export function useApi() {
const auth = useSelector(state => state.login.jwt); const auth = useSelector(state => state.login.jwt);

View File

@ -1,3 +1,7 @@
import preval from "preval.macro";
export const ApiHost = preval`module.exports = process.env.API_HOST || '';`;
/** /**
* @constant {number} - Size of 1 kiB * @constant {number} - Size of 1 kiB
*/ */

View File

@ -8,6 +8,7 @@ import {FilePaywall} from "./FilePaywall";
import {useApi} from "./Api"; import {useApi} from "./Api";
import {Helmet} from "react-helmet"; import {Helmet} from "react-helmet";
import {FormatBytes} from "./Util"; import {FormatBytes} from "./Util";
import {ApiHost} from "./Const";
export function FilePreview() { export function FilePreview() {
const {Api} = useApi(); const {Api} = useApi();
@ -92,9 +93,9 @@ export function FilePreview() {
if (order) { if (order) {
let orderObj = JSON.parse(order); let orderObj = JSON.parse(order);
setOrder(orderObj); setOrder(orderObj);
setLink(`/d/${info.id}?orderId=${orderObj.id}`); setLink(`${ApiHost}/d/${info.id}?orderId=${orderObj.id}`);
} else { } else {
setLink(`/d/${info.id}`); setLink(`${ApiHost}/d/${info.id}`);
} }
} }
}, [info]); }, [info]);

View File

@ -120,6 +120,7 @@ export function FileUpload(props) {
if (typeof (editSecret) === "string") { if (typeof (editSecret) === "string") {
req.setRequestHeader("V-EditSecret", editSecret); req.setRequestHeader("V-EditSecret", editSecret);
} }
req.withCredentials = true;
req.send(segment); req.send(segment);
} catch (e) { } catch (e) {
reject(e); reject(e);