Skip to content

Commit fd01549

Browse files
committed
refactor: better code style
1 parent 6ef8692 commit fd01549

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+5519
-2718
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
9+
[*.{ts,js,json,yaml,yml}]
10+
indent_style = space
11+
indent_size = 2
12+
13+
[*.md]
14+
trim_trailing_whitespace = false

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
dist
3+
.edgeone
4+
*.js

.eslintrc.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"parserOptions": {
4+
"ecmaVersion": 2020,
5+
"sourceType": "module"
6+
},
7+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
8+
"plugins": ["@typescript-eslint"],
9+
"rules": {
10+
"@typescript-eslint/no-explicit-any": "warn",
11+
"@typescript-eslint/explicit-function-return-type": "off",
12+
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }],
13+
"no-console": "off",
14+
"semi": ["error", "always"],
15+
"quotes": ["error", "single", { "avoidEscape": true }]
16+
},
17+
"env": {
18+
"browser": true,
19+
"es2020": true
20+
}
21+
}

.github/workflows/ci.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, master, develop]
6+
paths-ignore:
7+
- '**.md'
8+
- 'docs/**'
9+
- '.editorconfig'
10+
- '.gitignore'
11+
- 'LICENSE'
12+
pull_request:
13+
branches: [main, master, develop]
14+
paths-ignore:
15+
- '**.md'
16+
- 'docs/**'
17+
- '.editorconfig'
18+
- '.gitignore'
19+
- 'LICENSE'
20+
21+
jobs:
22+
lint-and-test:
23+
name: Lint and Test
24+
runs-on: ubuntu-latest
25+
26+
strategy:
27+
matrix:
28+
node-version: [ 24.5.0 ]
29+
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
34+
- name: Setup Node.js ${{ matrix.node-version }}
35+
uses: actions/setup-node@v4
36+
with:
37+
node-version: ${{ matrix.node-version }}
38+
cache: 'npm'
39+
40+
- name: Install dependencies
41+
run: npm ci
42+
43+
- name: Type check
44+
run: npm run type-check
45+
46+
- name: Lint
47+
run: npm run lint
48+
49+
- name: Format check
50+
run: npm run format:check
51+
52+
- name: Run tests
53+
run: npm run test
54+
55+
- name: Build
56+
run: npm run build
57+
58+
coverage:
59+
name: Test Coverage
60+
runs-on: ubuntu-latest
61+
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
62+
63+
steps:
64+
- name: Checkout code
65+
uses: actions/checkout@v4
66+
67+
- name: Setup Node.js
68+
uses: actions/setup-node@v4
69+
with:
70+
node-version: '24.5.0'
71+
cache: 'npm'
72+
73+
- name: Install dependencies
74+
run: npm ci
75+
76+
- name: Run tests with coverage
77+
run: npm run test:coverage
78+
79+
- name: Upload coverage to Codecov
80+
uses: codecov/codecov-action@v3
81+
with:
82+
files: ./coverage/coverage-final.json
83+
flags: unittests
84+
name: codecov-umbrella
85+
fail_ci_if_error: false

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
dist
3+
.edgeone
4+
*.md

.prettierrc.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"tabWidth": 2,
5+
"trailingComma": "es5",
6+
"printWidth": 100,
7+
"arrowParens": "always",
8+
"endOfLine": "lf"
9+
}

PROXY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
## 配置方式
1111

12-
### 1. 默认配置(推荐)⭐
12+
### 1. 默认配置
1313

1414
**无需任何环境变量配置**
1515

@@ -46,7 +46,7 @@ ENABLE_APN_PROXY=false
4646
- 可能因不支持 HTTP/2 而失败
4747
- 仅用于调试或特殊场景
4848

49-
### 4. 代理鉴权(可选)
49+
### 4. 代理鉴权(推荐)⭐
5050

5151
```env
5252
APNS_PROXY_SECRET=your-shared-secret

edge-functions/api/[[default]].ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* This file uses [[default]] naming to catch all unmatched routes.
1111
* It has the lowest priority, so specific routes like /push, /register, etc.
1212
* will be handled by their dedicated handlers first.
13-
*
13+
*
1414
* Note: This endpoint REQUIRES authentication when enabled
1515
*/
1616

@@ -22,19 +22,15 @@ import { checkBasicAuth, unauthorizedResponse } from '../../src/utils/auth';
2222
/**
2323
* Reserved paths that should not be handled by this catch-all
2424
*/
25-
const RESERVED_PATHS = [
26-
'/favicon.ico',
27-
'/robots.txt',
28-
];
25+
const RESERVED_PATHS = ['/favicon.ico', '/robots.txt'];
2926

3027
/**
3128
* Check if path is reserved
3229
*/
3330
function isReservedPath(path: string): boolean {
3431
const normalizedPath = path.toLowerCase();
3532
return RESERVED_PATHS.some(
36-
(reserved) =>
37-
normalizedPath === reserved || normalizedPath.startsWith(`${reserved}/`)
33+
(reserved) => normalizedPath === reserved || normalizedPath.startsWith(`${reserved}/`)
3834
);
3935
}
4036

edge-functions/api/healthz.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import type { EventContext } from '../../src/types/common';
55
* GET /healthz
66
*
77
* Returns plain text "ok" for health check
8-
*
8+
*
99
* Note: This endpoint does NOT require authentication
1010
*/
11-
export async function onRequest(context: EventContext): Promise<Response> {
11+
export async function onRequest(_context: EventContext): Promise<Response> {
1212
return new Response('ok', {
1313
status: 200,
1414
headers: {

edge-functions/api/info.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { EventContext } from '../../src/types/common';
22
import { countDevices } from '../../src/utils/kv';
33

4+
/* eslint-disable @typescript-eslint/no-explicit-any */
5+
46
/**
57
* Info endpoint - Server information
68
* GET /info
@@ -13,7 +15,8 @@ import { countDevices } from '../../src/utils/kv';
1315
*/
1416
export async function onRequest(context: EventContext): Promise<Response> {
1517
// Check if device counting is enabled via environment variable
16-
const enableDeviceCount = context.env.ENABLE_DEVICE_COUNT === 'true' || context.env.ENABLE_DEVICE_COUNT === '1';
18+
const enableDeviceCount =
19+
context.env.ENABLE_DEVICE_COUNT === 'true' || context.env.ENABLE_DEVICE_COUNT === '1';
1720

1821
const info: any = {
1922
version: 'v2.0.0',

0 commit comments

Comments
 (0)