Skip to content

Commit

Permalink
moment导出
Browse files Browse the repository at this point in the history
  • Loading branch information
hanaTsuk1 committed Aug 17, 2024
1 parent 2d0f828 commit 8a0f6b8
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"svg.js": "^2.7.1",
"tauri-plugin-shion-history-api": "github:shion-app/history",
"tauri-plugin-shion-watcher-api": "github:shion-app/watcher",
"turndown": "^7.2.0",
"vee-validate": "^4.11.8",
"vue": "^3.4.33",
"vue-component-type-helpers": "^1.8.24",
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion src-tauri/capabilities/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@
"fs:allow-copy-file",
"fs:allow-mkdir",
"fs:allow-write-file",
"fs:allow-write-text-file",
{
"identifier": "fs:allow-write-text-file",
"allow": [
{
"path": "**"
}
]
},
"fs:allow-read-text-file",
{
"identifier": "fs:allow-exists",
Expand All @@ -37,6 +44,14 @@
},
"fs:allow-remove",
"fs:scope-appdata-recursive",
{
"identifier": "fs:allow-rename",
"allow": [
{
"path": "**"
}
]
},
"log:allow-log",
"process:allow-restart",
"process:allow-exit",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/gen/schemas/capabilities.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"main-capability":{"identifier":"main-capability","description":"Capability for the main window","local":true,"windows":["main"],"permissions":["core:path:default","core:event:default","core:window:default","core:window:allow-start-dragging","core:window:allow-hide","core:window:allow-minimize","core:app:default","core:resources:default","core:menu:default","core:tray:default","core:tray:allow-get-by-id","autostart:allow-disable","autostart:allow-enable","autostart:allow-is-enabled","clipboard-manager:allow-write-text","dialog:allow-open","fs:allow-copy-file","fs:allow-mkdir","fs:allow-write-file","fs:allow-write-text-file","fs:allow-read-text-file",{"identifier":"fs:allow-exists","allow":[{"path":"**"}]},"fs:allow-remove","fs:scope-appdata-recursive","log:allow-log","process:allow-restart","process:allow-exit","shell:allow-open","sql:allow-load","sql:allow-select","sql:allow-execute","sql:allow-close","store:allow-length","store:allow-entries","store:allow-set","store:allow-save","updater:default","shion-history:allow-get-config","shion-history:allow-set-config","shion-history:allow-read-history","shion-watcher:allow-resume","shion-watcher:allow-suspend","shion-watcher:allow-get-program-list","shion-watcher:allow-get-program-by-path"]}}
{"main-capability":{"identifier":"main-capability","description":"Capability for the main window","local":true,"windows":["main"],"permissions":["core:path:default","core:event:default","core:window:default","core:window:allow-start-dragging","core:window:allow-hide","core:window:allow-minimize","core:app:default","core:resources:default","core:menu:default","core:tray:default","core:tray:allow-get-by-id","autostart:allow-disable","autostart:allow-enable","autostart:allow-is-enabled","clipboard-manager:allow-write-text","dialog:allow-open","fs:allow-copy-file","fs:allow-mkdir","fs:allow-write-file",{"identifier":"fs:allow-write-text-file","allow":[{"path":"**"}]},"fs:allow-read-text-file",{"identifier":"fs:allow-exists","allow":[{"path":"**"}]},"fs:allow-remove","fs:scope-appdata-recursive",{"identifier":"fs:allow-rename","allow":[{"path":"**"}]},"log:allow-log","process:allow-restart","process:allow-exit","shell:allow-open","sql:allow-load","sql:allow-select","sql:allow-execute","sql:allow-close","store:allow-length","store:allow-entries","store:allow-set","store:allow-save","updater:default","shion-history:allow-get-config","shion-history:allow-set-config","shion-history:allow-read-history","shion-watcher:allow-resume","shion-watcher:allow-suspend","shion-watcher:allow-get-program-list","shion-watcher:allow-get-program-by-path"]}}
2 changes: 2 additions & 0 deletions src/locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ about:
appInfo: copy app info
moment:
create: Record the moment
export: Export all data
inputTitle: Input title...
submit: Submit
edit: Edit
Expand All @@ -162,6 +163,7 @@ moment:
snackbar: Currently in candidate state, select the object that needs to be linked
submitTip: The selected {count} item will be linked to the target. Are you sure?
cancelTip: The link is about to be cancelled. Are you sure?
deprecated: The moment will be redone, please export all data in the more menu at the bottom left
box:
all: All
tip:
Expand Down
2 changes: 2 additions & 0 deletions src/locales/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ about:
appInfo: 复制应用信息
moment:
create: 记录下瞬间
export: 导出所有数据
inputTitle: 输入标题...
submit: 提交
edit: 编辑
Expand All @@ -162,6 +163,7 @@ moment:
snackbar: 正处于链接候选状态, 选中需要链接的对象
submitTip: 所选中{count}项将与目标链接在一起, 是否确认?
cancelTip: 即将取消链接, 是否确认?
deprecated: 瞬间功能将重做,所有数据请在左下方更多菜单中导出
box:
all: 全部
tip:
Expand Down
72 changes: 69 additions & 3 deletions src/pages/record/moment.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<script setup lang="ts">
import { open } from '@tauri-apps/plugin-dialog'
import TurndownService from 'turndown'
import { mkdir, rename, writeTextFile } from '@tauri-apps/plugin-fs'
import { basename, join } from '@tauri-apps/api/path'
import { db } from '@/modules/database'
import type { SelectBox, SelectMoment } from '@/modules/database'
import { useConfirmModal } from '@/hooks/useConfirmModal'
Expand All @@ -21,7 +26,7 @@ type Moment = SelectMoment & {
const { success, error } = useNotify()
const { getI18nMessage, isUniqueError } = useDatabase()
const { t } = useI18n()
const { formatYYYYmmdd } = useDateFns()
const { formatYYYYmmdd, format } = useDateFns()
const route = useRoute()
const confirm = useConfirmModal()
Expand Down Expand Up @@ -258,7 +263,67 @@ async function handleSearch(keyword: string, page: number, size: number) {
}
}
function getAssets(input: string) {
const matches: string[] = []
const regex = /src="http:\/\/asset\.localhost\/([^"]+)"/g
let match = regex.exec(input)
while ((match) !== null) {
matches.push(match[1])
match = regex.exec(input)
}
return matches
}
async function exportData() {
const selected = await open({
directory: true,
})
if (selected) {
const turndownService = new TurndownService()
for (const post of momentList.value) {
const markdownDir = await join(selected, post.box.name)
await mkdir(markdownDir, {
recursive: true,
})
const path = await join(markdownDir, `${post.title}.md`)
const assets = getAssets(post.content).map(decodeURIComponent)
const content = post.content.replace(/src="http:\/\/asset\.localhost\/([^"]+)"/g, (_, path) => {
const p = decodeURIComponent(path)
const name = p.split('\\').pop()
return `src="../assets/${name}"`
})
const markdown = turndownService.turndown(content)
const date
= '---\n'
+ `created: ${format(post.createdAt, 'yyyy/MM/dd HH:mm:ss')}\n`
+ `updated: ${format(post.updatedAt, 'yyyy/MM/dd HH:mm:ss')}\n`
+ '---\n'
await writeTextFile(path, date + markdown)
const assetsDir = await join(selected, 'assets')
await mkdir(assetsDir, {
recursive: true,
})
for (const asset of assets) {
const name = await basename(asset)
const path = await join(assetsDir, name)
await rename(asset, path)
}
}
success({})
}
}
refresh()
onMounted(() => {
confirm.require({
title: t('modal.prompt'),
content: t('moment.deprecated'),
})
})
</script>

<template>
Expand Down Expand Up @@ -321,14 +386,15 @@ refresh()
</v-snackbar>
<more-menu :visible="!linkActive">
<v-list>
<v-list-item
<!-- <v-list-item
v-if="selectedList.length" value="button.remove" :title="$t('button.remove')"
append-icon="mdi-trash-can-outline" base-color="red" @click="openBatchRemoveModal"
/>
<v-list-item
value="moment.create" :title="$t('moment.create')" append-icon="mdi-plus"
@click="viewMomentCreate"
/>
/> -->
<v-list-item value="moment.export" :title="$t('moment.export')" append-icon="mdi-export" @click="exportData" />
</v-list>
</more-menu>
<moment-edit v-model:visible="createDialogVisible" @submit="handleCreate" />
Expand Down
14 changes: 7 additions & 7 deletions src/stores/useNavStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ export const useNavStore = defineStore('nav', () => {
to: '/collection/monitor',
key: 'monitor',
},
{
icon: 'i-mdi:cube-outline',
activeIcon: 'i-mdi:cube',
name: t('nav.box'),
to: '/collection/box',
key: 'box',
},
// {
// icon: 'i-mdi:cube-outline',
// activeIcon: 'i-mdi:cube',
// name: t('nav.box'),
// to: '/collection/box',
// key: 'box',
// },
// {
// icon: 'i-mdi:cloud-outline',
// activeIcon: 'i-mdi:cloud',
Expand Down

0 comments on commit 8a0f6b8

Please sign in to comment.