Skip to content

Commit f56fb64

Browse files
committed
fix: Extra error handler for 500 responses, possible fix
refactor: Use static folder for extension provided themes
1 parent e6717ab commit f56fb64

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

src/back/extensions/ExtensionsScanner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ async function parseExtensionManifest(data: any) {
171171
parser.prop('main', v => parsed.main = str(v), true);
172172
// Don't change this to v. Probably happens because it's a map.
173173
parser.prop('contributes', v => parsed.contributes = parseContributions(parser.prop('contributes')), true);
174+
parser.prop('category', v => parsed.category = str(v), true);
174175
return parsed;
175176
}
176177

src/back/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,9 +699,14 @@ async function prepForInit(initConfig: BackInitArgs): Promise<void> {
699699
for (const theme of c.value) {
700700
const ext = await state.extensionsService.getExtension(c.extId);
701701
if (ext) {
702-
const realPath = path.join(ext.extensionPath, theme.path);
702+
const basePath = path.resolve(ext.extensionPath, 'static');
703+
const realPath = path.resolve(basePath, theme.path);
704+
if (!realPath.startsWith(basePath)) {
705+
log.error('Extensions', `[${ext.manifest.displayName || ext.manifest.name}] Error loading theme, it must be inside the 'static' directory "${theme.id}"\n`);
706+
continue;
707+
}
703708
try {
704-
await newThemeWatcher(theme.id, ext.extensionPath, realPath, state.themeState, state.registry, state.socketServer, ext.manifest.displayName || ext.manifest.name, theme.logoSet);
709+
await newThemeWatcher(theme.id, basePath, realPath, state.themeState, state.registry, state.socketServer, ext.manifest.displayName || ext.manifest.name, theme.logoSet);
705710
} catch (error) {
706711
log.error('Extensions', `[${ext.manifest.displayName || ext.manifest.name}] Error loading theme "${theme.id}"\n${error}`);
707712
}

src/back/util/FileServer.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as http from 'http';
2-
import * as fs from 'node:fs';
32
import * as mime from 'mime';
4-
import * as path from 'node:path';
53
import { Socket } from 'net';
4+
import * as fs from 'node:fs';
5+
import * as path from 'node:path';
66

77
type HandlerFunc = (relativePathname: string, url: URL, req: http.IncomingMessage, res: http.ServerResponse) => any;
88

@@ -75,8 +75,12 @@ export function serveFile(req: http.IncomingMessage, res: http.ServerResponse, f
7575
req.on('error', (err: any) => {
7676
log.error('Launcher', `Error serving file - ${err}`);
7777
if (err.code !== 'ECONNRESET') {
78-
res.writeHead(500);
79-
res.end();
78+
try {
79+
res.writeHead(500);
80+
res.end();
81+
} catch (err) {
82+
log.error('Launcher', 'Cannot write header after the above file server error');
83+
}
8084
}
8185
});
8286
fs.stat(filePath, (error, stats) => {

typings/flashpoint-launcher.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,6 +2801,7 @@ declare module 'flashpoint-launcher' {
28012801
description?: string;
28022802
icon?: string;
28032803
main?: string;
2804+
category?: string;
28042805
contributes?: Contributions;
28052806
}
28062807

0 commit comments

Comments
 (0)