@@ -4,7 +4,7 @@ import useSWRInfinite from 'swr/infinite'
4
4
5
5
import { toCopilotOperation } from 'models/converter'
6
6
import { OpRatingType , Operation } from 'models/operation'
7
- import { parseShortCode } from 'models/shortCode'
7
+ import { ShortCodeContent , parseShortCode } from 'models/shortCode'
8
8
import { OperationApi } from 'utils/maa-copilot-client'
9
9
import { useSWRRefresh } from 'utils/swr'
10
10
@@ -48,16 +48,32 @@ export function useOperations({
48
48
return null // reached the end
49
49
}
50
50
51
- // 用户输入 maa://xxxxxx 时 ,只传这个 id,其他参数都不传
51
+ // 用户输入神秘代码时 ,只传这个 id,其他参数都不传
52
52
if ( keyword ) {
53
- const id = parseShortCode ( keyword )
53
+ let content : ShortCodeContent | null = null
54
+
55
+ try {
56
+ content = parseShortCode ( keyword )
57
+ } catch ( e ) {
58
+ console . warn ( e )
59
+ }
60
+
61
+ if ( content ) {
62
+ let error : string | undefined
63
+
64
+ if ( content . type === 'operationSet' ) {
65
+ error = '该神秘代码属于作业集,无法在此使用⊙﹏⊙∥'
66
+ }
54
67
55
- if ( id ) {
56
68
return [
57
69
'operations' ,
58
70
{
59
- copilotIds : [ id ] ,
71
+ copilotIds : [ content . id ] ,
60
72
} satisfies QueriesCopilotRequest ,
73
+
74
+ // 如果直接抛出 error 的话,useSWRInfinite 会把这个 error 吞掉,所以传到 fetcher 里再抛出
75
+ // https://github.com/vercel/swr/issues/2102
76
+ error ,
61
77
]
62
78
}
63
79
}
@@ -77,7 +93,11 @@ export function useOperations({
77
93
} satisfies QueriesCopilotRequest ,
78
94
]
79
95
} ,
80
- async ( [ , req ] ) => {
96
+ async ( [ , req , error ] ) => {
97
+ if ( error ) {
98
+ throw new Error ( error )
99
+ }
100
+
81
101
// 如果指定了 id 列表,但是列表为空,就直接返回空数据。不然要是直接传空列表,就相当于没有这个参数,
82
102
// 会导致后端返回所有数据
83
103
if ( req . copilotIds ?. length === 0 ) {
0 commit comments