Skip to content

Commit f8535f7

Browse files
committed
feat(api): replace prolong with extend
1 parent 4644a8c commit f8535f7

File tree

9 files changed

+55
-54
lines changed

9 files changed

+55
-54
lines changed

src/GZCTF/ClientApp/src/Api.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,10 +1739,9 @@ export interface SignatureVerifyModel {
17391739
publicKey: string;
17401740
}
17411741

1742-
import type {AxiosInstance, AxiosRequestConfig, AxiosResponse, HeadersDefaults, ResponseType} from "axios";
1742+
import { apiLanguage } from "@Utils/I18n";
1743+
import type { AxiosInstance, AxiosRequestConfig, AxiosResponse, HeadersDefaults, ResponseType } from "axios";
17431744
import axios from "axios";
1744-
import useSWR, {mutate, MutatorOptions, SWRConfiguration} from "swr";
1745-
import {currentLanguage} from "@Utils/I18n";
17461745

17471746
export type QueryParamsType = Record<string | number, any>;
17481747

@@ -1863,7 +1862,7 @@ export class HttpClient<SecurityDataType = unknown> {
18631862
headers: {
18641863
...(requestParams.headers || {}),
18651864
...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}),
1866-
...({ "Accept-Language": currentLanguage.replace("_", "-") })
1865+
...{ "Accept-Language": apiLanguage },
18671866
},
18681867
params: query,
18691868
responseType: responseFormat,
@@ -1873,6 +1872,8 @@ export class HttpClient<SecurityDataType = unknown> {
18731872
};
18741873
}
18751874

1875+
import useSWR, { MutatorOptions, SWRConfiguration, mutate } from "swr";
1876+
18761877
/**
18771878
* @title GZCTF Server API
18781879
* @version v1
@@ -3653,6 +3654,22 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
36533654
options?: MutatorOptions,
36543655
) => mutate<GameEvent[]>([`/api/game/${id}/events`, query], data, options),
36553656

3657+
/**
3658+
* @description 延长容器时间,需要User权限,且只能在到期前十分钟延期两小时
3659+
*
3660+
* @tags Game
3661+
* @name GameExtendContainerLifetime
3662+
* @summary 延长容器时间
3663+
* @request POST:/api/game/{id}/container/{challengeId}/extend
3664+
*/
3665+
gameExtendContainerLifetime: (id: number, challengeId: number, params: RequestParams = {}) =>
3666+
this.request<ContainerInfoModel, RequestResponse>({
3667+
path: `/api/game/${id}/container/${challengeId}/extend`,
3668+
method: "POST",
3669+
format: "json",
3670+
...params,
3671+
}),
3672+
36563673
/**
36573674
* @description 获取比赛的详细信息
36583675
*
@@ -4124,22 +4141,6 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
41244141
options?: MutatorOptions,
41254142
) => mutate<ParticipationInfoModel[]>(`/api/game/${id}/participations`, data, options),
41264143

4127-
/**
4128-
* @description 延长容器时间,需要User权限,且只能在到期前十分钟延期两小时
4129-
*
4130-
* @tags Game
4131-
* @name GameProlongContainer
4132-
* @summary 延长容器时间
4133-
* @request POST:/api/game/{id}/container/{challengeId}/prolong
4134-
*/
4135-
gameProlongContainer: (id: number, challengeId: number, params: RequestParams = {}) =>
4136-
this.request<ContainerInfoModel, RequestResponse>({
4137-
path: `/api/game/${id}/container/${challengeId}/prolong`,
4138-
method: "POST",
4139-
format: "json",
4140-
...params,
4141-
}),
4142-
41434144
/**
41444145
* @description 获取积分榜数据
41454146
*

src/GZCTF/ClientApp/src/components/ChallengeDetailModal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ const ChallengeDetailModal: FC<ChallengeDetailModalProps> = (props) => {
124124
.finally(() => setDisabled(false))
125125
}
126126

127-
const onProlongContainer = () => {
127+
const onExtendContainer = () => {
128128
if (!challengeId) return
129129
setDisabled(true)
130130
api.game
131-
.gameProlongContainer(gameId, challengeId)
131+
.gameExtendContainerLifetime(gameId, challengeId)
132132
.then((res) => {
133133
mutate({
134134
...challenge,
@@ -331,7 +331,7 @@ const ChallengeDetailModal: FC<ChallengeDetailModalProps> = (props) => {
331331
<InstanceEntry
332332
context={challenge.context}
333333
onCreate={onCreateContainer}
334-
onProlong={onProlongContainer}
334+
onExtend={onExtendContainer}
335335
onDestroy={onDestroyContainer}
336336
disabled={disabled}
337337
/>

src/GZCTF/ClientApp/src/components/InstanceEntry.tsx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ interface InstanceEntryProps {
3333
context: ClientFlagContext
3434
disabled: boolean
3535
onCreate?: () => void
36-
onProlong?: () => void
36+
onExtend?: () => void
3737
onDestroy?: () => void
3838
}
3939

4040
dayjs.extend(duration)
4141

4242
interface CountdownProps {
4343
time: string
44-
prolongNotice: () => void
44+
extendNotice: () => void
4545
}
4646

47-
const Countdown: FC<CountdownProps> = ({ time, prolongNotice }) => {
47+
const Countdown: FC<CountdownProps> = ({ time, extendNotice }) => {
4848
const [now, setNow] = useState(dayjs())
4949
const end = dayjs(time)
5050
const countdown = dayjs.duration(end.diff(now))
@@ -60,7 +60,7 @@ const Countdown: FC<CountdownProps> = ({ time, prolongNotice }) => {
6060
if (countdown.asSeconds() <= 0) return
6161

6262
if (countdown.asMinutes() < 10 && !haveNoticed) {
63-
prolongNotice()
63+
extendNotice()
6464
setHaveNoticed(true)
6565
} else if (countdown.asMinutes() > 10) {
6666
setHaveNoticed(false)
@@ -83,39 +83,39 @@ export const InstanceEntry: FC<InstanceEntryProps> = (props) => {
8383
const isPlatformProxy = instanceEntry.length === 36 && !instanceEntry.includes(':')
8484
const copyEntry = isPlatformProxy ? getProxyUrl(instanceEntry, test) : instanceEntry
8585

86-
const [canProlong, setCanProlong] = useState(false)
86+
const [canExtend, setCanExtend] = useState(false)
8787

8888
const { t } = useTranslation()
8989

90-
const prolongNotice = () => {
91-
if (canProlong) return
90+
const extendNotice = () => {
91+
if (canExtend) return
9292

9393
showNotification({
9494
color: 'orange',
95-
title: t('challenge.notification.instance.prolong.note.title'),
96-
message: t('challenge.notification.instance.prolong.note.message'),
95+
title: t('challenge.notification.instance.extend.note.title'),
96+
message: t('challenge.notification.instance.extend.note.message'),
9797
icon: <Icon path={mdiExclamation} size={1} />,
9898
})
9999

100-
setCanProlong(true)
100+
setCanExtend(true)
101101
}
102102

103103
useEffect(() => {
104104
setWithContainer(!!context.instanceEntry)
105105
const countdown = dayjs.duration(dayjs(context.closeTime ?? 0).diff(dayjs()))
106-
setCanProlong(countdown.asMinutes() < 10)
106+
setCanExtend(countdown.asMinutes() < 10)
107107
}, [context])
108108

109-
const onProlong = () => {
110-
if (!canProlong || !props.onProlong) return
109+
const onExtend = () => {
110+
if (!canExtend || !props.onExtend) return
111111

112-
props.onProlong()
113-
setCanProlong(false)
112+
props.onExtend()
113+
setCanExtend(false)
114114

115115
showNotification({
116116
color: 'teal',
117-
title: t('challenge.notification.instance.prolong.success.title'),
118-
message: t('challenge.notification.instance.prolong.success.message'),
117+
title: t('challenge.notification.instance.extend.success.title'),
118+
message: t('challenge.notification.instance.extend.success.message'),
119119
icon: <Icon path={mdiCheck} size={1} />,
120120
})
121121
}
@@ -225,16 +225,16 @@ export const InstanceEntry: FC<InstanceEntryProps> = (props) => {
225225
<Stack align="left" spacing={0}>
226226
<Text size="sm" fw={600}>
227227
{t('challenge.content.instance.actions.count_down')}
228-
<Countdown time={context.closeTime ?? '0'} prolongNotice={prolongNotice} />
228+
<Countdown time={context.closeTime ?? '0'} extendNotice={extendNotice} />
229229
</Text>
230230
<Text size="xs" color="dimmed" fw={600}>
231231
{t('challenge.content.instance.actions.note')}
232232
</Text>
233233
</Stack>
234234

235235
<Group position="right" noWrap spacing="xs">
236-
<Button color="orange" onClick={onProlong} disabled={!canProlong}>
237-
{t('challenge.button.instance.prolong')}
236+
<Button color="orange" onClick={onExtend} disabled={!canExtend}>
237+
{t('challenge.button.instance.extend')}
238238
</Button>
239239
<Button color="red" onClick={onDestroy} disabled={disabled}>
240240
{t('challenge.button.instance.destroy')}

src/GZCTF/ClientApp/src/components/admin/ChallengePreviewModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ const ChallengePreviewModal: FC<ChallengePreviewModalProps> = (props) => {
188188
context={context}
189189
disabled={false}
190190
onCreate={onCreate}
191-
onProlong={onCreate}
191+
onExtend={onCreate}
192192
onDestroy={onDestroy}
193193
/>
194194
)}

src/GZCTF/ClientApp/src/locales/en_US/challenge.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"submit_flag": "Submit Flag",
1212
"instance": {
1313
"create": "Create",
14-
"prolong": "Extend",
14+
"extend": "Extend",
1515
"destroy": "Destroy"
1616
}
1717
},
@@ -105,7 +105,7 @@
105105
"title": "Instance entry copied to clipboard"
106106
}
107107
},
108-
"prolong": {
108+
"extend": {
109109
"note": {
110110
"message": "Please extend lifetime or destroy instance in time",
111111
"title": "Instance is due"

src/GZCTF/ClientApp/src/locales/ja_JP/challenge.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"submit_flag": "フラッグを提出",
1212
"instance": {
1313
"create": "インスタンスを作成",
14-
"prolong": "期限を延ばす",
14+
"extend": "期限を延ばす",
1515
"destroy": "インスタンスを破棄"
1616
}
1717
},
@@ -105,7 +105,7 @@
105105
"title": "インスタンスのエントリーがコピーされました"
106106
}
107107
},
108-
"prolong": {
108+
"extend": {
109109
"note": {
110110
"message": "期限を延長するか、期限内にインスタンスを破棄してください",
111111
"title": "インスタンスの有効期限が近づいています"

src/GZCTF/ClientApp/src/locales/zh_CN/challenge.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"submit_flag": "提交 flag",
1212
"instance": {
1313
"create": "创建实例",
14-
"prolong": "延长时间",
14+
"extend": "延长时间",
1515
"destroy": "销毁实例"
1616
}
1717
},
@@ -105,7 +105,7 @@
105105
"title": "实例入口已复制到剪贴板"
106106
}
107107
},
108-
"prolong": {
108+
"extend": {
109109
"note": {
110110
"message": "请及时延长时间或销毁实例",
111111
"title": "实例即将到期"

src/GZCTF/ClientApp/src/utils/I18n.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const useLanguage = () => {
2222

2323
useEffect(() => {
2424
i18n.changeLanguage(language)
25-
currentLanguage = language
25+
apiLanguage = language.replace("_", "-")
2626
}, [language])
2727

2828
const supportedLanguages = Object.keys(resources) as SupportedLanguages[]
@@ -40,4 +40,4 @@ export const useLanguage = () => {
4040
return { language, setLanguage, supportedLanguages }
4141
}
4242

43-
export let currentLanguage: string = 'zh-CN';
43+
export let apiLanguage: string = 'zh-CN'

src/GZCTF/ClientApp/template/http-client.eta

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { apiConfig, generateResponses, config } = it;
44

55
import type { AxiosInstance, AxiosRequestConfig, HeadersDefaults, ResponseType, AxiosResponse } from "axios";
66
import axios from "axios";
7-
import { currentLanguage } from "@Utils/I18n";
7+
import { apiLanguage } from "@Utils/I18n";
88

99
export type QueryParamsType = Record<string | number, any>;
1010

@@ -126,7 +126,7 @@ export class HttpClient<SecurityDataType = unknown> {
126126
headers: {
127127
...(requestParams.headers || {}),
128128
...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}),
129-
...({ "Accept-Language": currentLanguage.replace("_", "-") })
129+
...{ "Accept-Language": apiLanguage }
130130
},
131131
params: query,
132132
responseType: responseFormat,

0 commit comments

Comments
 (0)