Skip to content

Commit 5f15dc1

Browse files
authored
fix: create post (#179)
1 parent 33d7836 commit 5f15dc1

File tree

15 files changed

+99
-63
lines changed

15 files changed

+99
-63
lines changed

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
},
165165
{
166166
"command": "vscode-cnb.post.pull-all",
167-
"title": "下载全部随笔",
167+
"title": "下载全部",
168168
"icon": "$(cloud-download)",
169169
"enablement": "vscode-cnb.isAuthed && !vscode-cnb.post.list-view.refreshing && vscode-cnb.post.list-view.pageCount > 0",
170170
"category": "Cnblogs Post List"
@@ -177,8 +177,8 @@
177177
"enablement": "vscode-cnb.isAuthed"
178178
},
179179
{
180-
"command": "vscode-cnb.post.create-local-draft",
181-
"title": "新建本地草稿",
180+
"command": "vscode-cnb.post.create-local",
181+
"title": "新建博文",
182182
"icon": "$(new-file)",
183183
"category": "Cnblogs Local Draft"
184184
},
@@ -322,21 +322,21 @@
322322
},
323323
{
324324
"command": "vscode-cnb.post.search",
325-
"title": "搜索博文",
325+
"title": "搜索",
326326
"category": "Cnblogs",
327327
"icon": "$(vscode-cnb-post-list-search)",
328328
"enablement": "vscode-cnb.isAuthed && !vscode-cnb.post.list-view.refreshing"
329329
},
330330
{
331331
"command": "vscode-cnb.post.list-view.search.clear",
332-
"title": "清除随笔搜索结果",
332+
"title": "清除搜索结果",
333333
"category": "Cnblogs",
334334
"icon": "$(clear-all)",
335335
"enablement": "vscode-cnb.isAuthed && !vscode-cnb.post.list-view.refreshing"
336336
},
337337
{
338338
"command": "vscode-cnb.post.list-view.search.refresh",
339-
"title": "刷新随笔搜索结果",
339+
"title": "刷新搜索结果",
340340
"category": "Cnblogs",
341341
"icon": "$(refresh)",
342342
"enablement": "vscode-cnb.isAuthed && !vscode-cnb.post.list-view-refreshing"
@@ -855,7 +855,7 @@
855855
"group": "navigation@6"
856856
},
857857
{
858-
"command": "vscode-cnb.post.create-local-draft",
858+
"command": "vscode-cnb.post.create-local",
859859
"when": "view == cnblogs-post-list || view == cnblogs-post-list-another",
860860
"group": "navigation@7"
861861
},
@@ -1059,8 +1059,8 @@
10591059
"when": "viewItem =~ /^cnb-post/ && viewItem != cnb-post-category"
10601060
},
10611061
{
1062-
"command": "vscode-cnb.post.create-local-draft",
1063-
"when": "viewItem == cnb-local-drafts-folder"
1062+
"command": "vscode-cnb.post.create-local",
1063+
"when": "viewItem == cnb-local-posts-folder"
10641064
},
10651065
{
10661066
"command": "vscode-cnb.post.rename",

rs/src/cnb/ing/comment.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use reqwest::header::CONTENT_TYPE;
1010
use serde::{Deserialize, Serialize};
1111
use wasm_bindgen::prelude::*;
1212

13-
#[allow(non_camel_case_types)]
1413
#[serde_with::skip_serializing_none]
1514
#[derive(Serialize, Deserialize, Debug, Default)]
1615
struct Body {

rs/src/cnb/post/get_template.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use crate::cnb::post::PostReq;
2+
use crate::http::body_or_err;
3+
use crate::infra::http::setup_auth;
4+
use crate::infra::result::{HomoResult, ResultExt};
5+
use crate::{blog_backend, panic_hook};
6+
use alloc::format;
7+
use alloc::string::String;
8+
use anyhow::Result;
9+
use wasm_bindgen::prelude::*;
10+
11+
#[wasm_bindgen(js_class = PostReq)]
12+
impl PostReq {
13+
#[wasm_bindgen(js_name = getTemplate)]
14+
pub async fn export_get_template(&self) -> HomoResult<String> {
15+
panic_hook!();
16+
let url = blog_backend!("/posts/-1");
17+
18+
let client = reqwest::Client::new().get(url);
19+
20+
let req = setup_auth(client, &self.token, self.is_pat_token);
21+
22+
let result: Result<String> = try {
23+
let resp = req.send().await?;
24+
body_or_err(resp).await?
25+
};
26+
27+
result.homo_string()
28+
}
29+
}

rs/src/cnb/post/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod del_some;
33
mod get_count;
44
mod get_list;
55
mod get_one;
6+
mod get_template;
67
mod update;
78

89
use crate::panic_hook;

rs/src/cnb/user/get_info.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use crate::cnb::user::{UserReq, API_BASE_URL};
1+
use crate::cnb::user::UserReq;
22
use crate::http::body_or_err;
33
use crate::infra::http::setup_auth;
44
use crate::infra::result::{HomoResult, ResultExt};
5-
use crate::panic_hook;
5+
use crate::{openapi, panic_hook};
66
use alloc::format;
77
use alloc::string::String;
88
use anyhow::Result;
@@ -13,7 +13,7 @@ impl UserReq {
1313
#[wasm_bindgen(js_name = getInfo)]
1414
pub async fn export_get_info(&self) -> HomoResult<String> {
1515
panic_hook!();
16-
let url = format!("{}/users", API_BASE_URL);
16+
let url = openapi!("/users");
1717

1818
let client = reqwest::Client::new().get(url);
1919

rs/src/cnb/user/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ use crate::panic_hook;
44
use alloc::string::{String, ToString};
55
use wasm_bindgen::prelude::*;
66

7-
pub(crate) const API_BASE_URL: &str = "https://api.cnblogs.com/api";
8-
97
#[wasm_bindgen(js_name = UserReq)]
108
pub struct UserReq {
119
token: String,

rs/src/infra/log.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ extern "C" {
88

99
#[macro_export]
1010
macro_rules! console_log {
11-
($text:expr) => {
11+
($expr:expr) => {
1212
use alloc::format;
1313
use $crate::infra::log::log;
14-
let text = format!("{}", $text.to_string());
14+
let text = format!("{:#?}", $expr);
1515
log(&text);
1616
};
1717
}

src/cmd/post-list/create-local-draft.ts renamed to src/cmd/post-list/create-local.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import { osOpenActiveFile } from '@/cmd/open/os-open-active-file'
55
import { openPostFile } from './open-post-file'
66
import { WorkspaceCfg } from '@/ctx/cfg/workspace'
77

8-
export async function createLocalDraft() {
8+
export async function createLocal() {
9+
const dir = WorkspaceCfg.getWorkspaceUri().fsPath.replace(homedir(), '~')
910
let title = await window.showInputBox({
1011
placeHolder: '请输入标题',
11-
prompt: `文件将会保存到 ${WorkspaceCfg.getWorkspaceUri().fsPath.replace(homedir(), '~')} 目录下`,
12-
title: '新建本地草稿',
12+
prompt: `文件将会保存到 ${dir}`,
13+
title: '新建博文',
1314
validateInput: input => {
1415
if (!input) return '标题不能为空'
1516

src/cmd/post-list/modify-post-setting.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { PostFileMapManager } from '@/service/post/post-file-map'
66
import { revealPostListItem } from '@/service/post/post-list-view'
77
import { PostCfgPanel } from '@/service/post/post-cfg-panel'
88
import fs from 'fs'
9-
import { LocalDraft } from '@/service/local-draft'
9+
import { LocalPost } from '@/service/local-post'
1010
import { saveFilePendingChanges } from '@/infra/save-file-pending-changes'
1111
import { postDataProvider } from '@/tree-view/provider/post-data-provider'
1212
import { PostTreeItem } from '@/tree-view/model/post-tree-item'
@@ -48,7 +48,7 @@ export async function modifyPostSetting(input: Post | PostTreeItem | Uri) {
4848
beforeUpdate: async post => {
4949
if (localFilePath && fs.existsSync(localFilePath)) {
5050
await saveFilePendingChanges(localFilePath)
51-
post.postBody = await new LocalDraft(localFilePath).readAllText()
51+
post.postBody = await new LocalPost(localFilePath).readAllText()
5252
}
5353
return true
5454
},

src/cmd/post-list/open-post-file.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { TextDocumentShowOptions, Uri } from 'vscode'
22
import { execCmd } from '@/infra/cmd'
33
import { Post } from '@/model/post'
4-
import { LocalDraft } from '@/service/local-draft'
54
import { PostFileMapManager } from '@/service/post/post-file-map'
5+
import { LocalPost } from '@/service/local-post'
66

7-
export async function openPostFile(post: LocalDraft | Post | string, options?: TextDocumentShowOptions) {
7+
export async function openPostFile(post: LocalPost | Post | string, options?: TextDocumentShowOptions) {
88
let filePath = ''
9-
if (post instanceof LocalDraft) filePath = post.filePath
9+
if (post instanceof LocalPost) filePath = post.filePath
1010
else if (post instanceof Post) filePath = PostFileMapManager.getFilePath(post.id) ?? ''
1111
else filePath = post
1212

0 commit comments

Comments
 (0)