* Sends file content * @param {string} url * @param {string} id * @param {string} mime * @param {(txt: string) => string} processText * @returns
(url, id, mime, processText)
| 495 | * @returns |
| 496 | */ |
| 497 | async function sendFileContent(url, id, mime, processText) { |
| 498 | const fs = fsOperation(url); |
| 499 | |
| 500 | if (!(await fs.exists())) { |
| 501 | error(id); |
| 502 | return; |
| 503 | } |
| 504 | |
| 505 | let text = await fs.readFile(appSettings.value.defaultFileEncoding); |
| 506 | text = processText ? processText(text) : text; |
| 507 | if (mime === MIMETYPE_HTML) { |
| 508 | sendHTML(text, id); |
| 509 | } else { |
| 510 | sendText(text, id, mime); |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | /** |
| 515 | * Sends text |