add new settings redirect_to_flutter

This commit is contained in:
2024-02-03 09:35:41 +08:00
parent 80ad61f3e5
commit c9c92f0bd9
2 changed files with 24 additions and 1 deletions

View File

@@ -3,7 +3,10 @@ import { Handlers, PageProps } from "$fresh/server.ts";
import GlobalContext from "../components/GlobalContext.tsx";
import Container from "../islands/Container.tsx";
import { get_i18nmap, i18n_handle_request } from "../server/i18ns.ts";
import { get_task_manager } from "../server.ts";
import { UserAgent } from "std/http/user_agent.ts";
import { exists } from "std/fs/exists.ts";
import { get_host } from "../server/utils.ts";
type Props = {
lang: string;
@@ -11,13 +14,28 @@ type Props = {
};
export const handler: Handlers<Props> = {
GET(req, ctx) {
async GET(req, ctx) {
const re = i18n_handle_request(req);
const m = get_task_manager();
if (typeof re === "string") {
return ctx.render({
lang: re,
userAgent: req.headers.get("User-Agent"),
});
} else if (m.cfg.redirect_to_flutter) {
let flutter_base = import.meta.resolve("../static/flutter").slice(
7,
);
if (Deno.build.os === "windows") {
flutter_base = flutter_base.slice(1);
}
if (m.cfg.flutter_frontend) {
flutter_base = m.cfg.flutter_frontend;
}
if (!await exists(flutter_base)) {
return re;
}
return Response.redirect(`${get_host(req)}/flutter/`);
}
return re;
},