Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8ac5f41

Browse files
debug: use default httpClient
1 parent fee8a9e commit 8ac5f41

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

‎src/services/post.service.ts‎

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { PageModel } from '../models/page-model';
55
import { PostsListState } from '../models/posts-list-state';
66
import { PostEditDto } from '../models/post-edit-dto';
77
import { 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';
99
import { IErrorResponse } from '../models/error-response';
1010
import { AlertService } from './alert.service';
1111
import { PostFileMapManager } from './post-file-map';
1212
import { 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

1616
const defaultPageSize = 30;
1717
let 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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /