Skip to content

Commit 7b44676

Browse files
committed
revert: remove new short code format
1 parent 17489ca commit 7b44676

File tree

5 files changed

+10
-52
lines changed

5 files changed

+10
-52
lines changed

src/apis/operation-set.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ export function useOperationSetSearch({
111111
const shortCodeContent = parseShortCode(keyword)
112112

113113
if (shortCodeContent) {
114-
if (shortCodeContent.type === 'operation') {
115-
throw new Error('该神秘代码属于作业,无法在此使用⊙﹏⊙∥')
116-
}
117-
118114
id = shortCodeContent.id
119115
}
120116
}

src/apis/operation.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,11 @@ export function useOperations({
5959
}
6060

6161
if (content) {
62-
let error: string | undefined
63-
64-
if (content.type === 'operationSet') {
65-
error = '该神秘代码属于作业集,无法在此使用⊙﹏⊙∥'
66-
}
67-
6862
return [
6963
'operations',
7064
{
7165
copilotIds: [content.id],
7266
} satisfies QueriesCopilotRequest,
73-
74-
// 如果直接抛出 error 的话,useSWRInfinite 会把这个 error 吞掉,所以传到 fetcher 里再抛出
75-
// https://github.com/vercel/swr/issues/2102
76-
error,
7767
]
7868
}
7969
}
@@ -93,11 +83,7 @@ export function useOperations({
9383
} satisfies QueriesCopilotRequest,
9484
]
9585
},
96-
async ([, req, error]) => {
97-
if (error) {
98-
throw new Error(error)
99-
}
100-
86+
async ([, req]) => {
10187
// 如果指定了 id 列表,但是列表为空,就直接返回空数据。不然要是直接传空列表,就相当于没有这个参数,
10288
// 会导致后端返回所有数据
10389
if (req.copilotIds?.length === 0) {

src/components/editor/source/ShortCodeImporter.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,7 @@ export const ShortCodeImporter: FC<{
4747
throw new Error('无效的神秘代码')
4848
}
4949

50-
const { type, id } = shortCodeContent
51-
52-
if (type === 'operationSet') {
53-
throw new Error('该神秘代码属于作业集,无法在此使用⊙﹏⊙∥')
54-
}
55-
50+
const { id } = shortCodeContent
5651
const operationContent = (await getOperation({ id })).parsedContent
5752

5853
if (operationContent === INVALID_OPERATION_CONTENT) {

src/models/shortCode.ts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,24 @@
11
/*
2-
* operation: maa://123456
3-
* operationSet: maa://c123456
2+
* Format: maa://123456
3+
* Note that operations and operation sets share the same ID space
4+
* and currently there is no way to distinguish them.
45
*/
56

67
const shortCodeScheme = 'maa://'
78

89
export interface ShortCodeContent {
910
id: number
10-
type: 'operation' | 'operationSet'
1111
}
1212

13-
export function toShortCode({ id, type }: ShortCodeContent) {
14-
if (type === 'operation') {
15-
return shortCodeScheme + id
16-
} else if (type === 'operationSet') {
17-
return shortCodeScheme + 'c' + id
18-
}
19-
throw new Error('无效的神秘代码类型')
13+
export function toShortCode({ id }: ShortCodeContent) {
14+
return shortCodeScheme + id
2015
}
2116

2217
export function parseShortCode(code: string): ShortCodeContent | null {
2318
if (code.startsWith(shortCodeScheme)) {
2419
const idStr = code.slice(shortCodeScheme.length)
25-
let content: ShortCodeContent
26-
27-
if (idStr.startsWith('c')) {
28-
content = {
29-
id: +idStr.slice(1),
30-
type: 'operationSet',
31-
}
32-
} else {
33-
content = {
34-
id: +idStr,
35-
type: 'operation',
36-
}
20+
const content: ShortCodeContent = {
21+
id: +idStr,
3722
}
3823

3924
if (!isNaN(content.id)) {

src/services/operation.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,10 @@ export const handleDownloadJSON = (operationDoc: CopilotDocV1.Operation) => {
3232
/**
3333
* @param target - Either an operation or an operation set
3434
*/
35-
export const copyShortCode = async (target: {
36-
id: number
37-
copilotIds?: number[]
38-
}) => {
35+
export const copyShortCode = async (target: { id: number }) => {
3936
try {
4037
const content: ShortCodeContent = {
4138
id: target.id,
42-
type: target.copilotIds ? 'operationSet' : 'operation',
4339
}
4440

4541
const shortCode = toShortCode(content)

0 commit comments

Comments
 (0)