Skip to content

Commit

Permalink
Merge branch 'master' into feat/thai-parliament-section77
Browse files Browse the repository at this point in the history
  • Loading branch information
itpcc authored Jan 18, 2024
2 parents 67d3877 + cdb6f6f commit 535c8f6
Show file tree
Hide file tree
Showing 1,665 changed files with 6,423 additions and 6,512 deletions.
20 changes: 10 additions & 10 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"rangav.vscode-thunder-client",
"SonarSource.sonarlint-vscode",
"unifiedjs.vscode-mdx",
"ZihanLi.at-helper"
]
}
"ZihanLi.at-helper",
],
},
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
Expand All @@ -30,12 +30,12 @@
"portsAttributes": {
"1200": {
"label": "app port",
"onAutoForward": "notify"
"onAutoForward": "notify",
},
"3000": {
"label": "docs port",
"onAutoForward": "notify"
}
"onAutoForward": "notify",
},
},

"onCreateCommand": "sudo apt-get update && export DEBIAN_FRONTEND=noninteractive && sudo apt-get -y install --no-install-recommends ca-certificates fonts-liberation libasound2 libatk-bridge2.0-0 libatk1.0-0 libatspi2.0-0 libcairo2 libcups2 libdbus-1-3 libexpat1 libgbm1 libglib2.0-0 libnspr4 libnss3 libpango-1.0-0 libx11-6 libxcb1 libxcomposite1 libxdamage1 libxext6 libxfixes3 libxkbcommon0 libxrandr2 wget xdg-utils redis-server && sudo apt-get autoremove -y && sudo apt-get clean -y && sudo rm -rf /var/lib/apt/lists/*",
Expand All @@ -55,10 +55,10 @@
"remoteUser": "node",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker": {
"version": "latest"
"version": "latest",
},
"ghcr.io/devcontainers/features/github-cli": {
"version": "latest"
}
}
"version": "latest",
},
},
}
92 changes: 50 additions & 42 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
{
"extends": ["eslint:recommended", "plugin:n/recommended", "plugin:prettier/recommended", "plugin:yml/recommended"],
"plugins": ["prettier", "@stylistic/js"],
"extends": ["eslint:recommended", "plugin:n/recommended", "plugin:unicorn/recommended", "plugin:prettier/recommended", "plugin:yml/recommended"],
"plugins": ["prettier", "@stylistic/js", "unicorn"],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"env": {
"node": true,
"es6": true,
"es2024": true,
"browser": true
},
"rules": {
// possible problems
"array-callback-return": 2,
"array-callback-return": ["error", { "allowImplicit": true }],
"no-await-in-loop": 2,
"no-control-regex": 0,
"no-duplicate-imports": 2,
"no-prototype-builtins": 0,
"no-unsafe-negation": 2,
"require-atomic-updates": 0,
// suggestions
"arrow-body-style": 2,
"block-scoped-var": 2,
Expand All @@ -29,16 +26,7 @@
"no-eval": 2,
"no-extend-native": 2,
"no-extra-label": 2,
"no-global-assign": 2,
"no-implicit-coercion": [
"error",
{
"boolean": false,
"number": false,
"string": false,
"disallowTemplateShorthand": true
}
],
"no-implicit-coercion": ["error", { "boolean": false, "number": false, "string": false, "disallowTemplateShorthand": true }],
"no-implicit-globals": 2,
"no-labels": 2,
"no-multi-str": 2,
Expand All @@ -52,9 +40,49 @@
"object-shorthand": 2,
"prefer-arrow-callback": 2,
"prefer-const": 2,
"prefer-regex-literals": 1,
"prefer-object-has-own": 2,
"prefer-regex-literals": ["error", { "disallowRedundantWrapping": true }],
"require-await": 2,
// plugin specific
"unicorn/consistent-destructuring": 1,
"unicorn/consistent-function-scoping": 1,
"unicorn/explicit-length-check": 0,
"unicorn/filename-case": ["error", { "case": "kebabCase", "ignore": [".*\\.(yaml|yml)$", "RequestInProgress\\.js$"] }],
"unicorn/new-for-builtins": 0,
"unicorn/no-array-callback-reference": 0,
"unicorn/no-array-reduce": 1,
"unicorn/no-await-expression-member": 1,
"unicorn/no-empty-file": 1,
"unicorn/no-hex-escape": 1,
"unicorn/no-null": 0,
"unicorn/no-object-as-default-parameter": 1,
"unicorn/no-process-exit": 0,
"unicorn/no-useless-switch-case": 0,
"unicorn/no-useless-undefined": ["error", { "checkArguments": false }],
"unicorn/numeric-separators-style": [
"warn",
{
"onlyIfContainsSeparator": false,
"number": { "minimumDigits": 7, "groupLength": 3 },
"binary": { "minimumDigits": 9, "groupLength": 4 },
"octal": { "minimumDigits": 9, "groupLength": 4 },
"hexadecimal": { "minimumDigits": 5, "groupLength": 2 }
}
],
"unicorn/prefer-code-point": 1,
"unicorn/prefer-logical-operator-over-ternary": 1,
"unicorn/prefer-module": 0,
"unicorn/prefer-node-protocol": 0,
"unicorn/prefer-number-properties": ["warn", { "checkInfinity": false }],
"unicorn/prefer-object-from-entries": 1,
"unicorn/prefer-regexp-test": 1,
"unicorn/prefer-string-replace-all": 1,
"unicorn/prefer-string-slice": 0,
"unicorn/prefer-switch": ["error", { "emptyDefaultCase": "do-nothing-comment" }],
"unicorn/prefer-top-level-await": 0,
"unicorn/prevent-abbreviations": 0,
"unicorn/switch-case-braces": ["error", "avoid"],
"unicorn/text-encoding-identifier-case": 0,
// previous eslint formatting rules
"@stylistic/js/arrow-parens": 2,
"@stylistic/js/arrow-spacing": 2,
Expand All @@ -74,40 +102,20 @@
"@stylistic/js/space-unary-ops": 2,
"@stylistic/js/spaced-comment": 2,
// https://github.com/eslint-community/eslint-plugin-n
"n/no-extraneous-require": [
"error",
{
"allowModules": ["puppeteer-extra-plugin-user-preferences", "puppeteer-extra-plugin-user-data-dir"]
}
],
"n/no-extraneous-require": ["error", { "allowModules": ["puppeteer-extra-plugin-user-preferences", "puppeteer-extra-plugin-user-data-dir"] }],
"n/no-deprecated-api": 1,
"n/no-missing-require": 0,
"n/no-process-exit": 0,
"n/no-unpublished-require": [
"error",
{
"allowModules": ["tosource"]
}
],
"n/no-unpublished-require": ["error", { "allowModules": ["tosource"] }],
"prettier/prettier": 0,
"yml/quotes": [
"error",
{
"prefer": "single"
}
]
"yml/quotes": ["error", { "prefer": "single" }]
},
"overrides": [
{
"files": ["*.yaml", "*.yml"],
"parser": "yaml-eslint-parser",
"rules": {
"lines-around-comment": [
"error",
{
"beforeBlockComment": false
}
]
"lines-around-comment": ["error", { "beforeBlockComment": false }]
}
}
]
Expand Down
6 changes: 3 additions & 3 deletions assets/radar-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
docs: 'https://docs.rsshub.app/routes/multimedia#onejav',
source: '/',
target: (params, url, document) => {
const today = document.querySelector('div.card.mb-1.card-overview').getAttribute('data-date').replace(/-/g, '');
const today = document.querySelector('div.card.mb-1.card-overview').dataset.date.replaceAll('-', '');
return `/onejav/day/${today}`;
},
},
Expand Down Expand Up @@ -215,7 +215,7 @@
} else {
return false;
}
return `/sexinsex/${pid}/${typeid ? typeid : ''}`;
return `/sexinsex/${pid}/${typeid ?? ''}`;
},
},
],
Expand All @@ -230,7 +230,7 @@
target: (params, url) => {
const id = new URL(url).searchParams.get('fid');
const type = new URL(url).searchParams.get('type');
return `/t66y/${id}/${type ? type : ''}`;
return `/t66y/${id}/${type ?? ''}`;
},
},
],
Expand Down
6 changes: 3 additions & 3 deletions jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./lib/*"]
}
"@/*": ["./lib/*"],
},
},
"include": ["./lib/**/*"]
"include": ["./lib/**/*"],
}
5 changes: 2 additions & 3 deletions lib/api_router.js → lib/api-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ router.get('/routes/:name?', (ctx) => {
let counter = 0;

const maintainer = require('./maintainer');
Object.keys(maintainer).forEach((i) => {
const path = i;
for (const path of Object.keys(maintainer)) {
const top = path.split('/')[1];

if (!ctx.params.name || top === ctx.params.name) {
Expand All @@ -18,7 +17,7 @@ router.get('/routes/:name?', (ctx) => {
}
counter++;
}
});
}

ctx.body = { counter, result };
});
Expand Down
10 changes: 5 additions & 5 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ const antiHotlink = require('./middleware/anti-hotlink');
const loadOnDemand = require('./middleware/load-on-demand');

const router = require('./router');
const core_router = require('./core_router');
const protected_router = require('./protected_router');
const core_router = require('./core-router');
const protected_router = require('./protected-router');
const mount = require('koa-mount');

// API related
const apiTemplate = require('./middleware/api-template');
const api_router = require('./api_router');
const api_router = require('./api-router');
const apiResponseHandler = require('./middleware/api-response-handler');

process.on('uncaughtException', (e) => {
Expand All @@ -37,8 +37,8 @@ const app = new Koa();
app.proxy = true;

// favicon
app.use(favicon(__dirname + '/favicon.png', { maxAge: 31536000000 }));
app.use(serve(__dirname + '/static', { maxage: 31536000000 }));
app.use(favicon(__dirname + '/favicon.png', { maxAge: 31_536_000_000 }));
app.use(serve(__dirname + '/static', { maxage: 31_536_000_000 }));

// global error handing
app.use(onerror);
Expand Down
20 changes: 10 additions & 10 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ const calculateValue = () => {
socket: envs.SOCKET || null, // 监听 Unix Socket, null 为禁用
},
listenInaddrAny: envs.LISTEN_INADDR_ANY || 1, // 是否允许公网连接,取值 0 1
requestRetry: parseInt(envs.REQUEST_RETRY) || 2, // 请求失败重试次数
requestTimeout: parseInt(envs.REQUEST_TIMEOUT) || 30000, // Milliseconds to wait for the server to end the response before aborting the request
ua: envs.UA ? envs.UA : envs.NO_RANDOM_UA === 'true' || envs.NO_RANDOM_UA === '1' ? TRUE_UA : randUserAgent({ browser: 'chrome', os: 'mac os', device: 'desktop' }),
requestRetry: Number.parseInt(envs.REQUEST_RETRY) || 2, // 请求失败重试次数
requestTimeout: Number.parseInt(envs.REQUEST_TIMEOUT) || 30000, // Milliseconds to wait for the server to end the response before aborting the request
ua: envs.UA ?? (envs.NO_RANDOM_UA === 'true' || envs.NO_RANDOM_UA === '1' ? TRUE_UA : randUserAgent({ browser: 'chrome', os: 'mac os', device: 'desktop' })),
trueUA: TRUE_UA,
// cors request
allowOrigin: envs.ALLOW_ORIGIN,
// cache
cache: {
type: typeof envs.CACHE_TYPE === 'undefined' ? 'memory' : envs.CACHE_TYPE, // 缓存类型,支持 'memory' 和 'redis',设为空可以禁止缓存
requestTimeout: parseInt(envs.CACHE_REQUEST_TIMEOUT) || 60,
routeExpire: parseInt(envs.CACHE_EXPIRE) || 5 * 60, // 路由缓存时间,单位为秒
contentExpire: parseInt(envs.CACHE_CONTENT_EXPIRE) || 1 * 60 * 60, // 不变内容缓存时间,单位为秒
type: envs.CACHE_TYPE === undefined ? 'memory' : envs.CACHE_TYPE, // 缓存类型,支持 'memory' 和 'redis',设为空可以禁止缓存
requestTimeout: Number.parseInt(envs.CACHE_REQUEST_TIMEOUT) || 60,
routeExpire: Number.parseInt(envs.CACHE_EXPIRE) || 5 * 60, // 路由缓存时间,单位为秒
contentExpire: Number.parseInt(envs.CACHE_CONTENT_EXPIRE) || 1 * 60 * 60, // 不变内容缓存时间,单位为秒
},
memory: {
max: parseInt(envs.MEMORY_MAX) || Math.pow(2, 8), // The maximum number of items that remain in the cache. This must be a positive finite intger.
max: Number.parseInt(envs.MEMORY_MAX) || Math.pow(2, 8), // The maximum number of items that remain in the cache. This must be a positive finite intger.
// https://github.com/isaacs/node-lru-cache#options
},
redis: {
Expand Down Expand Up @@ -96,7 +96,7 @@ const calculateValue = () => {
showLoggerTimestamp: envs.SHOW_LOGGER_TIMESTAMP,
sentry: {
dsn: envs.SENTRY,
routeTimeout: parseInt(envs.SENTRY_ROUTE_TIMEOUT) || 30000,
routeTimeout: Number.parseInt(envs.SENTRY_ROUTE_TIMEOUT) || 30000,
},
// feed config
hotlink: {
Expand All @@ -110,7 +110,7 @@ const calculateValue = () => {
allow_user_supply_unsafe_domain: envs.ALLOW_USER_SUPPLY_UNSAFE_DOMAIN === 'true',
},
suffix: envs.SUFFIX,
titleLengthLimit: parseInt(envs.TITLE_LENGTH_LIMIT) || 150,
titleLengthLimit: Number.parseInt(envs.TITLE_LENGTH_LIMIT) || 150,
openai: {
apiKey: envs.OPENAI_API_KEY,
model: envs.OPENAI_MODEL || 'gpt-3.5-turbo-16k',
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ if (config.enableCluster && cluster.isMaster && process.env.NODE_ENV !== 'test'
if (fs.existsSync(config.connect.socket)) {
fs.unlinkSync(config.connect.socket);
}
server = app.listen(config.connect.socket, parseInt(config.listenInaddrAny) ? null : '127.0.0.1');
server = app.listen(config.connect.socket, Number.parseInt(config.listenInaddrAny) ? null : '127.0.0.1');
logger.info('Listening Unix Socket ' + config.connect.socket);
process.on('SIGINT', () => {
fs.unlinkSync(config.connect.socket);
process.exit();
});
}
if (config.connect.port) {
server = app.listen(config.connect.port, parseInt(config.listenInaddrAny) ? null : '127.0.0.1');
server = app.listen(config.connect.port, Number.parseInt(config.listenInaddrAny) ? null : '127.0.0.1');
logger.info('Listening Port ' + config.connect.port);
}

Expand Down
18 changes: 9 additions & 9 deletions lib/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const dirname = __dirname + '/v2';
const fs = require('fs');
const { join } = require('path');
const path = require('path');

// Presence Check
for (const dir of fs.readdirSync(dirname)) {
const dirPath = join(dirname, dir);
if (fs.existsSync(join(dirPath, 'router.js')) && !fs.existsSync(join(dirPath, 'maintainer.js'))) {
throw Error(`No maintainer.js in "${dirPath}".`);
const dirPath = path.join(dirname, dir);
if (fs.existsSync(path.join(dirPath, 'router.js')) && !fs.existsSync(path.join(dirPath, 'maintainer.js'))) {
throw new Error(`No maintainer.js in "${dirPath}".`);
}
}

Expand All @@ -24,15 +24,15 @@ for (const dir in maintainerPath) {

// typo check e.g., ✘ module.export, ✔ module.exports
if (!Object.keys(routes).length) {
throw Error(`No maintainer in "${dir}".`);
throw new Error(`No maintainer in "${dir}".`);
}
for (const author of Object.values(routes)) {
if (!Array.isArray(author)) {
throw Error(`Maintainers' name should be an array in "${dir}".`);
throw new TypeError(`Maintainers' name should be an array in "${dir}".`);
}
// check for [], [''] or ['Someone', '']
if (author.length < 1 || author.includes('')) {
throw Error(`Empty maintainer in "${dir}".`);
throw new Error(`Empty maintainer in "${dir}".`);
}
}

Expand All @@ -43,11 +43,11 @@ for (const dir in maintainerPath) {

// 兼容旧版路由
const router = require('./router');
router.stack.forEach((e) => {
for (const e of router.stack) {
if (!maintainers[e.path]) {
maintainers[e.path] = [];
}
});
}

module.exports = Object.keys(maintainers)
.sort()
Expand Down
Loading

0 comments on commit 535c8f6

Please sign in to comment.