Skip to content

Commit 48ff7b8

Browse files
committed
[add] Query API of BI Table schema
[optimize] support Ownership Transfer in copying Lark documents [remove] useless codes in Hackathon page
1 parent 95dbbd7 commit 48ff7b8

File tree

5 files changed

+176
-173
lines changed

5 files changed

+176
-173
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"mobx": "^6.15.0",
3333
"mobx-github": "^0.6.2",
3434
"mobx-i18n": "^0.7.2",
35-
"mobx-lark": "^2.6.0",
35+
"mobx-lark": "^2.6.3",
3636
"mobx-react": "^9.2.1",
3737
"mobx-react-helper": "^0.5.1",
3838
"mobx-restful": "^2.1.4",
@@ -74,7 +74,7 @@
7474
"eslint-config-prettier": "^10.1.8",
7575
"eslint-plugin-react": "^7.37.5",
7676
"eslint-plugin-simple-import-sort": "^12.1.1",
77-
"globals": "^16.5.0",
77+
"globals": "^17.0.0",
7878
"husky": "^9.1.7",
7979
"jiti": "^2.6.1",
8080
"less": "^4.5.1",
@@ -85,7 +85,7 @@
8585
"prettier-plugin-css-order": "^2.1.2",
8686
"sass": "^1.97.1",
8787
"typescript": "~5.9.3",
88-
"typescript-eslint": "^8.50.1"
88+
"typescript-eslint": "^8.51.0"
8989
},
9090
"resolutions": {
9191
"mobx-react-helper": "$mobx-react-helper",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Context } from 'koa';
2+
import { createKoaRouter, withKoaRouter } from 'next-ssr-middleware';
3+
4+
import { safeAPI, verifyJWT } from '../../../core';
5+
import { lark } from '../../core';
6+
7+
export const config = { api: { bodyParser: false } };
8+
9+
const router = createKoaRouter(import.meta.url);
10+
11+
router.get('/:id', safeAPI, verifyJWT, async (context: Context) => {
12+
const { id } = context.params,
13+
{ type } = context.query;
14+
15+
await lark.getAccessToken();
16+
17+
const documentId = type !== 'wiki' ? id : (await lark.wiki2drive(id)).obj_token;
18+
19+
context.body = await lark.getBiTableSchema(documentId);
20+
});
21+
22+
export default withKoaRouter(router);

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Context } from 'koa';
2+
import { LarkDocumentPathType } from 'mobx-lark';
23
import { createKoaRouter, withKoaRouter } from 'next-ssr-middleware';
34

45
import { safeAPI, verifyJWT } from '../../../core';
@@ -10,9 +11,25 @@ const router = createKoaRouter(import.meta.url);
1011

1112
router.post('/:type/:id', safeAPI, verifyJWT, async (context: Context) => {
1213
const { type, id } = context.params,
13-
{ name, parentToken } = Reflect.get(context.request, 'body');
14+
{ name, parentToken, ownerType, ownerId } = Reflect.get(context.request, 'body');
1415

15-
context.body = await lark.copyFile(`${type as 'wiki'}/${id}`, name, parentToken);
16+
const copiedFile =
17+
type === 'wiki'
18+
? await lark.copyFile(`${type as 'wiki'}/${id}`, name, parentToken)
19+
: await lark.copyFile(`${type as LarkDocumentPathType}/${id}`, name, parentToken);
20+
21+
const newId = 'token' in copiedFile ? copiedFile.token : copiedFile.obj_token;
22+
23+
if (ownerType && ownerId)
24+
try {
25+
await lark.driveFileStore.transferOwner(type, newId, {
26+
member_type: ownerType,
27+
member_id: ownerId,
28+
});
29+
} catch (error) {
30+
console.error(JSON.stringify(error, null, 2));
31+
}
32+
context.body = copiedFile;
1633
});
1734

1835
export default withKoaRouter(router);

pages/hackathon/[id].tsx

Lines changed: 46 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { observer } from 'mobx-react';
22
import { GetServerSideProps } from 'next';
33
import { FC, useContext } from 'react';
4-
import { Badge, Button, Card, Col, Container, Row } from 'react-bootstrap';
5-
import { UserRankView } from 'idea-react';
4+
import { Badge, Card, Col, Container, Row } from 'react-bootstrap';
5+
import { text2color, UserRankView } from 'idea-react';
66

77
import { PageHead } from '../../components/Layout/PageHead';
88
import { GitCard } from '../../components/Git/Card';
@@ -44,40 +44,19 @@ interface HackathonDetailProps {
4444
};
4545
}
4646

47+
const formatDateTime = (dateString: string) => {
48+
const date = new Date(dateString);
49+
return date.toLocaleString('zh-CN', {
50+
month: 'numeric',
51+
day: 'numeric',
52+
hour: '2-digit',
53+
minute: '2-digit',
54+
});
55+
};
56+
4757
const HackathonDetail: FC<HackathonDetailProps> = observer(({ hackathon }) => {
4858
const { t } = useContext(I18nContext);
4959

50-
const formatDateTime = (dateString: string) => {
51-
const date = new Date(dateString);
52-
return date.toLocaleString('zh-CN', {
53-
month: 'numeric',
54-
day: 'numeric',
55-
hour: '2-digit',
56-
minute: '2-digit',
57-
});
58-
};
59-
60-
const getTypeColor = (type: string) => {
61-
const colors: Record<string, string> = {
62-
workshop: 'info',
63-
presentation: 'danger',
64-
coding: 'success',
65-
break: 'warning',
66-
ceremony: 'primary',
67-
};
68-
return colors[type] || 'secondary';
69-
};
70-
71-
const getLevelColor = (level: string) => {
72-
const colors: Record<string, string> = {
73-
gold: 'warning',
74-
silver: 'secondary',
75-
bronze: 'dark',
76-
special: 'info',
77-
};
78-
return colors[level] || 'primary';
79-
};
80-
8160
return (
8261
<>
8362
<PageHead title={`${hackathon.title} - ${t('hackathon_detail')}`} />
@@ -112,63 +91,48 @@ const HackathonDetail: FC<HackathonDetailProps> = observer(({ hackathon }) => {
11291
</section>
11392

11493
<Container className="my-5">
115-
{/* Header: Agenda and Prizes side by side */}
116-
<Row>
117-
{/* Agenda Section */}
118-
<Col lg={6}>
119-
<section className={styles.section}>
120-
<h2 className={styles.sectionTitle}>📅 {t('agenda')}</h2>
121-
<div className="mt-4">
122-
{hackathon.agenda.map((item, index) => (
123-
<div key={index} className={`${styles.agendaItem} ${styles[item.type]}`}>
124-
<h5 className="text-white mb-2">{item.name}</h5>
125-
<p className="text-white-50 small mb-2">{item.summary}</p>
126-
<div className="d-flex justify-content-between align-items-center">
127-
<Badge bg={getTypeColor(item.type)} className="me-2">
128-
{t(item.type as any)}
129-
</Badge>
130-
<div className="text-white-50 small">
131-
{formatDateTime(item.startedAt)} - {formatDateTime(item.endedAt)}
132-
</div>
133-
</div>
94+
<section className={`${styles.section} ${styles.prizeSection}`}>
95+
<h2 className={styles.sectionTitle}>🏆 {t('prizes')}</h2>
96+
<div className="mt-4">
97+
<UserRankView
98+
title={t('hackathon_prizes')}
99+
rank={hackathon.prizes.map((prize, index) => ({
100+
id: `prize-${index}`,
101+
name: prize.name,
102+
avatar: prize.image,
103+
score: prize.price,
104+
email: prize.sponsor,
105+
}))}
106+
/>
107+
</div>
108+
</section>
109+
110+
<section className={styles.section}>
111+
<h2 className={styles.sectionTitle}>📅 {t('agenda')}</h2>
112+
<div className="mt-4">
113+
{hackathon.agenda.map((item, index) => (
114+
<div key={index} className={`${styles.agendaItem} ${styles[item.type]}`}>
115+
<h5 className="text-white mb-2">{item.name}</h5>
116+
<p className="text-white-50 small mb-2">{item.summary}</p>
117+
<div className="d-flex justify-content-between align-items-center">
118+
<Badge bg={text2color(item.type)} className="me-2">
119+
{t(item.type as any)}
120+
</Badge>
121+
<div className="text-white-50 small">
122+
{formatDateTime(item.startedAt)} - {formatDateTime(item.endedAt)}
134123
</div>
135-
))}
124+
</div>
136125
</div>
137-
</section>
138-
</Col>
139-
140-
{/* Prizes Section - Using UserRankView */}
141-
<Col lg={6}>
142-
<section className={`${styles.section} ${styles.prizeSection}`}>
143-
<h2 className={styles.sectionTitle}>🏆 {t('prizes')}</h2>
144-
<div className="mt-4">
145-
<UserRankView
146-
title={t('hackathon_prizes')}
147-
rank={hackathon.prizes.map((prize, index) => ({
148-
id: `prize-${index}`,
149-
name: prize.name,
150-
avatar: prize.image,
151-
score: prize.price,
152-
email: prize.sponsor,
153-
}))}
154-
/>
155-
</div>
156-
</section>
157-
</Col>
158-
</Row>
126+
))}
127+
</div>
128+
</section>
159129

160130
{/* Mid-front: Organizations - Horizontal logo layout */}
161131
<section className={styles.section}>
162132
<h2 className={styles.sectionTitle}>🏢 {t('organizations')}</h2>
163133
<div className={styles.orgContainer}>
164134
{hackathon.organizations.map((org, index) => (
165-
<a
166-
key={index}
167-
href={org.link}
168-
target="_blank"
169-
rel="noreferrer"
170-
title={org.name}
171-
>
135+
<a key={index} href={org.link} target="_blank" rel="noreferrer" title={org.name}>
172136
<img src={org.logo} alt={org.name} className={styles.orgLogo} />
173137
</a>
174138
))}

0 commit comments

Comments
 (0)