// manifest.js // Copyright (C) 2022,2023 DTP Technologies, LLC // All Rights Reserved 'use strict'; const DTP_COMPONENT_NAME = 'manifest'; import express from 'express'; import { SiteController } from '../../lib/site-controller.js'; export default class ManifestController extends SiteController { static get name ( ) { return 'ManifestController'; } static get slug ( ) { return 'manifest'; } static create (dtp) { const instance = new ManifestController(dtp); return instance; } constructor (dtp) { super(dtp, DTP_COMPONENT_NAME); } async start ( ) { const { dtp } = this; const { limiter: limiterService } = dtp.services; const router = express.Router(); dtp.app.use('/manifest.json', router); router.use(async (req, res, next) => { res.locals.currentView = DTP_COMPONENT_NAME; return next(); }); router.get('/', limiterService.create(limiterService.config.manifest.getManifest), this.getManifest.bind(this), ); } async getManifest (req, res, next) { try { const manifest = { id: '/', scope: '/', start_url: '/', name: this.dtp.config.site.name, short_name: this.dtp.config.site.name, description: this.dtp.config.site.description, display: 'fullscreen', theme_color: '#62767e', background_color: '#62767e', icons: [ ], }; [512, 384, 256, 192, 144, 96, 72, 48, 32, 16].forEach((size) => { manifest.icons.push({ src: `/img/icon/icon-${size}x${size}.png`, sizes: `${size}x${size}`, type: 'image/png' }); }); res.status(200).json(manifest); } catch (error) { return next(error); } } }