Browse Source

Refactoring

release/2.147.0-beta.1
Thomas Kaul 5 days ago
parent
commit
44e76bd802
  1. 6
      apps/api/src/app/app.module.ts
  2. 8
      apps/api/src/app/sitemap/sitemap.controller.ts
  3. 45
      apps/api/src/app/webmanifest/webmanifest.controller.ts
  4. 6
      apps/api/src/app/webmanifest/webmanifest.module.ts
  5. 61
      apps/api/src/assets/site.webmanifest
  6. 8
      apps/client/ngsw-config.json
  7. 3
      apps/client/project.json
  8. 31
      apps/client/src/assets/site.webmanifest
  9. 5
      apps/client/src/index.html

6
apps/api/src/app/app.module.ts

@ -51,6 +51,7 @@ import { SitemapModule } from './sitemap/sitemap.module';
import { SubscriptionModule } from './subscription/subscription.module'; import { SubscriptionModule } from './subscription/subscription.module';
import { SymbolModule } from './symbol/symbol.module'; import { SymbolModule } from './symbol/symbol.module';
import { UserModule } from './user/user.module'; import { UserModule } from './user/user.module';
import { WebManifestModule } from './webmanifest/webmanifest.module';
@Module({ @Module({
controllers: [AppController], controllers: [AppController],
@ -126,8 +127,9 @@ import { UserModule } from './user/user.module';
SymbolModule, SymbolModule,
TagsModule, TagsModule,
TwitterBotModule, TwitterBotModule,
UserModule UserModule,
WebManifestModule
], ],
providers: [CronService] providers: [CronService]
}) })
export class AppModule {} export class AppModule {}

8
apps/api/src/app/sitemap/sitemap.controller.ts

@ -9,8 +9,8 @@ import { personalFinanceTools } from '@ghostfolio/common/personal-finance-tools'
import { Controller, Get, Res, VERSION_NEUTRAL, Version } from '@nestjs/common'; import { Controller, Get, Res, VERSION_NEUTRAL, Version } from '@nestjs/common';
import { format } from 'date-fns'; import { format } from 'date-fns';
import { Response } from 'express'; import { Response } from 'express';
import * as fs from 'fs'; import { readFileSync } from 'fs';
import * as path from 'path'; import { join } from 'path';
@Controller('sitemap.xml') @Controller('sitemap.xml')
export class SitemapController { export class SitemapController {
@ -20,8 +20,8 @@ export class SitemapController {
private readonly configurationService: ConfigurationService private readonly configurationService: ConfigurationService
) { ) {
try { try {
this.sitemapXml = fs.readFileSync( this.sitemapXml = readFileSync(
path.join(__dirname, 'assets', 'sitemap.xml'), join(__dirname, 'assets', 'sitemap.xml'),
'utf8' 'utf8'
); );
} catch {} } catch {}

45
apps/api/src/app/webmanifest/webmanifest.controller.ts

@ -1,31 +1,44 @@
import { Controller, Get, Param, Res, Version, VERSION_NEUTRAL } from '@nestjs/common';
import { Response } from 'express';
import { interpolate } from '@ghostfolio/common/helper';
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service';
import * as fs from 'fs'; import { interpolate } from '@ghostfolio/common/helper';
import * as path from 'path';
import {
Controller,
Get,
Param,
Res,
Version,
VERSION_NEUTRAL
} from '@nestjs/common';
import { Response } from 'express';
import { readFileSync } from 'fs';
import { join } from 'path';
@Controller('assets') @Controller('assets')
export class WebManifestController { export class WebManifestController {
public webManifestTemplate: string; private webManifest = '';
public constructor(public readonly configService: ConfigurationService) { public constructor(
public readonly configurationService: ConfigurationService
) {
try { try {
this.webManifestTemplate = fs.readFileSync( this.webManifest = readFileSync(
path.resolve(__dirname, '../../assets/site.webmanifest'), join(__dirname, 'assets', 'site.webmanifest'),
'utf8' 'utf8'
); );
} catch (error) { } catch {}
console.error('Error reading site.webmanifest:', error);
this.webManifestTemplate = '';
}
} }
@Get('/:languageCode/site.webmanifest') @Get('/:languageCode/site.webmanifest')
@Version(VERSION_NEUTRAL) @Version(VERSION_NEUTRAL)
public getWebManifest(@Param('languageCode') languageCode: string, @Res() res: Response): void { public getWebManifest(
const rootUrl = this.configService.get('ROOT_URL') || 'https://default.url.com'; @Param('languageCode') languageCode: string,
const webManifest = interpolate(this.webManifestTemplate, { languageCode, rootUrl }); @Res() res: Response
): void {
const rootUrl = this.configurationService.get('ROOT_URL');
const webManifest = interpolate(this.webManifest, {
languageCode,
rootUrl
});
res.setHeader('Content-Type', 'application/json'); res.setHeader('Content-Type', 'application/json');
res.send(webManifest); res.send(webManifest);

6
apps/api/src/app/webmanifest/webmanifest.module.ts

@ -1,9 +1,11 @@
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service';
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { WebManifestController } from './webmanifest.controller'; import { WebManifestController } from './webmanifest.controller';
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service';
@Module({ @Module({
controllers: [WebManifestController], controllers: [WebManifestController],
providers: [ConfigurationService], providers: [ConfigurationService]
}) })
export class WebManifestModule {} export class WebManifestModule {}

61
apps/api/src/assets/site.webmanifest

@ -1,32 +1,31 @@
{ {
"background_color": "#FFFFFF", "background_color": "#FFFFFF",
"categories": ["finance", "utilities"], "categories": ["finance", "utilities"],
"description": "Open Source Wealth Management Software", "description": "Open Source Wealth Management Software",
"display": "standalone", "display": "standalone",
"icons": [ "icons": [
{ {
"sizes": "192x192", "sizes": "192x192",
"src": "/assets/android-chrome-192x192.png", "src": "/assets/android-chrome-192x192.png",
"type": "image/png" "type": "image/png"
}, },
{ {
"purpose": "any", "purpose": "any",
"sizes": "512x512", "sizes": "512x512",
"src": "/assets/android-chrome-512x512.png", "src": "/assets/android-chrome-512x512.png",
"type": "image/png" "type": "image/png"
}, },
{ {
"purpose": "maskable", "purpose": "maskable",
"sizes": "512x512", "sizes": "512x512",
"src": "/assets/android-chrome-512x512.png", "src": "/assets/android-chrome-512x512.png",
"type": "image/png" "type": "image/png"
} }
], ],
"name": "Ghostfolio", "name": "Ghostfolio",
"orientation": "portrait", "orientation": "portrait",
"short_name": "Ghostfolio", "short_name": "Ghostfolio",
"start_url": "/${languageCode}/", "start_url": "/${languageCode}/",
"theme_color": "#FFFFFF", "theme_color": "#FFFFFF",
"url": "${rootUrl}" "url": "${rootUrl}"
} }

8
apps/client/ngsw-config.json

@ -6,13 +6,7 @@
"name": "app", "name": "app",
"installMode": "prefetch", "installMode": "prefetch",
"resources": { "resources": {
"files": [ "files": ["/favicon.ico", "/index.html", "/*.css", "/*.js"]
"/favicon.ico",
"/index.html",
"/assets/site.webmanifest",
"/*.css",
"/*.js"
]
} }
}, },
{ {

3
apps/client/project.json

@ -146,9 +146,6 @@
{ {
"command": "shx cp apps/client/src/assets/robots.txt dist/apps/client" "command": "shx cp apps/client/src/assets/robots.txt dist/apps/client"
}, },
{
"command": "shx cp apps/client/src/assets/site.webmanifest dist/apps/client"
},
{ {
"command": "shx cp node_modules/ionicons/dist/index.js dist/apps/client" "command": "shx cp node_modules/ionicons/dist/index.js dist/apps/client"
}, },

31
apps/client/src/assets/site.webmanifest

@ -1,31 +0,0 @@
{
"background_color": "#FFFFFF",
"categories": ["finance", "utilities"],
"description": "Open Source Wealth Management Software",
"display": "standalone",
"icons": [
{
"sizes": "192x192",
"src": "/assets/android-chrome-192x192.png",
"type": "image/png"
},
{
"purpose": "any",
"sizes": "512x512",
"src": "/assets/android-chrome-512x512.png",
"type": "image/png"
},
{
"purpose": "maskable",
"sizes": "512x512",
"src": "/assets/android-chrome-512x512.png",
"type": "image/png"
}
],
"name": "Ghostfolio",
"orientation": "portrait",
"short_name": "Ghostfolio",
"start_url": "/en/",
"theme_color": "#FFFFFF",
"url": "https://ghostfol.io"
}

5
apps/client/src/index.html

@ -45,7 +45,10 @@
sizes="16x16" sizes="16x16"
type="image/png" type="image/png"
/> />
<link href="../assets/site.webmanifest" rel="manifest" /> <link
href="${rootUrl}/api/assets/${languageCode}/site.webmanifest"
rel="manifest"
/>
</head> </head>
<body> <body>
<gf-root></gf-root> <gf-root></gf-root>

Loading…
Cancel
Save