move pwa manifest to backend
This commit is contained in:
parent
7aa9038a61
commit
b4a7986c8a
16 changed files with 724 additions and 11 deletions
|
@ -2,12 +2,13 @@ import { Request, Response } from "express";
|
|||
import CalendarService from "../service/club/calendarService";
|
||||
import CalendarTypeService from "../service/configuration/calendarTypeService";
|
||||
import { calendar } from "../entity/club/calendar";
|
||||
import { createEvents } from "ics";
|
||||
import moment from "moment";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
import CalendarFactory from "../factory/admin/club/calendar";
|
||||
import { CalendarHelper } from "../helpers/calendarHelper";
|
||||
import SettingHelper from "../helpers/settingsHelper";
|
||||
import sharp from "sharp";
|
||||
import ico from "sharp-ico";
|
||||
import { FileSystemHelper } from "../helpers/fileSystemHelper";
|
||||
|
||||
/**
|
||||
* @description get all calendar items by types or nscdr
|
||||
|
@ -71,3 +72,136 @@ export async function getApplicationConfig(req: Request, res: Response): Promise
|
|||
|
||||
res.json(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get application Manifest
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getApplicationManifest(req: Request, res: Response): Promise<any> {
|
||||
const backendUrl = `${req.protocol}://${req.get("host")}`;
|
||||
const frontenUrl = `${req.get("referer")}`;
|
||||
|
||||
const manifest = {
|
||||
id: "ff_admin_webapp",
|
||||
lang: "de",
|
||||
name: SettingHelper.getSetting("club.name"),
|
||||
short_name: SettingHelper.getSetting("club.name"),
|
||||
theme_color: "#990b00",
|
||||
display: "standalone",
|
||||
orientation: "portrait-primary",
|
||||
start_url: frontenUrl,
|
||||
icons: [
|
||||
{
|
||||
src: `${backendUrl}/api/public/favicon.ico`,
|
||||
sizes: "48x48",
|
||||
type: "image/ico",
|
||||
},
|
||||
{
|
||||
src: `${backendUrl}/api/public/icon.png?width=512&height=512`,
|
||||
sizes: "512x512",
|
||||
type: "image/png",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
res.set({
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Content-Type": "application/manifest+json",
|
||||
});
|
||||
|
||||
res.json(manifest);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get application Logo
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getApplicationLogo(req: Request, res: Response): Promise<any> {
|
||||
let setLogo = SettingHelper.getSetting("club.logo");
|
||||
|
||||
res.set({
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Cross-Origin-Resource-Policy": "cross-origin",
|
||||
"Cross-Origin-Embedder-Policy": "credentialless",
|
||||
"Timing-Allow-Origin": "*",
|
||||
});
|
||||
|
||||
if (setLogo == "") {
|
||||
res.sendFile(FileSystemHelper.readAssetFile("admin-logo.png", true));
|
||||
} else {
|
||||
res.sendFile(FileSystemHelper.formatPath("/app/admin-logo.png"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get application Favicon
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getApplicationFavicon(req: Request, res: Response): Promise<any> {
|
||||
let icon = FileSystemHelper.readAssetFile("icon.png", true);
|
||||
let setLogo = SettingHelper.getSetting("club.icon");
|
||||
|
||||
if (setLogo != "") {
|
||||
icon = FileSystemHelper.formatPath("/app/icon.png");
|
||||
}
|
||||
|
||||
let image = await sharp(icon)
|
||||
.resize(48, 48, {
|
||||
fit: "inside",
|
||||
})
|
||||
.png()
|
||||
.toBuffer();
|
||||
|
||||
let buffer = ico.encode([image]);
|
||||
|
||||
res.set({
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Cross-Origin-Resource-Policy": "cross-origin",
|
||||
"Cross-Origin-Embedder-Policy": "credentialless",
|
||||
"Timing-Allow-Origin": "*",
|
||||
});
|
||||
|
||||
res.setHeader("Content-Type", "image/x-icon");
|
||||
res.send(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get application Icon
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getApplicationIcon(req: Request, res: Response): Promise<any> {
|
||||
const width = parseInt((req.query.width as string) ?? "");
|
||||
const height = parseInt((req.query.height as string) ?? "");
|
||||
|
||||
let icon = FileSystemHelper.readAssetFile("icon.png", true);
|
||||
let setLogo = SettingHelper.getSetting("club.icon");
|
||||
|
||||
if (setLogo != "") {
|
||||
icon = FileSystemHelper.formatPath("/app/icon.png");
|
||||
}
|
||||
|
||||
let image = await sharp(icon)
|
||||
.resize(width, height, {
|
||||
fit: "inside",
|
||||
})
|
||||
.png()
|
||||
.toBuffer();
|
||||
|
||||
res.set({
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Cross-Origin-Resource-Policy": "cross-origin",
|
||||
"Cross-Origin-Embedder-Policy": "credentialless",
|
||||
"Timing-Allow-Origin": "*",
|
||||
});
|
||||
|
||||
res.setHeader("Content-Type", "image/png");
|
||||
res.send(image);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue