@@ -33,10 +33,10 @@ export async function importPages(
33
33
data : ImportedData < boolean > ,
34
34
{ sid, csrf } : ImportInit ,
35
35
) : Promise <
36
- Result < { message : string } , ErrorLike >
36
+ Result < string , ErrorLike >
37
37
> {
38
38
if ( data . pages . length === 0 ) {
39
- return { ok : true , message : "No pages to import." } ;
39
+ return { ok : true , value : "No pages to import." } ;
40
40
}
41
41
42
42
const formData = new FormData ( ) ;
@@ -51,7 +51,7 @@ export async function importPages(
51
51
if ( ! csrf ) {
52
52
const result = await getCSRFToken ( sid ) ;
53
53
if ( ! result . ok ) return result ;
54
- csrf = result . csrfToken ;
54
+ csrf = result . value ;
55
55
}
56
56
57
57
const path = `https://scrapbox.io/api/page-data/import/${ project } .json` ;
@@ -72,17 +72,17 @@ export async function importPages(
72
72
if ( res . status === 503 ) {
73
73
throw makeCustomError ( "ServerError" , "503 Service Unavailable" ) ;
74
74
}
75
- const error = tryToErrorLike ( await res . text ( ) ) ;
76
- if ( ! error ) {
75
+ const value = tryToErrorLike ( await res . text ( ) ) ;
76
+ if ( ! value ) {
77
77
throw makeCustomError (
78
78
"UnexpectedError" ,
79
79
`Unexpected error has occuerd when fetching "${ path } "` ,
80
80
) ;
81
81
}
82
- return { ok : false , ... error } ;
82
+ return { ok : false , value } ;
83
83
}
84
- const result = ( await res . json ( ) ) as { message : string } ;
85
- return { ok : true , ... result } ;
84
+ const { message } = ( await res . json ( ) ) as { message : string } ;
85
+ return { ok : true , value : message } ;
86
86
}
87
87
88
88
/** `exportPages`の認証情報 */
@@ -119,18 +119,22 @@ export async function exportPages<withMetadata extends true | false>(
119
119
return { ok : false , ...error } ;
120
120
}
121
121
if ( ! res . ok ) {
122
- const error = tryToErrorLike ( await res . text ( ) ) ;
123
- if ( ! error ) {
122
+ const value = tryToErrorLike ( await res . text ( ) ) as
123
+ | false
124
+ | NotFoundError
125
+ | NotPrivilegeError
126
+ | NotLoggedInError ;
127
+ if ( ! value ) {
124
128
throw makeCustomError (
125
129
"UnexpectedError" ,
126
130
`Unexpected error has occuerd when fetching "${ path } "` ,
127
131
) ;
128
132
}
129
133
return {
130
134
ok : false ,
131
- ... ( error as NotFoundError | NotPrivilegeError | NotLoggedInError ) ,
135
+ value ,
132
136
} ;
133
137
}
134
- const result = ( await res . json ( ) ) as ExportedData < withMetadata > ;
135
- return { ok : true , ... result } ;
138
+ const value = ( await res . json ( ) ) as ExportedData < withMetadata > ;
139
+ return { ok : true , value } ;
136
140
}
0 commit comments