Skip to content

Commit ad52aa3

Browse files
committed
[fix] some API data & name bugs
1 parent a8af3ba commit ad52aa3

File tree

11 files changed

+34
-26
lines changed

11 files changed

+34
-26
lines changed

models/Base.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ export const wrapTime = (date?: TableCellValue) =>
7878
export const wrapURL = (link?: TableCellValue) =>
7979
link ? { link, text: link } : undefined;
8080

81-
export const wrapFile = (URI?: TableCellValue) =>
82-
typeof URI === 'string'
83-
? ([{ file_token: URI.split('/').at(-2) }] as TableCellValue)
84-
: undefined;
81+
export const wrapFile = (URIs?: TableCellValue) =>
82+
(Array.isArray(URIs) ? URIs : [URIs])
83+
.map(
84+
URI => typeof URI === 'string' && { file_token: URI.split('/').at(-2) },
85+
)
86+
.filter(Boolean) as TableCellValue;
8587

8688
export const wrapRelation = (ID?: TableCellValue) =>
8789
ID ? (Array.isArray(ID) ? ID : ([ID] as TableCellValue)) : undefined;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"mobx-restful-table": "^2.2.0",
4444
"next": "^15.3.1",
4545
"next-pwa": "~5.6.0",
46-
"next-ssr-middleware": "^0.10.0-rc.2",
46+
"next-ssr-middleware": "^0.10.0",
4747
"next-with-less": "^3.0.1",
4848
"prismjs": "^1.30.0",
4949
"react": "^19.1.0",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { withSafeKoa } from '../../../core';
22
import { proxyLark } from '../../core';
33

4+
export const config = { api: { bodyParser: false } };
5+
46
export default withSafeKoa(proxyLark());

pages/api/Lark/bitable/v1/[...slug].ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { DataObject } from 'mobx-restful';
44
import { withSafeKoa } from '../../../core';
55
import { proxyLark } from '../../core';
66

7+
export const config = { api: { bodyParser: false } };
8+
79
function filterData(fields: DataObject) {
810
for (const key of Object.keys(fields))
911
if (!/^\w+$/.test(key)) delete fields[key];

pages/api/Lark/core.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@ export const normalizeMarkdownArray = (list: TableCellText[]) =>
2121
export const proxyLark =
2222
<T extends LarkData>(dataFilter?: (path: string, data: T) => T): Middleware =>
2323
async context => {
24-
const { method, url, headers, body } = context;
24+
const { method, url, headers, request } = context;
2525

2626
if (!headers.authorization) await lark.getAccessToken();
2727

2828
delete headers.host;
2929

3030
const path = url!.slice(`/api/Lark/`.length);
3131

32-
const { status, body: data } = await lark.client.request<T>({
32+
const { status, body } = await lark.client.request<T>({
3333
// @ts-expect-error Type compatibility issue
3434
method,
3535
path,
3636
// @ts-expect-error Type compatibility issue
3737
headers,
38-
body: body || undefined,
38+
body: Reflect.get(request, 'body'),
3939
});
4040

4141
context.status = status;
4242

43-
context.body = dataFilter?.(path, data!) || data;
43+
context.body = dataFilter?.(path, body!) || body;
4444
};
4545

4646
export const larkOauth2 = oauth2Signer({

pages/api/Lark/document/markdown/[...slug].ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { createRouter } from 'next-ssr-middleware';
1+
import { createKoaRouter } from 'next-ssr-middleware';
22

33
import { withSafeKoaRouter } from '../../../core';
44
import { lark } from '../../core';
55

6-
const router = createRouter(import.meta.url);
6+
const router = createKoaRouter(import.meta.url);
77

88
router.get('/:type/:id', async context => {
99
const { type, id } = context.params;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { fileTypeFromStream } from 'file-type';
22
import MIME from 'mime';
3-
import { createRouter } from 'next-ssr-middleware';
3+
import { createKoaRouter } from 'next-ssr-middleware';
44
import { Readable } from 'stream';
55

66
import { withSafeKoaRouter } from '../../../core';
77
import { lark } from '../../core';
88

99
export const CACHE_HOST = process.env.NEXT_PUBLIC_CACHE_HOST!;
1010

11-
const router = createRouter(import.meta.url);
11+
const router = createKoaRouter(import.meta.url);
1212

1313
router.all('/:id/:name', async context => {
1414
const { method, url, params, query } = context;

pages/api/Lark/file/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import formidable from 'formidable';
33
import { readFile } from 'fs/promises';
44
import MIME from 'mime';
55
import { UploadTargetType } from 'mobx-lark';
6-
import { createRouter } from 'next-ssr-middleware';
6+
import { createKoaRouter } from 'next-ssr-middleware';
77
import { parse } from 'path';
88

99
import { LARK_API_HOST } from '../../../../models/Base';
@@ -12,7 +12,7 @@ import { lark } from '../core';
1212

1313
export const config = { api: { bodyParser: false } };
1414

15-
const router = createRouter(import.meta.url);
15+
const router = createKoaRouter(import.meta.url);
1616

1717
router.post('/', async context => {
1818
const form = formidable();

pages/api/core.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export const safeAPI: Middleware<any, any> = async (context: Context, next) => {
3535
} catch {
3636
//
3737
}
38-
console.error((context.body = body));
38+
console.error(JSON.stringify(body, null, 2));
39+
40+
context.body = body;
3941
}
4042
};
4143

pages/api/hello.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
2-
import { createRouter } from 'next-ssr-middleware';
2+
import { createKoaRouter } from 'next-ssr-middleware';
33

44
import { withSafeKoaRouter } from './core';
55

6-
const router = createRouter(import.meta.url);
6+
const router = createKoaRouter(import.meta.url);
77

8-
router.get('/', async ctx => {
9-
ctx.status = 401;
10-
ctx.body = { name: 'John Doe' };
8+
router.get('/', async context => {
9+
context.status = 401;
10+
context.body = { name: 'John Doe' };
1111
});
1212

1313
export default withSafeKoaRouter(router);

0 commit comments

Comments
 (0)