diff --git a/bun.lockb b/bun.lockb index b169c15..8929e42 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index b97df07..b99b926 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@elysiajs/static": "^1.4.0", "@types/html-minifier-next": "^2.1.0", "@types/pg": "^8.11.10", + "age-encryption": "^0.2.4", "date-fns": "^4.1.0", "elysia": "^1.1.25", "eta": "^4.0.1", diff --git a/src/router/html.ts b/src/router/html.ts index a0c778e..1da7400 100644 --- a/src/router/html.ts +++ b/src/router/html.ts @@ -1,5 +1,5 @@ import { Elysia } from 'elysia'; -import { m, eta } from '@/utils/html' +import { m, eta, error } from '@/utils/html' const app = new Elysia() app.get('/', async ({ set }) => { @@ -65,4 +65,5 @@ app.get('/donate', async ({ set }) => { })) }) +app.onError(error) export default app; \ No newline at end of file diff --git a/src/router/latest.ts b/src/router/latest.ts index 73e08de..cf9ea2b 100644 --- a/src/router/latest.ts +++ b/src/router/latest.ts @@ -1,7 +1,7 @@ import { Elysia } from 'elysia'; import { db } from '@/utils/database' import { createSitemapXML, createSitemapIndexXML } from '@/utils/sitemap' -import { m, eta } from '@/utils/html' +import { m, eta, error } from '@/utils/html' import redis from '@/utils/redis'; const app = new Elysia() @@ -67,4 +67,5 @@ app.get('/sitemap-:index.xml', async ({ set, params: { index }, error, path }) = return error(404) }) +app.onError(error) export default app \ No newline at end of file diff --git a/src/router/search.ts b/src/router/search.ts index d85f1ae..76ba2b6 100644 --- a/src/router/search.ts +++ b/src/router/search.ts @@ -3,7 +3,7 @@ import { RedisRateLimiter } from 'rolling-rate-limiter' import { db } from '@/utils/database' import { validateVideo, validateChannel } from '@/utils/regex' -import { m, eta } from '@/utils/html' +import { m, eta, error } from '@/utils/html' import redis from '@/utils/redis'; const app = new Elysia() @@ -59,4 +59,5 @@ app.get('/search/channel', async ({ query: { url }, error, redirect }) => { }) }) +app.onError(error) export default app \ No newline at end of file diff --git a/src/router/transparency.ts b/src/router/transparency.ts index 974b57c..1af45ec 100644 --- a/src/router/transparency.ts +++ b/src/router/transparency.ts @@ -1,7 +1,7 @@ import { Elysia } from 'elysia'; import { db } from '@/utils/database' -import { m, eta } from '@/utils/html' +import { m, eta, error } from '@/utils/html' import redis from '@/utils/redis'; const app = new Elysia() @@ -52,4 +52,5 @@ app.get('/transparency/:id', async ({ params: { id }, set, error }) => { return html }) +app.onError(error) export default app \ No newline at end of file diff --git a/src/router/video.ts b/src/router/video.ts index 13711af..76283a5 100644 --- a/src/router/video.ts +++ b/src/router/video.ts @@ -4,7 +4,7 @@ import DOMPurify from 'isomorphic-dompurify' import { db } from '@/utils/database' import { getChannel, getChannelVideos } from '@/utils/metadata'; import { convertRelativeToDate } from '@/utils/common'; -import { m, eta } from '@/utils/html' +import { m, eta, error } from '@/utils/html' import redis from '@/utils/redis'; const app = new Elysia() @@ -170,4 +170,5 @@ app.get('/channel/:id/videos', async ({ params: { id }, set }) => { return html }) +app.onError(error) export default app \ No newline at end of file diff --git a/src/router/websocket.ts b/src/router/websocket.ts index 407faab..125cffd 100644 --- a/src/router/websocket.ts +++ b/src/router/websocket.ts @@ -7,6 +7,7 @@ import { checkCaptcha, createDatabaseVideo } from '@/utils/common'; import { downloadVideo } from '@/utils/download'; import { uploadVideo } from '@/utils/upload'; import { getChannelVideos } from '@/utils/metadata'; +import { error } from '@/utils/html' import redis from '@/utils/redis'; const app = new Elysia() @@ -182,4 +183,5 @@ app.ws('/savechannel', { } }) +app.onError(error) export default app \ No newline at end of file diff --git a/src/utils/html.ts b/src/utils/html.ts index c00f301..1789d6f 100644 --- a/src/utils/html.ts +++ b/src/utils/html.ts @@ -1,4 +1,5 @@ import { minify } from 'html-minifier-next'; +import * as age from 'age-encryption' import { Eta } from 'eta'; import path from 'path'; @@ -10,4 +11,24 @@ export const m = async (html: string) => { }) } -export const eta = new Eta({ views: path.join(__dirname, '../templates'), functionHeader: `const hostname = "${process.env.SERVER_NICKNAME}"` }) \ No newline at end of file +export const eta = new Eta({ views: path.join(__dirname, '../templates'), functionHeader: `const hostname = "${process.env.SERVER_NICKNAME}"` }) + +export const error = async ({ error }: any) => { + const debuggingInfo = { + serverNickname: process.env.SERVER_NICKNAME, + currentTime: new Date().toISOString(), + errorStack: error.stack + } + + const e = new age.Encrypter() // my public key + e.addRecipient('age19f5carv77e9m7m3egef6dhmj3ltj5t84eca42ag84yn2ljwv94tqmh8le4') + const ciphertext = await e.encrypt(JSON.stringify(debuggingInfo)) + const armored = age.armor.encode(ciphertext) + + return `you found a bug! ${error.message} + +does this error keep persiting? please report it to admin@preservetube.com with the following debugging info: +(please copy paste this entire page into the email) + +${armored}` +} \ No newline at end of file