@@ -12,6 +12,9 @@ import { OldTokensConvert, OldTokensResult } from '../../interface_definition/ol
12
12
import { bot } from './bot' ;
13
13
import { TokensConvert , TokensResult } from '../../interface_definition/tokensInteface' ;
14
14
15
+ /**
16
+ *
17
+ */
15
18
export enum InfoType {
16
19
PageTitle = "PageTitle" ,
17
20
PageID = "PageID" ,
@@ -24,22 +27,27 @@ export interface IPageInfos {
24
27
[ key : string ] : string | undefined ;
25
28
}
26
29
27
- export function getContentInfo ( content : string ) : { content : string , info : IPageInfos | null } {
30
+ interface IContentInfo {
31
+ content : string ;
32
+ info ?: IPageInfos ;
33
+ }
34
+
35
+ export function getContentInfo ( content : string ) : IContentInfo {
28
36
const info : string | undefined = content . match ( / (?< = \< % \- \- \s * \[ P A G E _ I N F O \] ) [ \s \S ] * ?(? = \[ E N D _ P A G E _ I N F O \] \s * \- \- % \> ) / ) ?. [ 0 ] ;
29
37
30
- let pageInfo : IPageInfos | null = null ;
38
+ let pageInfo : IPageInfos | undefined = undefined ;
31
39
if ( info ) {
32
40
content = content . replace ( / \< % \- \- \s * \[ P A G E _ I N F O \] [ \s \S ] * ?\[ E N D _ P A G E _ I N F O \] \s * \- \- % \> \s * / , "" ) ;
33
- const foo = ( infoName : string ) : string | undefined => {
41
+ const getInfo = ( infoName : string ) : string | undefined => {
34
42
const reg = new RegExp ( `(?<=${ infoName } \\s*=\\s*#).*?(?=#)` ) ;
35
43
return info . match ( reg ) ?. [ 0 ] ;
36
44
} ;
37
45
pageInfo = {
38
- PageTitle : foo ( InfoType . PageTitle ) ,
39
- PageID : foo ( InfoType . PageID ) ,
40
- RevisionID : foo ( InfoType . RevisionID ) ,
41
- ContentModel : foo ( InfoType . ContentModel ) ,
42
- ContentFormat : foo ( InfoType . ContentFormat )
46
+ PageTitle : getInfo ( InfoType . PageTitle ) ,
47
+ PageID : getInfo ( InfoType . PageID ) ,
48
+ RevisionID : getInfo ( InfoType . RevisionID ) ,
49
+ ContentModel : getInfo ( InfoType . ContentModel ) ,
50
+ ContentFormat : getInfo ( InfoType . ContentFormat )
43
51
} ;
44
52
}
45
53
@@ -55,7 +63,7 @@ export async function writePage(): Promise<void> {
55
63
let args : any ;
56
64
let result : any ;
57
65
let token : string | undefined ;
58
- let errors : any [ ] = [ { } , { } ] ;
66
+ let errors : any [ ] = [ undefined , undefined ] ;
59
67
60
68
try {
61
69
args = {
@@ -74,22 +82,23 @@ export async function writePage(): Promise<void> {
74
82
console . log ( error ) ;
75
83
errors [ 0 ] = error ;
76
84
}
77
-
78
- try {
79
- args = {
80
- 'action' : "tokens" ,
81
- 'type' : "edit"
82
- } ;
83
- result = await bot . request ( args ) ;
84
- const reOld : OldTokensResult = OldTokensConvert . toOldTokensResult ( result ) ;
85
- token = reOld . tokens ?. edittoken ;
86
- if ( token ) {
87
- return token ;
85
+ if ( errors [ 0 ] !== undefined ) {
86
+ try {
87
+ args = {
88
+ 'action' : "tokens" ,
89
+ 'type' : "edit"
90
+ } ;
91
+ result = await bot . request ( args ) ;
92
+ const reOld : OldTokensResult = OldTokensConvert . toOldTokensResult ( result ) ;
93
+ token = reOld . tokens ?. edittoken ;
94
+ if ( token ) {
95
+ return token ;
96
+ }
97
+ }
98
+ catch ( error ) {
99
+ console . log ( error ) ;
100
+ errors [ 1 ] = error ;
88
101
}
89
- }
90
- catch ( error ) {
91
- console . log ( error ) ;
92
- errors [ 1 ] = error ;
93
102
}
94
103
95
104
throw new Error ( `Could not get edit token: NEW: ${ errors [ 0 ] . name } ; OLD: ${ errors [ 1 ] . name } ` ) ;
@@ -106,7 +115,7 @@ export async function writePage(): Promise<void> {
106
115
return undefined ;
107
116
}
108
117
109
- const contentInfo : { content : string , info : IPageInfos | null } = getContentInfo ( wikiContent ) ;
118
+ const contentInfo : IContentInfo = getContentInfo ( wikiContent ) ;
110
119
console . log ( contentInfo ) ;
111
120
112
121
const wikiTitle : string | undefined = await vscode . window . showInputBox ( {
@@ -217,9 +226,9 @@ export async function readPage(): Promise<void> {
217
226
const normalized : Jump | undefined = re . query ?. normalized ?. [ 0 ] ;
218
227
const redirects : Jump | undefined = re . query ?. redirects ?. [ 0 ] ;
219
228
vscode . window . showInformationMessage (
220
- `Opened page "${ page . title } " with Model ${ content ?. contentmodel } .` +
221
- ( normalized ? ` Normalized: " ${ normalized . from } " => " ${ normalized . to } ". ` : "" ) +
222
- ( redirects ? ` Redirect: " ${ redirects . from } " => " ${ redirects . to } " ` : "" )
229
+ `Opened page "${ page . title } " with Model ${ content ?. contentmodel } . ` +
230
+ `Normalized: ${ normalized ? `${ normalized . from } => ${ normalized . to } ` : undefined } . ` +
231
+ `Redirect: ${ redirects ? `${ redirects . from } => ${ redirects . to } ` : undefined } `
223
232
) ;
224
233
225
234
const infoHead : string =
0 commit comments