mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-27 18:22:41 -08:00
pretty
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import * as fs from "fs";
|
||||
import * as http from "http";
|
||||
import * as path from "path";
|
||||
import { createLogger } from "../../logger";
|
||||
import * as fs from 'fs';
|
||||
import * as http from 'http';
|
||||
import * as path from 'path';
|
||||
import { createLogger } from '../../logger';
|
||||
|
||||
const logger = createLogger("main:texthooker");
|
||||
const logger = createLogger('main:texthooker');
|
||||
|
||||
export class Texthooker {
|
||||
private server: http.Server | null = null;
|
||||
@@ -15,42 +15,39 @@ export class Texthooker {
|
||||
public start(port: number): http.Server | null {
|
||||
const texthookerPath = this.getTexthookerPath();
|
||||
if (!texthookerPath) {
|
||||
logger.error("texthooker-ui not found");
|
||||
logger.error('texthooker-ui not found');
|
||||
return null;
|
||||
}
|
||||
|
||||
this.server = http.createServer((req, res) => {
|
||||
const urlPath = (req.url || "/").split("?")[0];
|
||||
const filePath = path.join(
|
||||
texthookerPath,
|
||||
urlPath === "/" ? "index.html" : urlPath,
|
||||
);
|
||||
const urlPath = (req.url || '/').split('?')[0];
|
||||
const filePath = path.join(texthookerPath, urlPath === '/' ? 'index.html' : urlPath);
|
||||
|
||||
const ext = path.extname(filePath);
|
||||
const mimeTypes: Record<string, string> = {
|
||||
".html": "text/html",
|
||||
".js": "application/javascript",
|
||||
".css": "text/css",
|
||||
".json": "application/json",
|
||||
".png": "image/png",
|
||||
".svg": "image/svg+xml",
|
||||
".ttf": "font/ttf",
|
||||
".woff": "font/woff",
|
||||
".woff2": "font/woff2",
|
||||
'.html': 'text/html',
|
||||
'.js': 'application/javascript',
|
||||
'.css': 'text/css',
|
||||
'.json': 'application/json',
|
||||
'.png': 'image/png',
|
||||
'.svg': 'image/svg+xml',
|
||||
'.ttf': 'font/ttf',
|
||||
'.woff': 'font/woff',
|
||||
'.woff2': 'font/woff2',
|
||||
};
|
||||
|
||||
fs.readFile(filePath, (err, data) => {
|
||||
if (err) {
|
||||
res.writeHead(404);
|
||||
res.end("Not found");
|
||||
res.end('Not found');
|
||||
return;
|
||||
}
|
||||
res.writeHead(200, { "Content-Type": mimeTypes[ext] || "text/plain" });
|
||||
res.writeHead(200, { 'Content-Type': mimeTypes[ext] || 'text/plain' });
|
||||
res.end(data);
|
||||
});
|
||||
});
|
||||
|
||||
this.server.listen(port, "127.0.0.1", () => {
|
||||
this.server.listen(port, '127.0.0.1', () => {
|
||||
logger.info(`Texthooker server running at http://127.0.0.1:${port}`);
|
||||
});
|
||||
|
||||
@@ -66,17 +63,11 @@ export class Texthooker {
|
||||
|
||||
private getTexthookerPath(): string | null {
|
||||
const searchPaths = [
|
||||
path.join(__dirname, "..", "..", "..", "vendor", "texthooker-ui", "docs"),
|
||||
path.join(
|
||||
process.resourcesPath,
|
||||
"app",
|
||||
"vendor",
|
||||
"texthooker-ui",
|
||||
"docs",
|
||||
),
|
||||
path.join(__dirname, '..', '..', '..', 'vendor', 'texthooker-ui', 'docs'),
|
||||
path.join(process.resourcesPath, 'app', 'vendor', 'texthooker-ui', 'docs'),
|
||||
];
|
||||
for (const candidate of searchPaths) {
|
||||
if (fs.existsSync(path.join(candidate, "index.html"))) {
|
||||
if (fs.existsSync(path.join(candidate, 'index.html'))) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user