@@ -9,7 +9,7 @@ import { AbstractWordPressClient } from './abstract-wp-client';
99import WordpressPlugin from './main' ;
1010import { Term } from './wp-api' ;
1111import { RestClient } from './rest-client' ;
12- import { isFunction , isString , template } from 'lodash-es' ;
12+ import { isArray , isFunction , isString , template } from 'lodash-es' ;
1313import { SafeAny } from './utils' ;
1414import { WpProfile } from './wp-profile' ;
1515
@@ -103,7 +103,22 @@ export class WpRestClient extends AbstractWordPressClient {
103103 {
104104 headers : this . context . getHeaders ( certificate )
105105 } )
106- . then ( data => data as Term [ ] ?? [ ] ) ;
106+ . then ( data => {
107+ if ( isArray ( data ) ) {
108+ return data as Term [ ] ?? [ ] ;
109+ } else {
110+ if ( ( data as SafeAny ) . hasOwnProperty ( 'found' ) ) {
111+ // returns by wordpress.com
112+ return ( data as SafeAny )
113+ . categories
114+ . map ( ( it : Term & { ID : number } ) => ( {
115+ ...it ,
116+ id : String ( it . ID )
117+ } ) ) ;
118+ }
119+ }
120+ return [ ] ;
121+ } ) ;
107122 }
108123
109124 validateUser ( certificate : WordPressAuthParams ) : Promise < WordPressClientResult > {
@@ -134,9 +149,22 @@ export class WpRestClient extends AbstractWordPressClient {
134149 name
135150 } ) ,
136151 )
137- . then ( ( resp : SafeAny ) => {
138- console . log ( 'WpRestClient getTags response' , resp ) ;
139- return resp as Term [ ] ?? [ ] ;
152+ . then ( ( data : SafeAny ) => {
153+ console . log ( 'WpRestClient getTags response' , data ) ;
154+ if ( isArray ( data ) ) {
155+ return data as Term [ ] ?? [ ] ;
156+ } else {
157+ if ( ( data as SafeAny ) . hasOwnProperty ( 'found' ) ) {
158+ // returns by wordpress.com
159+ return ( data as SafeAny )
160+ . tags
161+ . map ( ( it : Term & { ID : number } ) => ( {
162+ ...it ,
163+ id : String ( it . ID )
164+ } ) ) ;
165+ }
166+ }
167+ return [ ] ;
140168 } ) ;
141169 if ( exists . length === 0 ) {
142170 return await this . client . httpPost (
@@ -149,7 +177,10 @@ export class WpRestClient extends AbstractWordPressClient {
149177 } )
150178 . then ( ( resp : SafeAny ) => {
151179 console . log ( 'WpRestClient newTag response' , resp ) ;
152- return resp ;
180+ return {
181+ ...resp ,
182+ id : resp . id ?? resp . ID
183+ } ;
153184 } ) ;
154185 } else {
155186 return exists [ 0 ] ;
@@ -198,7 +229,6 @@ interface WpRestClientContext {
198229
199230 getHeaders ( wp : WordPressAuthParams ) : Record < string , string > ;
200231
201-
202232}
203233
204234export class WpRestClientMiniOrangeContext implements WpRestClientContext {
0 commit comments