@@ -33,10 +33,10 @@ export async function importPages(
3333 data : ImportedData < boolean > ,
3434 { sid, csrf } : ImportInit ,
3535) : Promise <
36- Result < { message : string } , ErrorLike >
36+ Result < string , ErrorLike >
3737> {
3838 if ( data . pages . length === 0 ) {
39- return { ok : true , message : "No pages to import." } ;
39+ return { ok : true , value : "No pages to import." } ;
4040 }
4141
4242 const formData = new FormData ( ) ;
@@ -51,7 +51,7 @@ export async function importPages(
5151 if ( ! csrf ) {
5252 const result = await getCSRFToken ( sid ) ;
5353 if ( ! result . ok ) return result ;
54- csrf = result . csrfToken ;
54+ csrf = result . value ;
5555 }
5656
5757 const path = `https://scrapbox.io/api/page-data/import/${ project } .json` ;
@@ -72,17 +72,17 @@ export async function importPages(
7272 if ( res . status === 503 ) {
7373 throw makeCustomError ( "ServerError" , "503 Service Unavailable" ) ;
7474 }
75- const error = tryToErrorLike ( await res . text ( ) ) ;
76- if ( ! error ) {
75+ const value = tryToErrorLike ( await res . text ( ) ) ;
76+ if ( ! value ) {
7777 throw makeCustomError (
7878 "UnexpectedError" ,
7979 `Unexpected error has occuerd when fetching "${ path } "` ,
8080 ) ;
8181 }
82- return { ok : false , ... error } ;
82+ return { ok : false , value } ;
8383 }
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 } ;
8686}
8787
8888/** `exportPages`の認証情報 */
@@ -119,18 +119,22 @@ export async function exportPages<withMetadata extends true | false>(
119119 return { ok : false , ...error } ;
120120 }
121121 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 ) {
124128 throw makeCustomError (
125129 "UnexpectedError" ,
126130 `Unexpected error has occuerd when fetching "${ path } "` ,
127131 ) ;
128132 }
129133 return {
130134 ok : false ,
131- ... ( error as NotFoundError | NotPrivilegeError | NotLoggedInError ) ,
135+ value ,
132136 } ;
133137 }
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 } ;
136140}
0 commit comments