mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-11 15:47:48 +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 * as path from 'node:path';
|
||||||
import render from '@/utils/render';
|
import render from '@/utils/render';
|
||||||
import { type MiddlewareHandler } from 'hono';
|
import { type MiddlewareHandler } from 'hono';
|
||||||
|
import { Data } from '@/types';
|
||||||
|
|
||||||
const templateRegex = /\${([^{}]+)}/g;
|
const templateRegex = /\${([^{}]+)}/g;
|
||||||
const allowedUrlProperties = new Set(['hash', 'host', 'hostname', 'href', 'origin', 'password', 'pathname', 'port', 'protocol', 'search', 'searchParams', 'username']);
|
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.
|
// and here we will only check them in description.
|
||||||
// Use Cheerio to load the description as html and filter all
|
// Use Cheerio to load the description as html and filter all
|
||||||
// image link
|
// image link
|
||||||
const data = ctx.get('data');
|
const data: Data = ctx.get('data');
|
||||||
if (data) {
|
if (data) {
|
||||||
if (data.description) {
|
if (data.description) {
|
||||||
data.description = process(data.description, image_hotlink_template, multimedia_hotlink_template, shouldWrapInIframe);
|
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;
|
export default middleware;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import type { MiddlewareHandler } from 'hono';
|
|||||||
import { config } from '@/config';
|
import { config } from '@/config';
|
||||||
import { RequestInProgressError } from '@/errors';
|
import { RequestInProgressError } from '@/errors';
|
||||||
import cacheModule from '@/utils/cache/index'
|
import cacheModule from '@/utils/cache/index'
|
||||||
|
import { Data } from '@/types';
|
||||||
|
|
||||||
// only give cache string, as the `!` condition tricky
|
// only give cache string, as the `!` condition tricky
|
||||||
// md5 is used to shrink key size
|
// md5 is used to shrink key size
|
||||||
@@ -48,7 +49,7 @@ const middleware: MiddlewareHandler = async (ctx, next) => {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = ctx.get('data')
|
const data: Data = ctx.get('data');
|
||||||
if (ctx.res.headers.get('Cache-Control') !== 'no-cache' && data) {
|
if (ctx.res.headers.get('Cache-Control') !== 'no-cache' && data) {
|
||||||
data.lastBuildDate = new Date().toUTCString();
|
data.lastBuildDate = new Date().toUTCString();
|
||||||
ctx.set('data', data)
|
ctx.set('data', data)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { MiddlewareHandler } from "hono";
|
|||||||
import etagCalculate from "etag";
|
import etagCalculate from "etag";
|
||||||
import logger from "@/utils/logger";
|
import logger from "@/utils/logger";
|
||||||
import { config } from "@/config";
|
import { config } from "@/config";
|
||||||
|
import { Data } from "@/types";
|
||||||
|
|
||||||
const headers: Record<string, string> = {
|
const headers: Record<string, string> = {
|
||||||
'Access-Control-Allow-Methods': 'GET',
|
'Access-Control-Allow-Methods': 'GET',
|
||||||
@@ -29,7 +30,7 @@ const middleware: MiddlewareHandler = async (ctx, next) => {
|
|||||||
|
|
||||||
await next();
|
await next();
|
||||||
|
|
||||||
const data = ctx.get('data');
|
const data: Data = ctx.get('data');
|
||||||
if (!data || ctx.res.headers.get('ETag')) {
|
if (!data || ctx.res.headers.get('ETag')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,4 +41,5 @@ export type Data = {
|
|||||||
author?: string;
|
author?: string;
|
||||||
language?: string;
|
language?: string;
|
||||||
feedLink?: string;
|
feedLink?: string;
|
||||||
|
lastBuildDate?: string;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user