Skip to content

Commit c274370

Browse files
CopilotTechQuery
andauthored
[add] Render Debugger page for Lark Cloud documents (#15)
Co-authored-by: TechQuery <shiy2008@gmail.com>
1 parent 20beb11 commit c274370

14 files changed

Lines changed: 2936 additions & 2856 deletions

File tree

.github/workflows/Lark-notification.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ jobs:
2525

2626
- name: Event Message serialization
2727
id: message
28+
env:
29+
GITHUB_CONTEXT: ${{ toJSON(github) }}
2830
run: |
29-
YAML=$(
30-
cat <<JSON | deno run --allow-all .github/scripts/transform-message.ts
31-
${{ toJSON(github) }}
32-
JSON
33-
)
31+
YAML=$(printf '%s' "$GITHUB_CONTEXT" | deno run --allow-all .github/scripts/transform-message.ts)
3432
{
3533
echo 'content<<EOF'
3634
echo "$YAML"

.github/workflows/main.yml

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,45 +16,17 @@ jobs:
1616
- uses: actions/checkout@v6
1717
if: ${{ env.VERCEL_TOKEN && env.VERCEL_ORG_ID && env.VERCEL_PROJECT_ID }}
1818

19-
- uses: actions/setup-node@v6
20-
if: ${{ env.VERCEL_TOKEN && env.VERCEL_ORG_ID && env.VERCEL_PROJECT_ID }}
21-
with:
22-
node-version: 24
23-
2419
- name: Deploy to Vercel
2520
id: vercel-deployment
2621
if: ${{ env.VERCEL_TOKEN && env.VERCEL_ORG_ID && env.VERCEL_PROJECT_ID }}
27-
shell: bash
28-
run: |
29-
set -euo pipefail
30-
31-
npm install vercel -g
32-
33-
if [[ "$GITHUB_REF" == 'refs/heads/main' ]]; then
34-
DeployOutput=$(vercel -t "$VERCEL_TOKEN" --prod)
35-
else
36-
DeployOutput=$(vercel -t "$VERCEL_TOKEN")
37-
fi
38-
echo "$DeployOutput"
39-
40-
ParsedURL=$(echo "$DeployOutput" | grep -Eo 'https://[^[:space:]]*\.vercel\.app' | tail -n 1)
41-
42-
if [[ -z "$ParsedURL" ]]; then
43-
echo "Failed to parse Vercel URL from deploy output"
44-
exit 1
45-
fi
46-
vercel inspect "$ParsedURL" -t "$VERCEL_TOKEN" -F json > vercel-inspect.json
47-
48-
InspectURL=$(jq -r '.url // empty' vercel-inspect.json)
49-
50-
if [[ -z "$InspectURL" ]]; then
51-
echo "Failed to parse inspect url from vercel-inspect.json"
52-
exit 1
53-
fi
54-
if [[ "$InspectURL" != http* ]]; then
55-
InspectURL="https://$InspectURL"
56-
fi
57-
echo "preview-url=$InspectURL" >> "$GITHUB_OUTPUT"
22+
uses: amondnet/vercel-action@v42.3.0
23+
with:
24+
vercel-token: ${{ secrets.VERCEL_TOKEN }}
25+
github-token: ${{ secrets.GITHUB_TOKEN }}
26+
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
27+
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
28+
working-directory: ./
29+
vercel-args: ${{ github.ref == 'refs/heads/main' && ' --prod' || '' }}
5830

5931
- name: Lark notification
6032
uses: Open-Source-Bazaar/feishu-action@v3

components/GitDiffView.tsx

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import { generateDiffFile } from '@git-diff-view/file';
2+
import { DiffModeEnum, DiffView } from '@git-diff-view/react';
3+
import { Icon } from 'idea-react';
4+
import { computed, observable } from 'mobx';
5+
import { observer } from 'mobx-react';
6+
import { ObservedComponent } from 'mobx-react-helper';
7+
import { Alert, Button, ButtonGroup, Form } from 'react-bootstrap';
8+
9+
export interface TextFileData {
10+
fileName: string;
11+
content: string;
12+
language?: string;
13+
}
14+
15+
export type GitDiffViewProps = Record<'oldFile' | 'newFile', TextFileData>;
16+
17+
@observer
18+
export class GitDiffView extends ObservedComponent<GitDiffViewProps> {
19+
@observable
20+
accessor diffViewMode = DiffModeEnum.Split;
21+
22+
@observable
23+
accessor diffViewWrap = false;
24+
25+
@observable
26+
accessor diffViewHighlight = true;
27+
28+
@observable
29+
accessor expandAll = false;
30+
31+
@computed
32+
get hasNoDiff() {
33+
const { oldFile, newFile } = this.observedProps;
34+
35+
return oldFile.content === newFile.content;
36+
}
37+
38+
@computed
39+
get diffFile() {
40+
const { oldFile, newFile } = this.observedProps;
41+
const { diffViewMode, expandAll } = this;
42+
43+
const file = generateDiffFile(
44+
oldFile.fileName,
45+
oldFile.content,
46+
newFile.fileName,
47+
newFile.content,
48+
oldFile.language || 'text',
49+
newFile.language || 'text',
50+
);
51+
file.init();
52+
53+
if (diffViewMode & DiffModeEnum.Split) {
54+
file.buildSplitDiffLines();
55+
} else {
56+
file.buildUnifiedDiffLines();
57+
}
58+
if (expandAll)
59+
file.onAllExpand(diffViewMode & DiffModeEnum.Split ? 'split' : 'unified');
60+
61+
return file;
62+
}
63+
64+
renderDiff() {
65+
const {
66+
diffViewMode,
67+
diffViewWrap,
68+
diffViewHighlight,
69+
expandAll,
70+
diffFile,
71+
} = this;
72+
73+
return (
74+
<>
75+
<div className="d-flex flex-wrap align-items-center gap-2 mb-3">
76+
<ButtonGroup size="sm" aria-label="Diff mode">
77+
<Button
78+
variant={
79+
diffViewMode & DiffModeEnum.Split
80+
? 'primary'
81+
: 'outline-primary'
82+
}
83+
onClick={() => (this.diffViewMode = DiffModeEnum.Split)}
84+
>
85+
<Icon name="layout-split" />
86+
</Button>
87+
<Button
88+
variant={
89+
diffViewMode & DiffModeEnum.Split
90+
? 'outline-primary'
91+
: 'primary'
92+
}
93+
onClick={() => (this.diffViewMode = DiffModeEnum.Unified)}
94+
>
95+
<Icon name="list-ul" />
96+
</Button>
97+
</ButtonGroup>
98+
99+
<Form.Check
100+
type="switch"
101+
id="git-diff-wrap"
102+
label={<Icon name="text-wrap" />}
103+
checked={diffViewWrap}
104+
onChange={({ currentTarget }) =>
105+
(this.diffViewWrap = currentTarget.checked)
106+
}
107+
/>
108+
<Form.Check
109+
type="switch"
110+
id="git-diff-highlight"
111+
label={<Icon name="highlighter" />}
112+
checked={diffViewHighlight}
113+
onChange={({ currentTarget }) =>
114+
(this.diffViewHighlight = currentTarget.checked)
115+
}
116+
/>
117+
<Form.Check
118+
type="switch"
119+
id="git-diff-expand-all"
120+
label={<Icon name="arrows-expand" />}
121+
checked={expandAll}
122+
onChange={({ currentTarget }) =>
123+
(this.expandAll = currentTarget.checked)
124+
}
125+
/>
126+
</div>
127+
128+
<link
129+
rel="stylesheet"
130+
href="https://unpkg.com/@git-diff-view/react/styles/diff-view.css"
131+
/>
132+
<DiffView
133+
diffFile={diffFile}
134+
diffViewMode={diffViewMode}
135+
diffViewWrap={diffViewWrap}
136+
diffViewHighlight={diffViewHighlight}
137+
/>
138+
</>
139+
);
140+
}
141+
142+
render() {
143+
const { hasNoDiff, props } = this;
144+
145+
return hasNoDiff ? (
146+
<>
147+
<Alert variant="danger">No diff found between the two files.</Alert>
148+
149+
<pre>{props.oldFile.content}</pre>
150+
</>
151+
) : (
152+
this.renderDiff()
153+
);
154+
}
155+
}

eslint.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export default defineConfig(
2626
'simple-import-sort': simpleImportSortPlugin,
2727
'@typescript-eslint': tsEslint.plugin,
2828
react,
29-
// @ts-expect-error https://github.com/vercel/next.js/discussions/84792
3029
'@next/next': nextPlugin,
3130
},
3231
},

package.json

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,101 +8,94 @@
88
},
99
"dependencies": {
1010
"@editorjs/code": "^2.9.4",
11-
"@editorjs/editorjs": "^2.31.5",
12-
"@editorjs/header": "^2.8.8",
11+
"@editorjs/editorjs": "^2.31.6",
12+
"@editorjs/header": "^2.8.9",
1313
"@editorjs/image": "^2.10.3",
1414
"@editorjs/link": "^2.6.2",
1515
"@editorjs/list": "^2.0.9",
1616
"@editorjs/paragraph": "^2.11.7",
1717
"@editorjs/quote": "^2.7.6",
18+
"@git-diff-view/file": "^0.1.5",
19+
"@git-diff-view/react": "^0.1.5",
1820
"@mdx-js/loader": "^3.1.1",
1921
"@mdx-js/react": "^3.1.1",
20-
"@next/mdx": "^16.2.2",
21-
"@sentry/nextjs": "^10.47.0",
22+
"@next/mdx": "^16.2.9",
23+
"@sentry/nextjs": "^10.57.0",
2224
"copy-webpack-plugin": "^14.0.0",
2325
"core-js": "^3.49.0",
2426
"editorjs-html": "^4.0.5",
25-
"file-type": "^22.0.0",
27+
"file-type": "^22.0.1",
2628
"formidable": "^3.5.4",
27-
"idea-react": "^2.0.0-rc.13",
29+
"idea-react": "^2.2.2",
2830
"jsonwebtoken": "^9.0.3",
29-
"koa": "^3.2.0",
31+
"koa": "^3.2.1",
3032
"koa-jwt": "^4.0.4",
3133
"koajax": "^3.3.0",
3234
"less": "^4.6.4",
33-
"less-loader": "^12.3.2",
35+
"less-loader": "^13.0.0",
3436
"lodash": "^4.18.1",
35-
"marked": "^17.0.6",
37+
"marked": "^18.0.5",
3638
"mime": "^4.1.0",
37-
"mobx": "^6.15.0",
39+
"mobx": "^6.16.1",
3840
"mobx-github": "^0.6.2",
3941
"mobx-i18n": "^0.7.2",
4042
"mobx-lark": "^2.8.1",
41-
"mobx-react": "^9.2.1",
43+
"mobx-react": "^9.2.2",
4244
"mobx-react-helper": "^0.5.1",
4345
"mobx-restful": "^2.1.4",
4446
"mobx-restful-table": "^2.6.3",
45-
"next": "^16.2.2",
47+
"next": "^16.2.9",
4648
"next-pwa": "~5.6.0",
4749
"next-ssr-middleware": "^1.1.0",
4850
"next-with-less": "^3.0.1",
4951
"prismjs": "^1.30.0",
50-
"react": "^19.2.4",
52+
"react": "^19.2.7",
5153
"react-bootstrap": "^2.10.10",
5254
"react-bootstrap-editor": "^2.1.1",
53-
"react-dom": "^19.2.4",
55+
"react-dom": "^19.2.7",
5456
"react-editor-js": "^2.1.0",
5557
"remark-frontmatter": "^5.0.0",
5658
"remark-gfm": "^4.0.1",
5759
"remark-mdx-frontmatter": "^5.2.0",
58-
"undici": "^8.0.2",
59-
"web-utility": "^4.6.5",
60-
"webpack": "^5.105.4",
61-
"yaml": "^2.8.3"
60+
"undici": "^8.4.1",
61+
"web-utility": "^4.6.6",
62+
"webpack": "^5.107.2",
63+
"yaml": "^2.9.0"
6264
},
6365
"devDependencies": {
64-
"@babel/plugin-proposal-decorators": "^7.29.0",
65-
"@babel/plugin-transform-typescript": "^7.28.6",
66-
"@babel/preset-react": "^7.28.5",
67-
"@cspell/eslint-plugin": "^10.0.0",
66+
"@babel/plugin-proposal-decorators": "^7.29.7",
67+
"@babel/plugin-transform-typescript": "^7.29.7",
68+
"@babel/preset-react": "^7.29.7",
69+
"@cspell/eslint-plugin": "^10.0.1",
6870
"@eslint/js": "^10.0.1",
69-
"@next/eslint-plugin-next": "^16.2.2",
71+
"@next/eslint-plugin-next": "^16.2.9",
7072
"@softonus/prettier-plugin-duplicate-remover": "^1.1.2",
7173
"@stylistic/eslint-plugin": "^5.10.0",
7274
"@types/eslint-config-prettier": "^6.11.3",
73-
"@types/formidable": "^3.5.0",
75+
"@types/formidable": "^3.5.1",
7476
"@types/jsonwebtoken": "^9.0.10",
75-
"@types/koa": "^3.0.2",
77+
"@types/koa": "^3.0.3",
7678
"@types/lodash": "^4.17.24",
7779
"@types/next-pwa": "^5.6.9",
78-
"@types/node": "^24.12.2",
79-
"@types/react": "^19.2.14",
80-
"eslint": "^10.2.0",
81-
"eslint-config-next": "^16.2.2",
80+
"@types/node": "^24.13.2",
81+
"@types/react": "^19.2.17",
82+
"eslint": "^10.5.0",
83+
"eslint-config-next": "^16.2.9",
8284
"eslint-config-prettier": "^10.1.8",
8385
"eslint-plugin-react": "^7.37.5",
84-
"eslint-plugin-simple-import-sort": "^12.1.1",
85-
"globals": "^17.4.0",
86+
"eslint-plugin-simple-import-sort": "^13.0.0",
87+
"globals": "^17.6.0",
8688
"husky": "^9.1.7",
87-
"jiti": "^2.6.1",
88-
"lint-staged": "^16.4.0",
89-
"prettier": "^3.8.1",
89+
"jiti": "^2.7.0",
90+
"lint-staged": "^17.0.7",
91+
"prettier": "^3.8.4",
9092
"prettier-plugin-css-order": "^2.2.0",
9193
"typescript": "~5.9.3",
92-
"typescript-eslint": "^8.58.0"
94+
"typescript-eslint": "^8.61.0"
9395
},
9496
"resolutions": {
9597
"next": "$next"
9698
},
97-
"pnpm": {
98-
"onlyBuiltDependencies": [
99-
"@sentry/cli",
100-
"core-js",
101-
"less",
102-
"sharp",
103-
"unrs-resolver"
104-
]
105-
},
10699
"prettier": {
107100
"singleQuote": true,
108101
"trailingComma": "all",

pages/api/Lark/file/[id]/[name].ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Middleware } from 'koa';
33
import MIME from 'mime';
44
import { createKoaRouter, withKoaRouter } from 'next-ssr-middleware';
55
import { Readable } from 'stream';
6+
import { parseJSON } from 'web-utility';
67

78
import { CACHE_HOST } from '../../../../../models/configuration';
89
import { safeAPI } from '../../../core';
@@ -31,11 +32,7 @@ const downloader: Middleware = async context => {
3132
if (!ok) {
3233
context.status = status;
3334

34-
try {
35-
return (context.body = await response.json());
36-
} catch {
37-
return (context.body = await response.text());
38-
}
35+
return (context.body = parseJSON(await response.text()));
3936
}
4037
const mime = headers.get('Content-Type'),
4138
[stream1, stream2] = body!.tee();

0 commit comments

Comments
 (0)