diff --git a/lib/middleware/anti-hotlink.ts b/lib/middleware/anti-hotlink.ts index 5e5c8ce32f..65cde73156 100644 --- a/lib/middleware/anti-hotlink.ts +++ b/lib/middleware/anti-hotlink.ts @@ -4,6 +4,7 @@ import logger from '@/utils/logger'; import * as path from 'node:path'; import render from '@/utils/render'; import { type MiddlewareHandler } from 'hono'; +import { Data } from '@/types'; const templateRegex = /\${([^{}]+)}/g; const allowedUrlProperties = new Set(['hash', 'host', 'hostname', 'href', 'origin', 'password', 'pathname', 'port', 'protocol', 'search', 'searchParams', 'username']); @@ -130,7 +131,7 @@ const middleware: MiddlewareHandler = async (ctx, next) => { // and here we will only check them in description. // Use Cheerio to load the description as html and filter all // image link - const data = ctx.get('data'); + const data: Data = ctx.get('data'); if (data) { if (data.description) { data.description = process(data.description, image_hotlink_template, multimedia_hotlink_template, shouldWrapInIframe); @@ -148,4 +149,4 @@ const middleware: MiddlewareHandler = async (ctx, next) => { } }; -export default middleware; \ No newline at end of file +export default middleware; diff --git a/lib/middleware/cache.ts b/lib/middleware/cache.ts index 47c1eaab3f..8ae5484859 100644 --- a/lib/middleware/cache.ts +++ b/lib/middleware/cache.ts @@ -4,6 +4,7 @@ import type { MiddlewareHandler } from 'hono'; import { config } from '@/config'; import { RequestInProgressError } from '@/errors'; import cacheModule from '@/utils/cache/index' +import { Data } from '@/types'; // only give cache string, as the `!` condition tricky // md5 is used to shrink key size @@ -48,7 +49,7 @@ const middleware: MiddlewareHandler = async (ctx, next) => { throw error; } - const data = ctx.get('data') + const data: Data = ctx.get('data'); if (ctx.res.headers.get('Cache-Control') !== 'no-cache' && data) { data.lastBuildDate = new Date().toUTCString(); ctx.set('data', data) diff --git a/lib/middleware/header.ts b/lib/middleware/header.ts index c867e30f20..e32655d437 100644 --- a/lib/middleware/header.ts +++ b/lib/middleware/header.ts @@ -3,6 +3,7 @@ import { MiddlewareHandler } from "hono"; import etagCalculate from "etag"; import logger from "@/utils/logger"; import { config } from "@/config"; +import { Data } from "@/types"; const headers: Record = { 'Access-Control-Allow-Methods': 'GET', @@ -29,7 +30,7 @@ const middleware: MiddlewareHandler = async (ctx, next) => { await next(); - const data = ctx.get('data'); + const data: Data = ctx.get('data'); if (!data || ctx.res.headers.get('ETag')) { return; } diff --git a/lib/types.ts b/lib/types.ts index c983614112..bc708f7279 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -41,4 +41,5 @@ export type Data = { author?: string; language?: string; feedLink?: string; + lastBuildDate?: string; };