mirror of
https://github.com/growthbook/growthbook.git
synced 2021-08-07 14:23:53 +03:00
- Load front-end environment variables at runtime instead of buildtime - Add root Dockerfile and docker-compose.yml - Update CI to push docker images to Docker Hub - Update quick start in README to use `docker-compose up -d` instead of `yarn dev`
32 lines
701 B
TypeScript
32 lines
701 B
TypeScript
import { ApiCallType } from "./auth";
|
|
import { getApiHost } from "./env";
|
|
|
|
export async function uploadFile(
|
|
apiCall: ApiCallType<{ uploadURL: string; fileURL: string }>,
|
|
file: File
|
|
) {
|
|
const ext = file.name.split(".").reverse()[0];
|
|
const { uploadURL, fileURL } = await apiCall(`/upload/${ext}`, {
|
|
method: "POST",
|
|
});
|
|
|
|
const res = await fetch(
|
|
uploadURL.match(/^\//) ? getApiHost() + uploadURL : uploadURL,
|
|
{
|
|
method: "PUT",
|
|
headers: {
|
|
"Content-Type": file.type,
|
|
},
|
|
body: file,
|
|
}
|
|
);
|
|
|
|
if (!res.ok) {
|
|
throw new Error("Failed to upload file");
|
|
}
|
|
|
|
return {
|
|
fileURL: fileURL.match(/^\//) ? getApiHost() + fileURL : fileURL,
|
|
};
|
|
}
|