Skip to content

Commit 1dfe1a4

Browse files
authored
refactor: create post ux (#180)
1 parent 5f15dc1 commit 1dfe1a4

File tree

106 files changed

+1107
-1611
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1107
-1611
lines changed

.eslintrc.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
"endOfLine": "auto",
1616
"semi": false
1717
}
18+
],
19+
"@typescript-eslint/strict-boolean-expressions": [
20+
"error",
21+
{
22+
"allowString": false,
23+
"allowNumber": false,
24+
"allowNullableObject": false,
25+
"allowNullableBoolean": false
26+
}
1827
]
1928
},
2029
"ignorePatterns": [

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@
177177
"enablement": "vscode-cnb.isAuthed"
178178
},
179179
{
180-
"command": "vscode-cnb.post.create-local",
180+
"command": "vscode-cnb.post.create",
181181
"title": "新建博文",
182182
"icon": "$(new-file)",
183183
"category": "Cnblogs Local Draft"
@@ -855,7 +855,7 @@
855855
"group": "navigation@6"
856856
},
857857
{
858-
"command": "vscode-cnb.post.create-local",
858+
"command": "vscode-cnb.post.create",
859859
"when": "view == cnblogs-post-list || view == cnblogs-post-list-another",
860860
"group": "navigation@7"
861861
},
@@ -1059,7 +1059,7 @@
10591059
"when": "viewItem =~ /^cnb-post/ && viewItem != cnb-post-category"
10601060
},
10611061
{
1062-
"command": "vscode-cnb.post.create-local",
1062+
"command": "vscode-cnb.post.create",
10631063
"when": "viewItem == cnb-local-posts-folder"
10641064
},
10651065
{

rs/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rs/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ serde-wasm-bindgen = "0.5.0"
3030
serde_with = "3.1.0"
3131

3232
reqwest = { version = "0.11.16", features = ["json"] }
33+
34+
lazy_static = "1.4.0"

rs/src/cnb/ing/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
mod comment;
22
mod get_comment;
33
mod get_list;
4-
mod r#pub;
4+
mod publish;
55

66
use crate::panic_hook;
77
use alloc::string::{String, ToString};
8+
use lazy_static::lazy_static;
9+
use regex::Regex;
810
use wasm_bindgen::prelude::*;
911

1012
#[wasm_bindgen(js_name = IngReq)]
@@ -24,3 +26,13 @@ impl IngReq {
2426
}
2527
}
2628
}
29+
30+
#[wasm_bindgen(js_name = ingStarIconToText)]
31+
pub fn ing_star_tag_to_text(icon: &str) -> String {
32+
lazy_static! {
33+
static ref REGEX: Regex = Regex::new(r#"<img.*alt="\[(.*?)]".*>"#).unwrap();
34+
}
35+
let caps = REGEX.captures(icon).unwrap();
36+
let star_text = caps.get(1).unwrap().as_str();
37+
star_text.to_string()
38+
}

rs/src/cnb/ing/pub.rs renamed to rs/src/cnb/ing/publish.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use wasm_bindgen::prelude::*;
1111

1212
#[wasm_bindgen(js_class = IngReq)]
1313
impl IngReq {
14-
#[wasm_bindgen(js_name = pub)]
15-
pub async fn export_pub(&self, content: &str, is_private: bool) -> Result<(), String> {
14+
#[wasm_bindgen(js_name = publish)]
15+
pub async fn export_publish(&self, content: &str, is_private: bool) -> Result<(), String> {
1616
panic_hook!();
1717
let url = openapi!("/statuses");
1818

src/auth/auth-manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ authProvider.onDidChangeSessions(async ({ added }) => {
1919
await AuthManager.updateAuthStatus()
2020

2121
accountViewDataProvider.fireTreeDataChangedEvent()
22-
postDataProvider.fireTreeDataChangedEvent(undefined)
22+
postDataProvider.fireTreeDataChangedEvent()
2323
postCategoryDataProvider.fireTreeDataChangedEvent()
2424

25-
BlogExportProvider.optionalInstance?.refreshRecords({ force: false, clearCache: true }).catch(console.warn)
25+
await BlogExportProvider.optionalInstance?.refreshRecords({ force: false, clearCache: true })
2626
})
2727

2828
export namespace AuthManager {

src/auth/auth-session.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class AuthSession implements CodeAuthSession {
1515

1616
const accessTokenPart2 = this.accessToken.split('.')[1]
1717
const buf = Buffer.from(accessTokenPart2, 'base64')
18-
return (<{ exp: number }>JSON.parse(buf.toString())).exp
18+
const exp = <number>JSON.parse(buf.toString()).exp
19+
return exp * 1000 < Date.now()
1920
}
2021
}

src/cmd/blog-export/delete.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,13 @@ export async function deleteBlogExport(input: unknown): Promise<void> {
2121
function confirm(
2222
itemName: string,
2323
hasLocalFile = true,
24-
detail: string | undefined | null = '数据可能无法恢复, 请谨慎操作!'
24+
detail: string
2525
): Thenable<null | { shouldDeleteLocal: boolean } | undefined> {
2626
const options = [
2727
{ title: '确定' + (hasLocalFile ? '(保留本地文件)' : ''), result: { shouldDeleteLocal: false } },
2828
...(hasLocalFile ? [{ title: '确定(同时删除本地文件)', result: { shouldDeleteLocal: true } }] : []),
2929
]
30-
return Alert.info(
31-
`确定要删除 ${itemName} 吗?`,
32-
{ modal: true, detail: detail ? detail : undefined },
33-
...options
34-
).then(
30+
return Alert.info(`确定要删除 ${itemName} 吗?`, { modal: true, detail }, ...options).then(
3531
x => x?.result,
3632
() => undefined
3733
)
@@ -66,14 +62,12 @@ async function deleteExportRecordItem(item: BlogExportRecordTreeItem) {
6662
void Alert.err(`删除博客备份失败: ${<string>e}`)
6763
return false
6864
})
69-
if (hasDeleted) if (downloaded) await removeDownloadedBlogExport(downloaded, { shouldDeleteLocal })
65+
if (hasDeleted) if (downloaded !== undefined) await removeDownloadedBlogExport(downloaded, { shouldDeleteLocal })
7066

7167
await BlogExportProvider.optionalInstance?.refreshRecords()
7268
}
7369

7470
async function removeDownloadedBlogExport(downloaded: DownloadedBlogExport, { shouldDeleteLocal = false }) {
75-
await DownloadedExportStore.remove(downloaded, { shouldRemoveExportRecordMap: shouldDeleteLocal }).catch(
76-
console.warn
77-
)
78-
if (shouldDeleteLocal) await promisify(fs.rm)(downloaded.filePath).catch(console.warn)
71+
await DownloadedExportStore.remove(downloaded, { shouldRemoveExportRecordMap: shouldDeleteLocal })
72+
if (shouldDeleteLocal) await promisify(fs.rm)(downloaded.filePath)
7973
}

src/cmd/blog-export/download.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import path from 'path'
1111
import { promisify } from 'util'
1212
import { execCmd } from '@/infra/cmd'
1313
import { WorkspaceCfg } from '@/ctx/cfg/workspace'
14+
import AdmZip from 'adm-zip'
1415

1516
function parseInput(input: unknown): BlogExportRecordTreeItem | null | undefined {
1617
return input instanceof BlogExportRecordTreeItem ? input : null
@@ -37,8 +38,8 @@ export async function downloadBlogExport(input: unknown) {
3738
const { optionalInstance: blogExportProvider } = BlogExportProvider
3839
await setIsDownloading(true)
3940

40-
const onError = (msg?: string | null) => {
41-
if (msg) void Alert.warn(msg)
41+
const onError = (msg: string) => {
42+
void Alert.warn(msg)
4243
if (!isFileExist) fs.rmSync(zipFilePath)
4344
blogExportProvider?.refreshItem(treeItem)
4445
setIsDownloading(false).then(undefined, console.warn)
@@ -70,26 +71,19 @@ export async function downloadBlogExport(input: unknown) {
7071
treeItem.reportDownloadingProgress({ percentage: 100, message: '解压中' })
7172
blogExportProvider?.refreshItem(treeItem)
7273

73-
import('adm-zip')
74-
// eslint-disable-next-line @typescript-eslint/naming-convention
75-
.then(({ default: AdmZip }) => {
74+
void (async () => {
75+
try {
7676
const entry = new AdmZip(zipFilePath)
77-
return promisify(entry.extractAllToAsync.bind(entry))(
78-
targetDir,
79-
true,
80-
undefined
81-
).then(() => promisify(fs.rm)(zipFilePath))
82-
})
83-
.then(() => {
84-
DownloadedExportStore.add(nonZipFilePath, exportId)
85-
.then(() => treeItem.reportDownloadingProgress(null))
86-
.then(() => blogExportProvider?.refreshItem(treeItem))
87-
.then(() => blogExportProvider?.refreshDownloadedExports())
88-
.catch(console.warn)
89-
}, console.warn)
90-
.finally(() => {
77+
await promisify(entry.extractAllToAsync.bind(entry))(targetDir, true, undefined)
78+
await promisify(fs.rm)(zipFilePath)
79+
await DownloadedExportStore.add(nonZipFilePath, exportId)
80+
treeItem.reportDownloadingProgress(null)
81+
blogExportProvider?.refreshItem(treeItem)
82+
await blogExportProvider?.refreshDownloadedExports()
83+
} finally {
9184
setIsDownloading(false).then(undefined, console.warn)
92-
})
85+
}
86+
})()
9387
})
9488
)
9589
} else {

0 commit comments

Comments
 (0)