fix: typescript build errors

This commit is contained in:
DIYgod
2024-02-25 23:43:34 +08:00
parent 42a1c171a0
commit d1a4e19c62
12 changed files with 51 additions and 37 deletions
+2 -1
View File
@@ -117,7 +117,8 @@
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/no-explicit-any": 0,
"n/no-missing-import": 0,
"n/no-unpublished-import": 0
"n/no-unpublished-import": 0,
"no-prototype-builtins": 0
},
"overrides": [
{
+1
View File
@@ -19,6 +19,7 @@ coverage
docs/.vuepress/dist
node_modules
tmp
dist
Session.vim
combined.log
+2 -2
View File
@@ -1,7 +1,7 @@
import type { MiddlewareHandler } from 'hono';
import { config } from '@/config';
import md5 from '@/utils/md5';
import isLocalhost from 'is-localhost-ip';
import ipUtils from 'ip';
import { getIp } from '@/utils/helpers';
import RejectError from '@/errors/reject';
@@ -39,7 +39,7 @@ const middleware: MiddlewareHandler = async (ctx, next) => {
const isControlled = config.accessKey || config.allowlist || config.denylist;
const allowLocalhost = config.allowLocalhost && ip && (await isLocalhost(ip));
const allowLocalhost = config.allowLocalhost && ip && ipUtils.isPrivate(ip);
const grant = async () => {
if (ctx.res.status !== 403) {
+13 -3
View File
@@ -49,9 +49,18 @@ const summarizeArticle = async (articleText: string) => {
},
});
// @ts-expect-error custom field
return response.data.choices[0].message.content;
};
const getAuthorString = (item) => {
let author = '';
if (item.author) {
author = typeof item.author === 'string' ? item.author : item.author.map((i) => i.name).join(' ');
}
return author;
};
const middleware: MiddlewareHandler = async (ctx, next) => {
await next();
@@ -187,7 +196,7 @@ const middleware: MiddlewareHandler = async (ctx, next) => {
data.item = data.item.filter((item) => {
const title = item.title || '';
const description = item.description || title;
const author = item.author || '';
const author = getAuthorString(item);
const category = item.category || [];
const isFilter =
regex instanceof RE2JS
@@ -203,7 +212,7 @@ const middleware: MiddlewareHandler = async (ctx, next) => {
data.item = data.item.filter((item) => {
const title = item.title || '';
const description = item.description || title;
const author = item.author || '';
const author = getAuthorString(item);
const category = item.category || [];
let isFilter = true;
@@ -232,7 +241,7 @@ const middleware: MiddlewareHandler = async (ctx, next) => {
data.item = data.item.filter((item) => {
const title = item.title;
const description = item.description || title;
const author = item.author || '';
const author = getAuthorString(item);
const category = item.category || [];
let isFilter = true;
@@ -295,6 +304,7 @@ const middleware: MiddlewareHandler = async (ctx, next) => {
if (link) {
// if parser failed, return default description and not report error
try {
// @ts-expect-error custom field
const { data: res } = await got(link);
const $ = load(res);
const result = await Parser.parse(link, {
+8 -8
View File
@@ -30,14 +30,14 @@ const middleware: MiddlewareHandler = async (ctx, next) => {
const template = path.resolve(__dirname, `../views/${templateName}`);
if (data) {
data.title = utils.collapseWhitespace(data.title);
data.description && (data.description = utils.collapseWhitespace(data.description));
data.author && (data.author = utils.collapseWhitespace(data.author));
data.title = utils.collapseWhitespace(data.title) || '';
data.description && (data.description = utils.collapseWhitespace(data.description) || '');
data.author && (data.author = utils.collapseWhitespace(data.author) || '');
if (data.item) {
for (const item of data.item) {
if (item.title) {
item.title = utils.collapseWhitespace(item.title);
item.title = utils.collapseWhitespace(item.title) || '';
// trim title length
for (let length = 0, i = 0; i < item.title.length; i++) {
length += Buffer.from(item.title[i]).length === 1 ? 1 : 2;
@@ -49,10 +49,10 @@ const middleware: MiddlewareHandler = async (ctx, next) => {
}
if (typeof item.author === 'string') {
item.author = utils.collapseWhitespace(item.author);
item.author = utils.collapseWhitespace(item.author) || '';
} else if (typeof item.author === 'object' && item.author !== null) {
for (const a of item.author) {
a.name = utils.collapseWhitespace(a.name);
a.name = utils.collapseWhitespace(a.name) || '';
}
if (outputType !== 'json') {
item.author = item.author.map((a: { name: string }) => a.name).join(', ');
@@ -66,8 +66,8 @@ const middleware: MiddlewareHandler = async (ctx, next) => {
}
if (outputType !== 'rss') {
item.pubDate && (item.pubDate = utils.convertDateToISO8601(item.pubDate));
item.updated && (item.updated = utils.convertDateToISO8601(item.updated));
item.pubDate && (item.pubDate = utils.convertDateToISO8601(item.pubDate) || '');
item.updated && (item.updated = utils.convertDateToISO8601(item.updated) || '');
}
}
}
+3 -3
View File
@@ -4,7 +4,7 @@ import type CacheModule from './base';
const status = { available: false };
let memoryCache: LRUCache<any, any>;
let memoryCache: LRUCache<any, any> | undefined;
export default {
init: () => {
@@ -15,7 +15,7 @@ export default {
status.available = true;
},
get: (key: string, refresh = true) => {
if (key && status.available) {
if (key && status.available && memoryCache) {
let value = memoryCache.get(key, { updateAgeOnGet: refresh }) as string | undefined;
if (value) {
value = value + '';
@@ -30,7 +30,7 @@ export default {
if (typeof value === 'object') {
value = JSON.stringify(value);
}
if (key && status.available) {
if (key && status.available && memoryCache) {
return memoryCache.set(key, value, { ttl: maxAge * 1000 });
}
},
+3 -3
View File
@@ -3,7 +3,7 @@ import Redis from 'ioredis';
import logger from '@/utils/logger';
import type CacheModule from './base';
let redisClient: Redis;
let redisClient: Redis | undefined;
const status = { available: false };
@@ -33,7 +33,7 @@ export default {
});
},
get: async (key: string, refresh = true) => {
if (key && status.available) {
if (key && status.available && redisClient) {
const cacheTtlKey = getCacheTtlKey(key);
let [value, cacheTtl] = await redisClient.mget(key, cacheTtlKey);
if (value && refresh) {
@@ -52,7 +52,7 @@ export default {
}
},
set: (key: string, value?: string | Record<string, any>, maxAge = config.cache.contentExpire) => {
if (!status.available) {
if (!status.available || !redisClient) {
return;
}
if (!value || value === 'undefined') {
+2 -1
View File
@@ -43,9 +43,10 @@ async function buildData(data) {
let charset = 'utf-8';
for (const attr of contentType.split(';')) {
if (attr.includes('charset=')) {
charset = attr.split('=').pop();
charset = attr.split('=').pop() || 'utf-8';
}
}
// @ts-expect-error custom property
const responseData = charset === 'utf-8' ? response.data : iconv.decode((await got.get({ url: data.url, responseType: 'buffer' })).data, charset);
const $ = cheerio.load(responseData);
const $item = $(data.item.item);
+1 -1
View File
@@ -10,7 +10,7 @@ import StealthPlugin from 'puppeteer-extra-plugin-stealth';
const options = {
args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-infobars', '--window-position=0,0', '--ignore-certificate-errors', '--ignore-certificate-errors-spki-list', `--user-agent=${config.ua}`],
headless: 'new' as const,
headless: true,
ignoreHTTPSErrors: true,
};
+3 -2
View File
@@ -20,9 +20,10 @@
"lib"
],
"scripts": {
"build:all": "npm run build:radar && npm run build:maintainer",
"build:all": "npm run build && npm run build:radar && npm run build:maintainer",
"build:maintainer": "node scripts/workflow/build-maintainer.js",
"build:radar": "node scripts/workflow/build-radar.js",
"build": "tsc",
"dev": "cross-env NODE_ENV=dev tsx watch lib/index.ts",
"format": "eslint --cache --fix \"**/*.{ts,js,yml}\" && node website/docs/.format/format.mjs && prettier \"**/*.{ts,js,json}\" --write",
"format:check": "eslint --cache \"**/*.{ts,js,yml}\" && prettier \"**/*.{ts,js,json}\" --check",
@@ -106,8 +107,8 @@
"imapflow": "1.0.152",
"instagram-private-api": "1.45.3",
"ioredis": "5.3.2",
"ip": "2.0.1",
"ip-regex": "4.3.0",
"is-localhost-ip": "2.0.0",
"jsdom": "24.0.0",
"json-bigint": "1.0.0",
"json5": "2.2.3",
+6 -11
View File
@@ -98,12 +98,12 @@ dependencies:
ioredis:
specifier: 5.3.2
version: 5.3.2
ip:
specifier: 2.0.1
version: 2.0.1
ip-regex:
specifier: 4.3.0
version: 4.3.0
is-localhost-ip:
specifier: 2.0.0
version: 2.0.0
jsdom:
specifier: 24.0.0
version: 24.0.0
@@ -6302,8 +6302,8 @@ packages:
resolution: {integrity: sha512-PuExPYUiu6qMBQb4l06ecm6T6ujzhmh+MeJcW9wa89PoAz5pvd4zPgN5WJV104mb6S2T1AwNIAaB70JNrLQWhg==}
dev: false
/ip@2.0.0:
resolution: {integrity: sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==}
/ip@2.0.1:
resolution: {integrity: sha512-lJUL9imLTNi1ZfXT+DU6rBBdbiKGBuay9B6xGSPVjUeQwaH1RIGqef8RZkUtHioLmSNpPR5M4HVKJGm1j8FWVQ==}
dev: false
/is-alphabetical@1.0.4:
@@ -6447,11 +6447,6 @@ packages:
engines: {node: '>=0.10.0'}
dev: false
/is-localhost-ip@2.0.0:
resolution: {integrity: sha512-vlgs2cSgMOfnKU8c1ewgKPyum9rVrjjLLW2HBdL5i0iAJjOs8NY55ZBd/hqUTaYR0EO9CKZd3hVSC2HlIbygTQ==}
engines: {node: '>=12'}
dev: false
/is-number@7.0.0:
resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==}
engines: {node: '>=0.12.0'}
@@ -10156,7 +10151,7 @@ packages:
resolution: {integrity: sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ==}
engines: {node: '>= 10.13.0', npm: '>= 3.0.0'}
dependencies:
ip: 2.0.0
ip: 2.0.1
smart-buffer: 4.2.0
dev: false
+7 -2
View File
@@ -1,6 +1,8 @@
{
"compilerOptions": {
"lib": ["ES2022"],
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"strict": true,
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx",
@@ -9,5 +11,8 @@
},
"esModuleInterop": true,
"noImplicitAny": false,
}
"outDir": "./dist"
},
"include": ["./lib/**/*"],
"exclude": ["node_modules", "*.test.*"]
}