Docker support, backend SPA mode
This commit is contained in:
@@ -1,9 +1,24 @@
|
||||
import { Treaty, treaty } from "@elysiajs/eden";
|
||||
import type { App } from "backend/app";
|
||||
import { ACCEPTED_MEDIA_TYPES } from "common/MediaType";
|
||||
import { Effect } from "effect";
|
||||
|
||||
export type ResponseEffect<R extends Record<number, unknown>> = Effect.Effect<R[200], Exclude<keyof R, 200> extends never ? never : { [Status in keyof R]: { status: Status, value: R[Status] } }[Exclude<keyof R, 200>]>;
|
||||
|
||||
export const client = treaty<App>("localhost:3000", { fetch: { credentials: "include" } });
|
||||
export const client = treaty<App>(process.env.NODE_ENV === "production" ? "" : "localhost:3000", {
|
||||
fetch: {
|
||||
credentials: "include",
|
||||
},
|
||||
keepDomain: true,
|
||||
onResponse: async (res) => {
|
||||
const contentType = res.headers.get('Content-Type')?.split(';')[0];
|
||||
if (contentType !== undefined && ACCEPTED_MEDIA_TYPES.includes(contentType)) {
|
||||
const blob = await res.blob();
|
||||
// TODO Decode filename from Content-Disposition header
|
||||
const file = new File([blob], "", { type: contentType });
|
||||
return file;
|
||||
}
|
||||
},
|
||||
}).api;
|
||||
|
||||
export const mapResponse = <R extends Record<number, unknown>>({ error, data }: Treaty.TreatyResponse<R>): ResponseEffect<R> => error !== null ? Effect.fail(error) as any : Effect.succeed(data);
|
||||
|
||||
@@ -201,7 +201,7 @@ function AttachmentRow(props: AttachmentRow.Props) {
|
||||
const url = URL.createObjectURL(data);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = data.name;
|
||||
a.download = props.attachment.filename; // TODO Use `data.name` after Content-Disposition parser is implemented
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}, [props.attachment.attachmentId, props.attachment.pieceId]);
|
||||
|
||||
Reference in New Issue
Block a user