mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-12-22 19:01:26 +00:00
Only generate manifest if it isn't already in memory (#2272)
* Only generate manifest if it isn't already in memory * Remove forward header --------- Co-authored-by: SleeplessOne <insomnia-void@protonmail.com>
This commit is contained in:
parent
fc234716b0
commit
8a722c939c
3 changed files with 10 additions and 32 deletions
|
@ -1 +1 @@
|
|||
Subproject commit 1d3cf4a38da9e8d093b977ff83baaa4dab56af71
|
||||
Subproject commit 45d478e44fb12f0748640cf0416724e42e37d9a6
|
|
@ -1,23 +1,19 @@
|
|||
import { getHttpBaseExternal, getHttpBaseInternal } from "@utils/env";
|
||||
import { getHttpBaseInternal } from "@utils/env";
|
||||
import type { Request, Response } from "express";
|
||||
import { LemmyHttp } from "lemmy-js-client";
|
||||
import { wrapClient } from "../../shared/services/HttpService";
|
||||
import generateManifestJson from "../utils/generate-manifest-json";
|
||||
import { setForwardedHeaders } from "../utils/set-forwarded-headers";
|
||||
|
||||
let manifest: Awaited<ReturnType<typeof generateManifestJson>> | undefined =
|
||||
undefined;
|
||||
|
||||
export default async (req: Request, res: Response) => {
|
||||
if (!manifest || manifest.start_url !== getHttpBaseExternal()) {
|
||||
const headers = setForwardedHeaders(req.headers);
|
||||
const client = wrapClient(
|
||||
new LemmyHttp(getHttpBaseInternal(), { headers }),
|
||||
);
|
||||
export default async (_req: Request, res: Response) => {
|
||||
if (!manifest) {
|
||||
const client = wrapClient(new LemmyHttp(getHttpBaseInternal()));
|
||||
const site = await client.getSite();
|
||||
|
||||
if (site.state === "success") {
|
||||
manifest = await generateManifestJson(site.data);
|
||||
manifest = await generateManifestJson(site.data.site_view.site);
|
||||
} else {
|
||||
res.sendStatus(500);
|
||||
return;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { readFile } from "fs/promises";
|
||||
import { GetSiteResponse } from "lemmy-js-client";
|
||||
import { Site } from "lemmy-js-client";
|
||||
import path from "path";
|
||||
import sharp from "sharp";
|
||||
import { fetchIconPng } from "./fetch-icon-png";
|
||||
|
||||
const iconSizes = [72, 96, 128, 144, 152, 192, 384, 512];
|
||||
|
@ -13,13 +12,7 @@ const defaultLogoPathDirectory = path.join(
|
|||
"icons",
|
||||
);
|
||||
|
||||
export default async function ({
|
||||
my_user,
|
||||
site_view: {
|
||||
site,
|
||||
local_site: { community_creation_admin_only },
|
||||
},
|
||||
}: GetSiteResponse) {
|
||||
export default async function (site: Site) {
|
||||
const icon = site.icon ? await fetchIconPng(site.icon) : null;
|
||||
|
||||
return {
|
||||
|
@ -38,6 +31,7 @@ export default async function ({
|
|||
).then(buf => buf.toString("base64"));
|
||||
|
||||
if (icon) {
|
||||
const sharp = (await import("sharp")).default;
|
||||
src = await sharp(icon)
|
||||
.resize(size, size)
|
||||
.png()
|
||||
|
@ -72,19 +66,7 @@ export default async function ({
|
|||
short_name: "Create Post",
|
||||
description: "Create a post.",
|
||||
},
|
||||
].concat(
|
||||
my_user?.local_user_view.local_user.admin ||
|
||||
!community_creation_admin_only
|
||||
? [
|
||||
{
|
||||
name: "Create Community",
|
||||
url: "/create_community",
|
||||
short_name: "Create Community",
|
||||
description: "Create a community",
|
||||
},
|
||||
]
|
||||
: [],
|
||||
),
|
||||
],
|
||||
related_applications: [
|
||||
{
|
||||
platform: "f-droid",
|
||||
|
|
Loading…
Reference in a new issue