]> Untitled Git - lemmy-ui.git/blob - src/server/utils/generate-manifest-json.ts
just remove sharp actually
[lemmy-ui.git] / src / server / utils / generate-manifest-json.ts
1 import { readFile } from "fs/promises";
2 import { GetSiteResponse } from "lemmy-js-client";
3 import path from "path";
4
5 const iconSizes = [72, 96, 128, 144, 152, 192, 384, 512];
6
7 const defaultLogoPathDirectory = path.join(
8   process.cwd(),
9   "dist",
10   "assets",
11   "icons",
12 );
13
14 export default async function ({
15   my_user,
16   site_view: {
17     site,
18     local_site: { community_creation_admin_only },
19   },
20 }: GetSiteResponse) {
21   return {
22     name: site.name,
23     description: site.description ?? "A link aggregator for the fediverse",
24     start_url: "/",
25     scope: "/",
26     display: "standalone",
27     id: "/",
28     background_color: "#222222",
29     theme_color: "#222222",
30     icons: await Promise.all(
31       iconSizes.map(async size => {
32         const src = await readFile(
33           path.join(defaultLogoPathDirectory, `icon-${size}x${size}.png`),
34         ).then(buf => buf.toString("base64"));
35
36         return {
37           sizes: `${size}x${size}`,
38           type: "image/png",
39           src: `data:image/png;base64,${src}`,
40           purpose: "any maskable",
41         };
42       }),
43     ),
44     shortcuts: [
45       {
46         name: "Search",
47         short_name: "Search",
48         description: "Perform a search.",
49         url: "/search",
50       },
51       {
52         name: "Communities",
53         url: "/communities",
54         short_name: "Communities",
55         description: "Browse communities",
56       },
57       {
58         name: "Create Post",
59         url: "/create_post",
60         short_name: "Create Post",
61         description: "Create a post.",
62       },
63     ].concat(
64       my_user?.local_user_view.person.admin || !community_creation_admin_only
65         ? [
66             {
67               name: "Create Community",
68               url: "/create_community",
69               short_name: "Create Community",
70               description: "Create a community",
71             },
72           ]
73         : [],
74     ),
75     related_applications: [
76       {
77         platform: "f-droid",
78         url: "https://f-droid.org/packages/com.jerboa/",
79         id: "com.jerboa",
80       },
81     ],
82   };
83 }