|
20 | 20 | 后续服务端传输HTML到前端,直接显示到dialog |
21 | 21 | */ |
22 | 22 |
|
23 | | -import { checkIsTraditional, downloadNovel, exists, Status, getAppDataDir, defaultGetInfo, traditionalAsyncWrapper, moduleExists } from "./main.ts"; |
| 23 | +import { checkIsTraditional, downloadNovel, exists, Status, getAppDataDir, defaultGetInfo, traditionalAsyncWrapper, moduleExists, sleep } from "./main.ts"; |
24 | 24 | import mainPage from "./static/server.html" with { type: "text" }; |
25 | 25 | import { render } from "npm:ejs"; |
26 | 26 | import { processTXTContent } from "./2epub.ts"; |
@@ -230,7 +230,7 @@ async function handleContentRequest(_: Request, url: URL) { |
230 | 230 | // 使用SQLite缓存 |
231 | 231 | const cachedInfo = await cache.get(novelURL.href); |
232 | 232 | if (cachedInfo) { |
233 | | - Deno.stdout.writeSync(new TextEncoder().encode('HIT ')); |
| 233 | + await Deno.stdout.write(new TextEncoder().encode('HIT ')); |
234 | 234 | info = cachedInfo; |
235 | 235 | } else { |
236 | 236 | let basicInfo: TraditionalConfig; |
@@ -336,6 +336,8 @@ async function handleContentRequest(_: Request, url: URL) { |
336 | 336 | }); |
337 | 337 | } else if (info.content) { |
338 | 338 | info.content = processTXTContent(info.content, info.jpStyle); |
| 339 | + } else if (info.summary) { |
| 340 | + info.summary = processTXTContent(info.summary, info.jpStyle); |
339 | 341 | } |
340 | 342 |
|
341 | 343 | // render page |
@@ -524,9 +526,16 @@ export default async function main() { |
524 | 526 | return res; |
525 | 527 | }); |
526 | 528 |
|
| 529 | + let $shutting = false; |
527 | 530 | Deno.addSignalListener("SIGINT", async () => { |
| 531 | + if($shutting) return console.log("Server is already shutting down..."); |
| 532 | + $shutting = true; |
528 | 533 | kv.close(); |
529 | | - await $s.shutdown(); |
| 534 | + console.log("Server shutting down...(timeout 3s)"); |
| 535 | + await Promise.race([ |
| 536 | + $s.shutdown(), |
| 537 | + sleep(3) |
| 538 | + ]); |
530 | 539 | console.log("Server stopped"); |
531 | 540 | Deno.exit(0); |
532 | 541 | }); |
|
0 commit comments