From 8a722c939c04f21299af7b3c4961a5c25b7f6903 Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 Date: Wed, 6 Dec 2023 13:57:31 +0000 Subject: [PATCH] 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 --- lemmy-translations | 2 +- src/server/handlers/manifest-handler.ts | 14 +++++------- src/server/utils/generate-manifest-json.ts | 26 ++++------------------ 3 files changed, 10 insertions(+), 32 deletions(-) diff --git a/lemmy-translations b/lemmy-translations index 1d3cf4a3..45d478e4 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit 1d3cf4a38da9e8d093b977ff83baaa4dab56af71 +Subproject commit 45d478e44fb12f0748640cf0416724e42e37d9a6 diff --git a/src/server/handlers/manifest-handler.ts b/src/server/handlers/manifest-handler.ts index fced7bd6..158608d7 100644 --- a/src/server/handlers/manifest-handler.ts +++ b/src/server/handlers/manifest-handler.ts @@ -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> | 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; diff --git a/src/server/utils/generate-manifest-json.ts b/src/server/utils/generate-manifest-json.ts index dd56bc3c..5571a39a 100644 --- a/src/server/utils/generate-manifest-json.ts +++ b/src/server/utils/generate-manifest-json.ts @@ -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",