Skip to content

Commit 6ca64ea

Browse files
committed
feat: tcp endpoints
1 parent c5a37ec commit 6ca64ea

File tree

7 files changed

+103
-40
lines changed

7 files changed

+103
-40
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@
2121
npm-debug.log*
2222
yarn-debug.log*
2323
yarn-error.log*
24+
25+
.vscode

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schema/fragment.gql

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ fragment Endpoint on Endpoint {
33
port
44
}
55

6-
fragment LabWithoutEndpoint on Lab {
6+
fragment LabWithEndpoint on Lab {
77
id
8-
endpoints {
8+
wsEndpoints {
9+
...Endpoint
10+
}
11+
tcpEndpoints {
912
...Endpoint
1013
}
1114
resources {
@@ -19,7 +22,7 @@ fragment LabCategory on LabCategory {
1922
...Translation
2023
}
2124
labs {
22-
...LabWithoutEndpoint
25+
...LabWithEndpoint
2326
}
2427
}
2528

@@ -33,7 +36,10 @@ fragment LabInstance on LabInstance {
3336
lang
3437
name
3538
content
36-
endpoints {
39+
wsEndpoints {
40+
...Endpoint
41+
}
42+
tcpEndpoints {
3743
...Endpoint
3844
}
3945
}

schema/schema.gql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ type Endpoint {
88

99
type Lab {
1010
id: String!
11-
endpoints: [Endpoint!]!
11+
wsEndpoints: [Endpoint!]!
12+
tcpEndpoints: [Endpoint!]!
1213
resources: [ResourceWithTranslation!]!
1314
}
1415

@@ -22,7 +23,8 @@ type LabInstance {
2223
lang: String!
2324
name: String!
2425
content: String!
25-
endpoints: [Endpoint!]!
26+
wsEndpoints: [Endpoint!]!
27+
tcpEndpoints: [Endpoint!]!
2628
}
2729

2830
type Practice {

src/generated/graphql.tsx

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import * as ApolloReactCommon from '@apollo/client';
33
import * as ApolloReactHooks from '@apollo/client';
44
export type Maybe<T> = T | null;
55
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
6+
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
7+
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
8+
const defaultOptions = {}
69
/** All built-in and custom scalars, mapped to their actual values */
710
export type Scalars = {
811
ID: string;
@@ -22,7 +25,8 @@ export type Endpoint = {
2225
export type Lab = {
2326
__typename?: 'Lab';
2427
id: Scalars['String'];
25-
endpoints: Array<Endpoint>;
28+
wsEndpoints: Array<Endpoint>;
29+
tcpEndpoints: Array<Endpoint>;
2630
resources: Array<ResourceWithTranslation>;
2731
};
2832

@@ -38,11 +42,12 @@ export type LabInstance = {
3842
lang: Scalars['String'];
3943
name: Scalars['String'];
4044
content: Scalars['String'];
41-
endpoints: Array<Endpoint>;
45+
wsEndpoints: Array<Endpoint>;
46+
tcpEndpoints: Array<Endpoint>;
4247
};
4348

4449
export type Practice = {
45-
__typename?: 'nav.practice';
50+
__typename?: 'Practice';
4651
labCategories: Array<LabCategory>;
4752
};
4853

@@ -77,10 +82,13 @@ export type EndpointFragment = (
7782
& Pick<Endpoint, 'host' | 'port'>
7883
);
7984

80-
export type LabWithoutEndpointFragment = (
85+
export type LabWithEndpointFragment = (
8186
{ __typename?: 'Lab' }
8287
& Pick<Lab, 'id'>
83-
& { endpoints: Array<(
88+
& { wsEndpoints: Array<(
89+
{ __typename?: 'Endpoint' }
90+
& EndpointFragment
91+
)>, tcpEndpoints: Array<(
8492
{ __typename?: 'Endpoint' }
8593
& EndpointFragment
8694
)>, resources: Array<(
@@ -97,12 +105,12 @@ export type LabCategoryFragment = (
97105
& TranslationFragment
98106
)>, labs: Array<(
99107
{ __typename?: 'Lab' }
100-
& LabWithoutEndpointFragment
108+
& LabWithEndpointFragment
101109
)> }
102110
);
103111

104112
export type PracticeFragment = (
105-
{ __typename?: 'nav.practice' }
113+
{ __typename?: 'Practice' }
106114
& { labCategories: Array<(
107115
{ __typename?: 'LabCategory' }
108116
& LabCategoryFragment
@@ -112,7 +120,10 @@ export type PracticeFragment = (
112120
export type LabInstanceFragment = (
113121
{ __typename?: 'LabInstance' }
114122
& Pick<LabInstance, 'lang' | 'name' | 'content'>
115-
& { endpoints: Array<(
123+
& { wsEndpoints: Array<(
124+
{ __typename?: 'Endpoint' }
125+
& EndpointFragment
126+
)>, tcpEndpoints: Array<(
116127
{ __typename?: 'Endpoint' }
117128
& EndpointFragment
118129
)> }
@@ -142,7 +153,7 @@ export type PracticesQueryVariables = Exact<{ [key: string]: never; }>;
142153
export type PracticesQuery = (
143154
{ __typename?: 'Query' }
144155
& { practice: (
145-
{ __typename?: 'nav.practice' }
156+
{ __typename?: 'Practice' }
146157
& PracticeFragment
147158
) }
148159
);
@@ -180,10 +191,13 @@ export const ResourceWithTranslationFragmentDoc = gql`
180191
name
181192
}
182193
`;
183-
export const LabWithoutEndpointFragmentDoc = gql`
184-
fragment LabWithoutEndpoint on Lab {
194+
export const LabWithEndpointFragmentDoc = gql`
195+
fragment LabWithEndpoint on Lab {
185196
id
186-
endpoints {
197+
wsEndpoints {
198+
...Endpoint
199+
}
200+
tcpEndpoints {
187201
...Endpoint
188202
}
189203
resources {
@@ -199,11 +213,11 @@ export const LabCategoryFragmentDoc = gql`
199213
...Translation
200214
}
201215
labs {
202-
...LabWithoutEndpoint
216+
...LabWithEndpoint
203217
}
204218
}
205219
${TranslationFragmentDoc}
206-
${LabWithoutEndpointFragmentDoc}`;
220+
${LabWithEndpointFragmentDoc}`;
207221
export const PracticeFragmentDoc = gql`
208222
fragment Practice on Practice {
209223
labCategories {
@@ -216,7 +230,10 @@ export const LabInstanceFragmentDoc = gql`
216230
lang
217231
name
218232
content
219-
endpoints {
233+
wsEndpoints {
234+
...Endpoint
235+
}
236+
tcpEndpoints {
220237
...Endpoint
221238
}
222239
}
@@ -243,10 +260,12 @@ export const HelloDocument = gql`
243260
* });
244261
*/
245262
export function useHelloQuery(baseOptions?: ApolloReactHooks.QueryHookOptions<HelloQuery, HelloQueryVariables>) {
246-
return ApolloReactHooks.useQuery<HelloQuery, HelloQueryVariables>(HelloDocument, baseOptions);
263+
const options = {...defaultOptions, ...baseOptions}
264+
return ApolloReactHooks.useQuery<HelloQuery, HelloQueryVariables>(HelloDocument, options);
247265
}
248266
export function useHelloLazyQuery(baseOptions?: ApolloReactHooks.LazyQueryHookOptions<HelloQuery, HelloQueryVariables>) {
249-
return ApolloReactHooks.useLazyQuery<HelloQuery, HelloQueryVariables>(HelloDocument, baseOptions);
267+
const options = {...defaultOptions, ...baseOptions}
268+
return ApolloReactHooks.useLazyQuery<HelloQuery, HelloQueryVariables>(HelloDocument, options);
250269
}
251270
export type HelloQueryHookResult = ReturnType<typeof useHelloQuery>;
252271
export type HelloLazyQueryHookResult = ReturnType<typeof useHelloLazyQuery>;
@@ -275,10 +294,12 @@ export const PracticesDocument = gql`
275294
* });
276295
*/
277296
export function usePracticesQuery(baseOptions?: ApolloReactHooks.QueryHookOptions<PracticesQuery, PracticesQueryVariables>) {
278-
return ApolloReactHooks.useQuery<PracticesQuery, PracticesQueryVariables>(PracticesDocument, baseOptions);
297+
const options = {...defaultOptions, ...baseOptions}
298+
return ApolloReactHooks.useQuery<PracticesQuery, PracticesQueryVariables>(PracticesDocument, options);
279299
}
280300
export function usePracticesLazyQuery(baseOptions?: ApolloReactHooks.LazyQueryHookOptions<PracticesQuery, PracticesQueryVariables>) {
281-
return ApolloReactHooks.useLazyQuery<PracticesQuery, PracticesQueryVariables>(PracticesDocument, baseOptions);
301+
const options = {...defaultOptions, ...baseOptions}
302+
return ApolloReactHooks.useLazyQuery<PracticesQuery, PracticesQueryVariables>(PracticesDocument, options);
282303
}
283304
export type PracticesQueryHookResult = ReturnType<typeof usePracticesQuery>;
284305
export type PracticesLazyQueryHookResult = ReturnType<typeof usePracticesLazyQuery>;
@@ -309,11 +330,13 @@ export const LabDocument = gql`
309330
* },
310331
* });
311332
*/
312-
export function useLabQuery(baseOptions?: ApolloReactHooks.QueryHookOptions<LabQuery, LabQueryVariables>) {
313-
return ApolloReactHooks.useQuery<LabQuery, LabQueryVariables>(LabDocument, baseOptions);
333+
export function useLabQuery(baseOptions: ApolloReactHooks.QueryHookOptions<LabQuery, LabQueryVariables>) {
334+
const options = {...defaultOptions, ...baseOptions}
335+
return ApolloReactHooks.useQuery<LabQuery, LabQueryVariables>(LabDocument, options);
314336
}
315337
export function useLabLazyQuery(baseOptions?: ApolloReactHooks.LazyQueryHookOptions<LabQuery, LabQueryVariables>) {
316-
return ApolloReactHooks.useLazyQuery<LabQuery, LabQueryVariables>(LabDocument, baseOptions);
338+
const options = {...defaultOptions, ...baseOptions}
339+
return ApolloReactHooks.useLazyQuery<LabQuery, LabQueryVariables>(LabDocument, options);
317340
}
318341
export type LabQueryHookResult = ReturnType<typeof useLabQuery>;
319342
export type LabLazyQueryHookResult = ReturnType<typeof useLabLazyQuery>;

src/i18n/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ i18n
1515
resources: {
1616
'en-US': {
1717
translations: {
18+
'quote': ': ',
1819
'nav': {
1920
'home': 'Cryptography Learning Platform',
2021
'tutorial': 'Tutorial',
@@ -51,7 +52,8 @@ i18n
5152
'etc-contact': 'You really can give a help hand at [email protected].'
5253
},
5354
'lab': {
54-
'endpoint': 'Endpoint ',
55+
'ws_endpoint': 'Web Endpoint ',
56+
'tcp_endpoint': 'Raw TCP Endpoint ',
5557
'clear': 'Clear'
5658
},
5759
'wip': 'Work In Progress',
@@ -63,6 +65,7 @@ i18n
6365
},
6466
'zh-CN': {
6567
translations: {
68+
'quote': ':',
6669
'nav': {
6770
'home': '密码学学习平台',
6871
'tutorial': '教程',
@@ -100,7 +103,8 @@ i18n
100103
},
101104
'wip': '施工中',
102105
'lab': {
103-
'endpoint': '服务器 ',
106+
'ws_endpoint': '网页节点 ',
107+
'tcp_endpoint': 'TCP节点 ',
104108
'clear': '关闭所有'
105109
},
106110
i18n: {

src/pages/practice/Lab.tsx

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import { useApolloData } from 'hooks/common'
33
import { useTranslation } from 'react-i18next'
44
import { Endpoint, useLabQuery } from 'generated/graphql'
5-
import { Button, Card, H3, Intent } from '@blueprintjs/core'
5+
import { Button, Card, H3, H4, Intent } from '@blueprintjs/core'
66
import { useRouteMatch } from 'react-router-dom'
77
import { Markdown } from 'components/Markdown'
88
import styled from '@emotion/styled/macro'
@@ -35,12 +35,24 @@ const Container = styled.div`
3535
const BlockWrapper = styled(Card)`
3636
margin-top: 20px;
3737
`
38-
const EndpointContainer = styled(BlockWrapper)`
38+
const WSEndpointContainer = styled(BlockWrapper)`
3939
display: flex;
4040
flex-flow: row wrap;
4141
align-items: center;
4242
justify-content: space-around;
4343
`
44+
const TCPEndpointsContainer = styled(BlockWrapper)`
45+
display: flex;
46+
flex-flow: column wrap;
47+
align-items: center;
48+
justify-content: space-around;
49+
`
50+
51+
const TCPEndpointWrapper = styled(Div)`
52+
display: flex;
53+
align-items: center;
54+
`
55+
4456
interface Match {
4557
category: string
4658
lab: string
@@ -60,25 +72,39 @@ export const Page: React.FC = () => {
6072
const [ terminals, setTermianls ] = useState<Endpoint[]>([])
6173

6274
const content = useApolloData(query, (data) => {
63-
const endpoints = data.lab.endpoints
75+
const wsEndpoints = data.lab.wsEndpoints
76+
const tcpEndpoints = data.lab.tcpEndpoints
6477
return <>
6578
<Markdown source={data.lab.content}></Markdown>
6679
{
67-
!!endpoints.length && <EndpointContainer>
80+
!!tcpEndpoints.length && <TCPEndpointsContainer>
81+
{
82+
tcpEndpoints.map((endpoint, id) => {
83+
const source = `\`\`\` bash\nnc ${endpoint.host} ${endpoint.port}\n\`\`\``
84+
return <TCPEndpointWrapper key={id}>
85+
<H4>{t('lab.tcp_endpoint') + id.toString() + t('quote')}</H4>
86+
<Markdown source={source} key={id}></Markdown>
87+
</TCPEndpointWrapper>
88+
})
89+
}
90+
</TCPEndpointsContainer>
91+
}
92+
{
93+
!!wsEndpoints.length && <WSEndpointContainer>
6894
{
69-
endpoints.map((endpoint, id) => {
95+
wsEndpoints.map((endpoint, id) => {
7096
const onClick = () => {
7197
if(terminals.find(term => term === endpoint)) {
7298
setTermianls(terminals.filter(term => term !== endpoint))
7399
} else {
74100
setTermianls(terminals.concat([endpoint]))
75101
}
76102
}
77-
return <Button key={id} onClick={onClick}intent={Intent.PRIMARY} outlined={true}>{t('lab.endpoint') + id.toString()}</Button>
103+
return <Button key={id} onClick={onClick}intent={Intent.PRIMARY} outlined={true}>{t('lab.ws_endpoint') + id.toString()}</Button>
78104
})
79105
}
80106
<Button onClick={() => setTermianls([])} intent={Intent.DANGER} outlined={true}>{t('lab.clear')}</Button>
81-
</EndpointContainer>
107+
</WSEndpointContainer>
82108
}
83109
</>
84110
})

0 commit comments

Comments
 (0)