Skip to content

Commit 2e28a72

Browse files
committed
[fix] Lark file download type
[optimize] generate Next.js type after installation automatically [optimize] update Upstream packages
1 parent c6b8061 commit 2e28a72

File tree

6 files changed

+546
-556
lines changed

6 files changed

+546
-556
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ yarn.lock
1111
/coverage
1212

1313
# next.js
14+
next-env.d.ts
1415
/.next/
1516
/out/
1617

next-env.d.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"@mui/material": "^7.3.6",
1818
"@mui/material-nextjs": "^7.3.6",
1919
"@passwordless-id/webauthn": "^2.3.1",
20-
"@sentry/nextjs": "^10.30.0",
21-
"file-type": "^21.1.1",
20+
"@sentry/nextjs": "^10.32.1",
21+
"file-type": "^21.2.0",
2222
"idb-keyval": "^6.2.2",
2323
"jsonwebtoken": "^9.0.3",
2424
"koa": "^3.1.1",
@@ -34,13 +34,13 @@
3434
"mobx-react": "^9.2.1",
3535
"mobx-react-helper": "^0.5.1",
3636
"mobx-restful": "^2.1.4",
37-
"next": "^16.0.10",
37+
"next": "^16.1.1",
3838
"next-pwa": "~5.6.0",
39-
"next-ssr-middleware": "^1.0.3",
39+
"next-ssr-middleware": "^1.1.0",
4040
"react": "^19.2.3",
4141
"react-dom": "^19.2.3",
4242
"web-utility": "^4.6.4",
43-
"webpack": "^5.103.0"
43+
"webpack": "^5.104.1"
4444
},
4545
"devDependencies": {
4646
"@babel/plugin-proposal-decorators": "^7.28.0",
@@ -49,7 +49,7 @@
4949
"@cspell/eslint-plugin": "^9.4.0",
5050
"@eslint/js": "^9.39.2",
5151
"@idea2app/data-server": "^1.0.0-rc.9",
52-
"@next/eslint-plugin-next": "^16.0.10",
52+
"@next/eslint-plugin-next": "^16.1.1",
5353
"@stylistic/eslint-plugin": "^5.6.1",
5454
"@tailwindcss/postcss": "^4.1.18",
5555
"@tailwindcss/typography": "^0.5.19",
@@ -58,10 +58,10 @@
5858
"@types/koa": "^3.0.1",
5959
"@types/lodash.debounce": "^4.0.9",
6060
"@types/next-pwa": "^5.6.9",
61-
"@types/node": "^22.19.2",
61+
"@types/node": "^22.19.3",
6262
"@types/react": "^19.2.7",
6363
"eslint": "^9.39.2",
64-
"eslint-config-next": "^16.0.10",
64+
"eslint-config-next": "^16.1.1",
6565
"eslint-config-prettier": "^10.1.8",
6666
"eslint-plugin-react": "^7.37.5",
6767
"eslint-plugin-simple-import-sort": "^12.1.1",
@@ -76,7 +76,7 @@
7676
"prettier-plugin-tailwindcss": "^0.7.2",
7777
"tailwindcss": "^4.1.18",
7878
"typescript": "~5.9.3",
79-
"typescript-eslint": "^8.49.0"
79+
"typescript-eslint": "^8.50.1"
8080
},
8181
"resolutions": {
8282
"mobx-github": "$mobx-github",
@@ -108,6 +108,7 @@
108108
"e": "pnpx @dotenvx/dotenvx run -f .env.personal.local -- pnpm",
109109
"prepare": "husky || true",
110110
"install": "xgit download https://github.com/idea2app/key-vault main idea2app.github.io || true",
111+
"postinstall": "next typegen",
111112
"dev": "next dev --webpack",
112113
"build": "next build --webpack",
113114
"start": "next start",

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,30 @@ const downloader: Middleware = async context => {
2222
const token = await lark.getAccessToken();
2323

2424
const response = await fetch(lark.client.baseURI + `drive/v1/medias/${id}/download`, {
25-
method,
2625
headers: { Authorization: `Bearer ${token}` },
2726
});
2827
const { ok, status, headers, body } = response;
2928

3029
if (!ok) {
3130
context.status = status;
3231

33-
return (context.body = await response.json());
32+
try {
33+
return (context.body = await response.json());
34+
} catch {
35+
return (context.body = await response.text());
36+
}
3437
}
3538
const mime = headers.get('Content-Type'),
3639
[stream1, stream2] = body!.tee();
3740

38-
const contentType = mime?.startsWith('application/octet-stream')
39-
? (await fileTypeFromStream(stream1))?.mime
40-
: mime;
41+
const contentType = (await fileTypeFromStream(stream1))?.mime || mime;
42+
4143
context.set('Content-Type', contentType || 'application/octet-stream');
4244
context.set('Content-Disposition', headers.get('Content-Disposition') || '');
4345
context.set('Content-Length', headers.get('Content-Length') || '');
4446

45-
if (method === 'GET')
46-
// @ts-expect-error Web type compatibility
47-
context.body = Readable.fromWeb(stream2);
47+
// @ts-expect-error Web type compatibility
48+
context.body = method === 'GET' ? Readable.fromWeb(stream2) : '';
4849
};
4950

5051
router.head('/:id', safeAPI, downloader).get('/:id', safeAPI, downloader);

pages/api/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { JsonWebTokenError, sign } from 'jsonwebtoken';
1+
import { JsonWebTokenError } from 'jsonwebtoken';
22
import { Context, Middleware, ParameterizedContext } from 'koa';
33
import JWT from 'koa-jwt';
44
import { HTTPError } from 'koajax';

0 commit comments

Comments
 (0)