mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-10 23:34:38 +08:00
feat: strict data type
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<string, string> = {
|
||||
'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;
|
||||
}
|
||||
|
||||
@@ -41,4 +41,5 @@ export type Data = {
|
||||
author?: string;
|
||||
language?: string;
|
||||
feedLink?: string;
|
||||
lastBuildDate?: string;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user