diff --git a/config.ts b/config.ts index b072f56..ef2411f 100644 --- a/config.ts +++ b/config.ts @@ -25,6 +25,7 @@ export type ConfigType = { img_verify_secret?: string; meili_hosts?: Record; cors_credentials_hosts: Array; + flutter_frontend?: string; }; export enum ThumbnailMethod { @@ -160,6 +161,9 @@ export class Config { } return []; } + get flutter_frontend() { + return this._return_string("flutter_frontend"); + } to_json(): ConfigType { return { cookies: typeof this.cookies === "string", @@ -185,6 +189,7 @@ export class Config { img_verify_secret: this.img_verify_secret, meili_hosts: this.meili_hosts, cors_credentials_hosts: this.cors_credentials_hosts, + flutter_frontend: this.flutter_frontend, }; } } diff --git a/fresh.gen.ts b/fresh.gen.ts index a61cb3b..ad3c604 100644 --- a/fresh.gen.ts +++ b/fresh.gen.ts @@ -23,10 +23,11 @@ import * as $17 from "./routes/api/token.ts"; import * as $18 from "./routes/api/user.ts"; import * as $19 from "./routes/file/[id].ts"; import * as $20 from "./routes/file/_middleware.ts"; -import * as $21 from "./routes/index.tsx"; -import * as $22 from "./routes/manifest.json.ts"; -import * as $23 from "./routes/thumbnail/[id].ts"; -import * as $24 from "./routes/thumbnail/_middleware.ts"; +import * as $21 from "./routes/flutter/_middleware.ts"; +import * as $22 from "./routes/index.tsx"; +import * as $23 from "./routes/manifest.json.ts"; +import * as $24 from "./routes/thumbnail/[id].ts"; +import * as $25 from "./routes/thumbnail/_middleware.ts"; import * as $$0 from "./islands/Container.tsx"; import * as $$1 from "./islands/Settings.tsx"; import * as $$2 from "./islands/TaskManager.tsx"; @@ -54,10 +55,11 @@ const manifest = { "./routes/api/user.ts": $18, "./routes/file/[id].ts": $19, "./routes/file/_middleware.ts": $20, - "./routes/index.tsx": $21, - "./routes/manifest.json.ts": $22, - "./routes/thumbnail/[id].ts": $23, - "./routes/thumbnail/_middleware.ts": $24, + "./routes/flutter/_middleware.ts": $21, + "./routes/index.tsx": $22, + "./routes/manifest.json.ts": $23, + "./routes/thumbnail/[id].ts": $24, + "./routes/thumbnail/_middleware.ts": $25, }, islands: { "./islands/Container.tsx": $$0, diff --git a/routes/flutter/_middleware.ts b/routes/flutter/_middleware.ts new file mode 100644 index 0000000..5ebb4ec --- /dev/null +++ b/routes/flutter/_middleware.ts @@ -0,0 +1,25 @@ +import { MiddlewareHandlerContext } from "$fresh/server.ts"; +import { get_task_manager } from "../../server.ts"; +import { join } from "std/path/mod.ts"; +import { exists } from "std/fs/exists.ts"; +import { + get_file_response, + GetFileResponseOptions, +} from "../../server/get_file_response.ts"; + +export async function handler(req: Request, _ctx: MiddlewareHandlerContext) { + const m = get_task_manager(); + if (!m.cfg.flutter_frontend) { + return new Response("Flutter frontend is not enabled", { status: 404 }); + } + const u = new URL(req.url); + let p = join(m.cfg.flutter_frontend, u.pathname); + if (!(await exists(p))) { + p = join(m.cfg.flutter_frontend, "/index.html"); + } + const opts: GetFileResponseOptions = {}; + opts.range = req.headers.get("range"); + opts.if_modified_since = req.headers.get("If-Modified-Since"); + opts.if_unmodified_since = req.headers.get("If-Unmodified-Since"); + return await get_file_response(p, opts); +}