Skip to content

Commit fc6b004

Browse files
authored
Merge branch 'LemmyNet:main' into master
2 parents 2bb9b72 + 39f86d4 commit fc6b004

File tree

5 files changed

+24
-55
lines changed

5 files changed

+24
-55
lines changed

src/server/handlers/manifest-handler.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
import { getHttpBaseExternal, getHttpBaseInternal } from "@utils/env";
1+
import { getHttpBaseInternal } from "@utils/env";
22
import type { Request, Response } from "express";
33
import { LemmyHttp } from "lemmy-js-client";
44
import { wrapClient } from "../../shared/services/HttpService";
55
import generateManifestJson from "../utils/generate-manifest-json";
6-
import { setForwardedHeaders } from "../utils/set-forwarded-headers";
76

87
let manifest: Awaited<ReturnType<typeof generateManifestJson>> | undefined =
98
undefined;
109

11-
export default async (req: Request, res: Response) => {
12-
if (!manifest || manifest.start_url !== getHttpBaseExternal()) {
13-
const headers = setForwardedHeaders(req.headers);
14-
const client = wrapClient(
15-
new LemmyHttp(getHttpBaseInternal(), { headers }),
16-
);
10+
export default async (_req: Request, res: Response) => {
11+
if (!manifest) {
12+
const client = wrapClient(new LemmyHttp(getHttpBaseInternal()));
1713
const site = await client.getSite();
1814

1915
if (site.state === "success") {
20-
manifest = await generateManifestJson(site.data);
16+
manifest = await generateManifestJson(site.data.site_view.site);
2117
} else {
2218
res.sendStatus(500);
2319
return;

src/server/utils/generate-manifest-json.ts

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { readFile } from "fs/promises";
2-
import { GetSiteResponse } from "lemmy-js-client";
2+
import { Site } from "lemmy-js-client";
33
import path from "path";
4-
import sharp from "sharp";
54
import { fetchIconPng } from "./fetch-icon-png";
65

76
const iconSizes = [72, 96, 128, 144, 152, 192, 384, 512];
@@ -13,13 +12,7 @@ const defaultLogoPathDirectory = path.join(
1312
"icons",
1413
);
1514

16-
export default async function ({
17-
my_user,
18-
site_view: {
19-
site,
20-
local_site: { community_creation_admin_only },
21-
},
22-
}: GetSiteResponse) {
15+
export default async function (site: Site) {
2316
const icon = site.icon ? await fetchIconPng(site.icon) : null;
2417

2518
return {
@@ -38,6 +31,7 @@ export default async function ({
3831
).then(buf => buf.toString("base64"));
3932

4033
if (icon) {
34+
const sharp = (await import("sharp")).default;
4135
src = await sharp(icon)
4236
.resize(size, size)
4337
.png()
@@ -72,19 +66,7 @@ export default async function ({
7266
short_name: "Create Post",
7367
description: "Create a post.",
7468
},
75-
].concat(
76-
my_user?.local_user_view.local_user.admin ||
77-
!community_creation_admin_only
78-
? [
79-
{
80-
name: "Create Community",
81-
url: "/create_community",
82-
short_name: "Create Community",
83-
description: "Create a community",
84-
},
85-
]
86-
: [],
87-
),
69+
],
8870
related_applications: [
8971
{
9072
platform: "f-droid",

src/shared/components/post/create-post.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { enableDownvotes, enableNsfw, setIsoData } from "@utils/app";
1+
import {
2+
communityToChoice,
3+
enableDownvotes,
4+
enableNsfw,
5+
setIsoData,
6+
} from "@utils/app";
27
import { getIdFromString, getQueryParams } from "@utils/helpers";
38
import type { QueryParams } from "@utils/types";
49
import { Choice, RouteDataResponse } from "@utils/types";
@@ -85,10 +90,9 @@ export class CreatePost extends Component<
8590
};
8691

8792
if (communityRes?.state === "success") {
88-
const communityChoice: Choice = {
89-
label: communityRes.data.community_view.community.title,
90-
value: communityRes.data.community_view.community.id.toString(),
91-
};
93+
const communityChoice = communityToChoice(
94+
communityRes.data.community_view,
95+
);
9296

9397
this.state = {
9498
...this.state,
@@ -107,10 +111,7 @@ export class CreatePost extends Component<
107111
});
108112
if (res.state === "success") {
109113
this.setState({
110-
selectedCommunityChoice: {
111-
label: res.data.community_view.community.title,
112-
value: res.data.community_view.community.id.toString(),
113-
},
114+
selectedCommunityChoice: communityToChoice(res.data.community_view),
114115
loading: false,
115116
});
116117
}

src/shared/components/post/post-form.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -263,26 +263,16 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
263263
community_id: getIdFromString(selectedCommunityChoice.value),
264264
},
265265
communitySearchOptions: [selectedCommunityChoice].concat(
266-
(
267-
this.props.initialCommunities?.map(
268-
({ community: { id, title } }) => ({
269-
label: title,
270-
value: id.toString(),
271-
}),
272-
) ?? []
273-
).filter(option => option.value !== selectedCommunityChoice.value),
266+
(this.props.initialCommunities?.map(communityToChoice) ?? []).filter(
267+
option => option.value !== selectedCommunityChoice.value,
268+
),
274269
),
275270
};
276271
} else {
277272
this.state = {
278273
...this.state,
279274
communitySearchOptions:
280-
this.props.initialCommunities?.map(
281-
({ community: { id, title } }) => ({
282-
label: title,
283-
value: id.toString(),
284-
}),
285-
) ?? [],
275+
this.props.initialCommunities?.map(communityToChoice) ?? [],
286276
};
287277
}
288278

0 commit comments

Comments
 (0)