@@ -5,13 +5,13 @@ import { PageModel } from '../models/page-model';
55import { PostsListState } from '../models/posts-list-state' ;
66import { PostEditDto } from '../models/post-edit-dto' ;
77import { PostUpdatedResponse } from '../models/post-updated-response' ;
8- import { throwIfNotOkGotResponse , throwIfNotOkResponse } from '../utils/throw-if-not-ok-response' ;
8+ import { throwIfNotOkResponse } from '../utils/throw-if-not-ok-response' ;
99import { IErrorResponse } from '../models/error-response' ;
1010import { AlertService } from './alert.service' ;
1111import { PostFileMapManager } from './post-file-map' ;
1212import { ZzkSearchResult } from '../models/zzk-search-result' ;
13- import httpClient , { Options , got } from '@/utils/http-client' ;
14- import iconv from 'iconv-lite ' ;
13+ import got from '@/utils/http-client' ;
14+ import httpClient from '@/utils/http-client ' ;
1515
1616const defaultPageSize = 30 ;
1717let newPostTemplate : PostEditDto | undefined ;
@@ -74,31 +74,29 @@ export class PostService {
7474 // responseType: 'buffer',
7575 // });
7676
77- // const response = await got(`${this._baseUrl}/api/posts/${postId}`);
78- 79- // try {
80- // throwIfNotOkGotResponse(response);
81- // } catch (ex) {
82- // const { statusCode, errors } = ex as IErrorResponse;
83- // if (!muteErrorNotification) {
84- // if (statusCode === 404) {
85- // AlertService.error('博文不存在');
86- // const postFilePath = PostFileMapManager.getFilePath(postId);
87- // if (postFilePath) await PostFileMapManager.updateOrCreate(postId, '');
88- // } else {
89- // AlertService.error(errors.join('\n'));
90- // }
91- // }
92- // return undefined;
93- // }
94- 95- // const decodedBody = iconv.decode(response.rawBody, 'utf-8');
96- 97- // const { blogPost, myConfig } = JSON.parse(decodedBody) as { blogPost?: Post; myConfig?: unknown };
98- 99- // return blogPost ? new PostEditDto(Object.assign(new Post(), blogPost), myConfig) : undefined;
100- await new Promise < string > ( ( ) => undefined ) ;
101- return undefined ;
77+ const response = await httpClient ( `${ this . _baseUrl } /api/posts/${ postId } ` ) ;
78+ 79+ try {
80+ throwIfNotOkResponse ( response ) ;
81+ } catch ( ex ) {
82+ const { statusCode, errors } = ex as IErrorResponse ;
83+ if ( ! muteErrorNotification ) {
84+ if ( statusCode === 404 ) {
85+ AlertService . error ( '博文不存在' ) ;
86+ const postFilePath = PostFileMapManager . getFilePath ( postId ) ;
87+ if ( postFilePath ) await PostFileMapManager . updateOrCreate ( postId , '' ) ;
88+ } else {
89+ AlertService . error ( errors . join ( '\n' ) ) ;
90+ }
91+ }
92+ return undefined ;
93+ }
94+ 95+ const decodedBody = 'test' ; // iconv.decode(response.rawBody, 'utf-8');
96+ 97+ const { blogPost, myConfig } = JSON . parse ( decodedBody ) as { blogPost ?: Post ; myConfig ?: unknown } ;
98+ 99+ return blogPost ? new PostEditDto ( Object . assign ( new Post ( ) , blogPost ) , myConfig ) : undefined ;
102100 }
103101
104102 async deletePost ( postId : number ) {
0 commit comments