Skip to content

Commit

Permalink
feat: 设置增加 jsDelivr 加速开关
Browse files Browse the repository at this point in the history
  • Loading branch information
codexu committed Dec 24, 2024
1 parent 5173308 commit e6ad1ff
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

NoteGen 是一个基于 Tauri + ChatGPT 的免费开源笔记 App,旨在帮助用户以**截图**、插图、文本的记录方式,快捷的保存碎片化知识,通过 AI 自动整理为一篇可读的笔记,通过内置的 Markdown 编辑器将 AI 笔记进行二次创作。笔记最终形态以文件存储于本地,同时也支持`同步``图床`功能,其基于 Github 实现,保证数据安全。

![4b0cbac8-dacd-4334-8b5b-7446728248c8.png](https://fastly.jsdelivr.net/gh/codexu/note-gen-image-sync@main/4b0cbac8-dacd-4334-8b5b-7446728248c8.png)
![4b0cbac8-dacd-4334-8b5b-7446728248c8.png](https://cdn.jsdelivr.net/gh/codexu/note-gen-image-sync@main/4b0cbac8-dacd-4334-8b5b-7446728248c8.png)

## 下载

Expand Down Expand Up @@ -68,7 +68,7 @@ flowchart LR

支持截图、插图和文本的多种记录方式,用户可以根据不同场景灵活选择最适合的记录形式。借助 ChatGPT 的强大功能,您无需担心记录的顺序和完整性,轻松捕捉灵感与信息,提升记录效率。

![b8df1739-09db-4f0f-bc6d-6b322f7f6f95.jpg](https://fastly.jsdelivr.net/gh/codexu/note-gen-image-sync@main/b8df1739-09db-4f0f-bc6d-6b322f7f6f95.jpg)
![b8df1739-09db-4f0f-bc6d-6b322f7f6f95.jpg](https://cdn.jsdelivr.net/gh/codexu/note-gen-image-sync@main/b8df1739-09db-4f0f-bc6d-6b322f7f6f95.jpg)

**记录方式**

Expand Down Expand Up @@ -96,7 +96,7 @@ flowchart LR

写作模式是基于文件管理器和 Markdown 编辑器组合实现的,即使你不使用记录功能,它也可以完全独立使用。

![35370027-b170-497a-8b91-d788824183ff.jpg](https://fastly.jsdelivr.net/gh/codexu/note-gen-image-sync@main/35370027-b170-497a-8b91-d788824183ff.jpg)
![35370027-b170-497a-8b91-d788824183ff.jpg](https://cdn.jsdelivr.net/gh/codexu/note-gen-image-sync@main/35370027-b170-497a-8b91-d788824183ff.jpg)

**文件管理器**

Expand Down
9 changes: 6 additions & 3 deletions src/app/core/article/md-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function MdEditor() {
const { currentArticle, setCurrentArticle , saveCurrentArticle, activeFilePath } = useArticleStore()
const [mdTheme, setMdTheme] = useState<Themes>('light')
const { theme } = useTheme()
const { codeTheme, previewTheme, githubUsername } = useSettingStore()
const { codeTheme, previewTheme, githubUsername, jsdelivr } = useSettingStore()
const [toolbar, setToolbar] = useState<ToolbarNames[]>([])

async function handleSave(value: string) {
Expand Down Expand Up @@ -47,8 +47,11 @@ export function MdEditor() {
file: fileBase64,
repo: RepoNames.image
}).then(async res => {
await fetch(`https://purge.jsdelivr.net/gh/${githubUsername}/${RepoNames.image}@main/${res?.data.content.name}`)
const url = `https://fastly.jsdelivr.net/gh/${githubUsername}/${RepoNames.image}@main/${res?.data.content.name}`
let url = res?.data.content.download_url
if (jsdelivr) {
await fetch(`https://purge.jsdelivr.net/gh/${githubUsername}/${RepoNames.image}@main/${res?.data.content.name}`)
url = `https://cdn.jsdelivr.net/gh/${githubUsername}/${RepoNames.image}@main/${res?.data.content.name}`
}
resolve(url)
}).catch(err => {
reject(err)
Expand Down
6 changes: 3 additions & 3 deletions src/app/core/image/image-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ export function ImageCard({file}: {file: GithubFile}) {
}

async function handleCopyLink() {
const fileLink = `https://fastly.jsdelivr.net/gh/${githubUsername}/${RepoNames.image}@main/${file.name}`
const fileLink = `https://cdn.jsdelivr.net/gh/${githubUsername}/${RepoNames.image}@main/${file.name}`
navigator.clipboard.writeText(fileLink)
toast({ title: '已复制 URL 到剪切板', description: fileLink })
}

async function handleCopyMarkdown() {
const fileLink = `![${file.name}](https://fastly.jsdelivr.net/gh/${githubUsername}/${RepoNames.image}@main/${file.name})`
const fileLink = `![${file.name}](https://cdn.jsdelivr.net/gh/${githubUsername}/${RepoNames.image}@main/${file.name})`
navigator.clipboard.writeText(fileLink)
toast({ title: '已复制 Markdown 到剪切板', description: fileLink })
}

async function handleCopyHTML() {
const fileLink = `<img src="https://fastly.jsdelivr.net/gh/${githubUsername}/${RepoNames.image}@main/${file.name}" />`
const fileLink = `<img src="https://cdn.jsdelivr.net/gh/${githubUsername}/${RepoNames.image}@main/${file.name}" />`
navigator.clipboard.writeText(fileLink)
toast({ title: '已复制 HTML 到剪切板', description: fileLink })
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/note/mark/control-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function ControlImage() {
if (res) {
setQueue(queueId, { progress: '通知 jsdelivr 缓存' });
await fetch(`https://purge.jsdelivr.net/gh/${githubUsername}/${RepoNames.image}@main/${res.data.content.name}`)
mark.url = `https://fastly.jsdelivr.net/gh/${githubUsername}/${RepoNames.image}@main/${res.data.content.name}`
mark.url = `https://cdn.jsdelivr.net/gh/${githubUsername}/${RepoNames.image}@main/${res.data.content.name}`
} else {
mark.url = filename
}
Expand Down
10 changes: 10 additions & 0 deletions src/app/core/setting/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ export const config = [
layout: 'vertical',
type: 'input',
},
{
title: 'jsDelivr 加速',
key: 'jsdelivr',
value: true,
desc: <>开启后,将使用 jsDelivr 加速图床,图片链接将替换为 jsDelivr 的链接,否则将使用 raw.githubusercontent.com。</>,
schema: z.boolean(),
disabled: false,
layout: 'horizontal',
type: 'switch',
},
],
},
{
Expand Down
6 changes: 6 additions & 0 deletions src/stores/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ interface SettingState {

accessToken: string
setAccessToken: (accessToken: string) => void

jsdelivr: boolean
setJsdelivr: (jsdelivr: boolean) => void
}


Expand Down Expand Up @@ -106,6 +109,9 @@ const useSettingStore = create<SettingState>((set, get) => ({

accessToken: '',
setAccessToken: (accessToken: string) => set({ accessToken }),

jsdelivr: true,
setJsdelivr: (jsdelivr: boolean) => set({ jsdelivr }),
}))

export default useSettingStore

0 comments on commit e6ad1ff

Please sign in to comment.