File tree Expand file tree Collapse file tree 5 files changed +10
-52
lines changed Expand file tree Collapse file tree 5 files changed +10
-52
lines changed Original file line number Diff line number Diff line change @@ -111,10 +111,6 @@ export function useOperationSetSearch({
111
111
const shortCodeContent = parseShortCode ( keyword )
112
112
113
113
if ( shortCodeContent ) {
114
- if ( shortCodeContent . type === 'operation' ) {
115
- throw new Error ( '该神秘代码属于作业,无法在此使用⊙﹏⊙∥' )
116
- }
117
-
118
114
id = shortCodeContent . id
119
115
}
120
116
}
Original file line number Diff line number Diff line change @@ -59,21 +59,11 @@ export function useOperations({
59
59
}
60
60
61
61
if ( content ) {
62
- let error : string | undefined
63
-
64
- if ( content . type === 'operationSet' ) {
65
- error = '该神秘代码属于作业集,无法在此使用⊙﹏⊙∥'
66
- }
67
-
68
62
return [
69
63
'operations' ,
70
64
{
71
65
copilotIds : [ content . id ] ,
72
66
} satisfies QueriesCopilotRequest ,
73
-
74
- // 如果直接抛出 error 的话,useSWRInfinite 会把这个 error 吞掉,所以传到 fetcher 里再抛出
75
- // https://github.com/vercel/swr/issues/2102
76
- error ,
77
67
]
78
68
}
79
69
}
@@ -93,11 +83,7 @@ export function useOperations({
93
83
} satisfies QueriesCopilotRequest ,
94
84
]
95
85
} ,
96
- async ( [ , req , error ] ) => {
97
- if ( error ) {
98
- throw new Error ( error )
99
- }
100
-
86
+ async ( [ , req ] ) => {
101
87
// 如果指定了 id 列表,但是列表为空,就直接返回空数据。不然要是直接传空列表,就相当于没有这个参数,
102
88
// 会导致后端返回所有数据
103
89
if ( req . copilotIds ?. length === 0 ) {
Original file line number Diff line number Diff line change @@ -47,12 +47,7 @@ export const ShortCodeImporter: FC<{
47
47
throw new Error ( '无效的神秘代码' )
48
48
}
49
49
50
- const { type, id } = shortCodeContent
51
-
52
- if ( type === 'operationSet' ) {
53
- throw new Error ( '该神秘代码属于作业集,无法在此使用⊙﹏⊙∥' )
54
- }
55
-
50
+ const { id } = shortCodeContent
56
51
const operationContent = ( await getOperation ( { id } ) ) . parsedContent
57
52
58
53
if ( operationContent === INVALID_OPERATION_CONTENT ) {
Original file line number Diff line number Diff line change 1
1
/*
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.
4
5
*/
5
6
6
7
const shortCodeScheme = 'maa://'
7
8
8
9
export interface ShortCodeContent {
9
10
id : number
10
- type : 'operation' | 'operationSet'
11
11
}
12
12
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
20
15
}
21
16
22
17
export function parseShortCode ( code : string ) : ShortCodeContent | null {
23
18
if ( code . startsWith ( shortCodeScheme ) ) {
24
19
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 ,
37
22
}
38
23
39
24
if ( ! isNaN ( content . id ) ) {
Original file line number Diff line number Diff line change @@ -32,14 +32,10 @@ export const handleDownloadJSON = (operationDoc: CopilotDocV1.Operation) => {
32
32
/**
33
33
* @param target - Either an operation or an operation set
34
34
*/
35
- export const copyShortCode = async ( target : {
36
- id : number
37
- copilotIds ?: number [ ]
38
- } ) => {
35
+ export const copyShortCode = async ( target : { id : number } ) => {
39
36
try {
40
37
const content : ShortCodeContent = {
41
38
id : target . id ,
42
- type : target . copilotIds ? 'operationSet' : 'operation' ,
43
39
}
44
40
45
41
const shortCode = toShortCode ( content )
You can’t perform that action at this time.
0 commit comments