1
1
import type {
2
+ ErrorLike ,
2
3
NotFoundError ,
3
4
NotLoggedInError ,
4
5
NotMemberError ,
@@ -12,18 +13,32 @@ import { BaseOptions, Result, setDefaults } from "./util.ts";
12
13
13
14
/** Options for `getPage()` */
14
15
export interface GetPageOption extends BaseOptions {
15
- /** use `followRename` */ followRename ?: boolean ;
16
+ /** use `followRename` */
17
+ followRename ?: boolean ;
18
+
19
+ /** project ids to get External links */
20
+ projects ?: string [ ] ;
21
+ }
22
+
23
+ export interface TooLongURIError extends ErrorLike {
24
+ name : "TooLongURIError" ;
16
25
}
17
26
18
27
const getPage_toRequest : GetPage [ "toRequest" ] = (
19
28
project ,
20
29
title ,
21
30
options ,
22
31
) => {
23
- const { sid, hostName, followRename } = setDefaults ( options ?? { } ) ;
32
+ const { sid, hostName, followRename, projects } = setDefaults ( options ?? { } ) ;
33
+ const params = new URLSearchParams ( ) ;
34
+ params . append ( "followRename" , `${ followRename ?? true } ` ) ;
35
+ for ( const id of projects ?? [ ] ) {
36
+ params . append ( "projects" , id ) ;
37
+ }
24
38
const path = `https://${ hostName } /api/pages/${ project } /${
25
39
encodeTitleURI ( title )
26
- } ?followRename=${ followRename ?? true } `;
40
+ } ?${ params . toString ( ) } `;
41
+
27
42
return new Request (
28
43
path ,
29
44
sid ? { headers : { Cookie : cookie ( sid ) } } : undefined ,
@@ -32,6 +47,15 @@ const getPage_toRequest: GetPage["toRequest"] = (
32
47
33
48
const getPage_fromResponse : GetPage [ "fromResponse" ] = async ( res ) => {
34
49
if ( ! res . ok ) {
50
+ if ( res . status === 414 ) {
51
+ return {
52
+ ok : false ,
53
+ value : {
54
+ name : "TooLongURIError" ,
55
+ message : "project ids may be too much." ,
56
+ } ,
57
+ } ;
58
+ }
35
59
return makeError < NotFoundError | NotLoggedInError | NotMemberError > ( res ) ;
36
60
}
37
61
const value = ( await res . json ( ) ) as Page ;
@@ -60,14 +84,14 @@ export interface GetPage {
60
84
fromResponse : ( res : Response ) => Promise <
61
85
Result <
62
86
Page ,
63
- NotFoundError | NotLoggedInError | NotMemberError
87
+ NotFoundError | NotLoggedInError | NotMemberError | TooLongURIError
64
88
>
65
89
> ;
66
90
67
91
( project : string , title : string , options ?: GetPageOption ) : Promise <
68
92
Result <
69
93
Page ,
70
- NotFoundError | NotLoggedInError | NotMemberError
94
+ NotFoundError | NotLoggedInError | NotMemberError | TooLongURIError
71
95
>
72
96
> ;
73
97
}
0 commit comments