Skip to content

Commit

Permalink
fix: fix open & fix dir init
Browse files Browse the repository at this point in the history
  • Loading branch information
baicie committed Jan 5, 2024
1 parent e7dd115 commit 6182cbf
Show file tree
Hide file tree
Showing 8 changed files with 650 additions and 455 deletions.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"publish-script": "tsx scripts/publish-script.ts"
},
"devDependencies": {
"@antfu/eslint-config": "0.41.0",
"@antfu/eslint-config": "2.6.1",
"@b-reader/utils": "workspace:^",
"@baicie/commitizen": "^0.1.0",
"@pnpm/find-workspace-packages": "^6.0.9",
Expand All @@ -21,14 +21,14 @@
"@types/lodash": "^4.14.202",
"@types/mime-types": "^2.1.4",
"@types/mocha": "^10.0.6",
"@types/node": "~20.10.5",
"@types/node": "~20.10.6",
"@types/unzipper": "^0.10.9",
"@types/uuid": "^9.0.7",
"@types/vscode": "^1.85.0",
"@types/xml2js": "^0.4.14",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.15.0",
"@vitejs/plugin-vue": "^4.5.2",
"@typescript-eslint/eslint-plugin": "^6.17.0",
"@typescript-eslint/parser": "^6.17.0",
"@vitejs/plugin-vue": "^5.0.2",
"@vitejs/plugin-vue-jsx": "^3.1.0",
"@vscode/test-cli": "^0.0.4",
"@vscode/test-electron": "^2.3.8",
Expand All @@ -38,16 +38,16 @@
"fast-glob": "^3.3.2",
"lodash": "^4.17.21",
"mime-types": "^2.1.35",
"oxlint": "^0.0.21",
"sass": "^1.69.5",
"oxlint": "^0.0.22",
"sass": "^1.69.7",
"semantic-release-vsce": "^5.6.4",
"tsup": "^8.0.1",
"tsx": "^4.7.0",
"turbo": "^1.11.2",
"turbo": "^1.11.3",
"typescript": "^5.3.3",
"vite": "^5.0.10",
"vue": "^3.3.13",
"vue-tsc": "^1.8.26"
"vue": "^3.4.5",
"vue-tsc": "^1.8.27"
},
"version": "0.0.0"
}
16 changes: 12 additions & 4 deletions packages/client/modules/sliderbar/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,26 @@ onBeforeMount(() => {
<template>
<ConfigProvider :locale="locale" :theme="theme" class="flex">
<ButtonGroup :style="{ display: 'flex', flexDirection: 'column' }">
<UploadDragger :show-upload-list="false" :before-upload="(file: any) => beforeUpload(file)" accept=".epub"
:style="{ width: '100%', display: 'block' }">
<UploadDragger
:show-upload-list="false"
:before-upload="(file:any) => beforeUpload(file)"
accept=".epub"
:style="{ width: '100%', display: 'block' }"
>
<Button type="ghost" :style="{ width: '100%' }">
{{ t("menus.add_book") }}
</Button>
</UploadDragger>

<!-- <Button v-dev type="ghost" @click="() => handleOpenLocal(config.bookPath?.path)">
<Button type="ghost" @click="() => handleOpenLocal(config.bookPath?.path)">
打开本地
</Button>

<Button v-dev type="ghost" @click="() => handleOpenLocal(config.globalStorageUri?.path)">
<!-- <Button
v-dev
type="ghost"
@click="() => handleOpenLocal(config.globalStorageUri?.fsPath)"
>
dev
</Button> -->

Expand Down
4 changes: 2 additions & 2 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"@ant-design/icons-vue": "^7.0.1",
"@b-reader/epub": "workspace:^",
"@b-reader/utils": "workspace:^",
"@vueuse/core": "^10.7.0",
"@vueuse/core": "^10.7.1",
"ant-design-vue": "^4.0.8",
"readium-js": "^0.0.0",
"vue": "^3.3.13",
"vue": "^3.4.5",
"vue-i18n": "^9.8.0",
"xml2js": "^0.6.2"
},
Expand Down
41 changes: 12 additions & 29 deletions packages/epub/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'node:path'
import os from 'node:os'
import fs from 'node:fs'
import { get } from 'lodash'
import mime from 'mime-types'
import type { Nav, TocNavPoint } from './types'
Expand Down Expand Up @@ -61,35 +61,18 @@ export function transformNavPoint(nav: TocNavPoint[], parentId: string = 'root')
* @returns
*/
export function resolveId(importer: string, id: string) {
const _importer = normalizePath(importer)
const _id = normalizePath(id)
let res = ''
const bareImportRE = /^(?![a-zA-Z]:)[\w@](?!.*:\/\/)/
if (!(_importer && _id))
res = _id || _importer

else if (_importer.startsWith('/'))
res = path.resolve(path.dirname(_importer), _id)

else if (_importer.startsWith('/') && _id.startsWith('.'))
res = path.resolve(path.dirname(_importer), _id)

else if (_id.startsWith('.'))
res = path.resolve(_importer, _id)

else if (bareImportRE.test(_id) && bareImportRE.test(_importer))
res = path.dirname(_importer) === '.' ? _id : path.resolve(path.dirname(_importer), _id)

else res = _id
if (!(importer && id))
res = id || importer
else if (importer.startsWith('/'))
res = path.resolve(path.dirname(importer), id)
else if (importer.startsWith('/') && id.startsWith('.'))
res = path.resolve(path.dirname(importer), id)
else if (id.startsWith('.'))
res = path.resolve(importer, id)
else if (bareImportRE.test(id) && bareImportRE.test(importer))
res = path.resolve(path.dirname(importer), id)
else res = id
return decodeURIComponent(res)
}

export const isWindows = os.platform() === 'win32'
export function normalizePath(id: string): string {
return path.posix.normalize(isWindows ? slash(id) : id)
}

const windowsSlashRE = /\\/g
export function slash(p: string): string {
return p.replace(windowsSlashRE, '/')
}
17 changes: 6 additions & 11 deletions packages/extension/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function resolveConfig(context: ExtensionContext) {

const database = useDatabase(config)

await database.initDatabase(config)
await initDir(config)

return {
extensionConfig,
Expand All @@ -50,22 +50,17 @@ export async function resolveConfig(context: ExtensionContext) {
}

/**
* @deprecated
* @param config
*/
export function initDir(config: BReaderContext) {
const { dbPath, bookPath } = config
export async function initDir(config: BReaderContext) {
const { dbPath, bookPath, imgPath } = config

const paths = {
dbPath,
bookPath,
imgPath,
}

for (const key of Object.keys(paths)) {
const uri: Uri = paths[key]
const _path = path.resolve(uri.fsPath)

if (!fs.existsSync(_path))
fs.mkdirSync(_path, { recursive: true })
}
for (const key of Object.keys(paths))
await workspace.fs.createDirectory(paths[key])
}
21 changes: 5 additions & 16 deletions packages/extension/src/receive-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import type {
} from '@b-reader/utils'
import type { ExtensionContext, Webview } from 'vscode'
import { commands } from 'vscode'
import open from 'open'
import { parseBook } from './book-parse'
import { Commands, StoreKeys } from './config'
import { useDatabase } from './db'
import { getCacheBook } from './utils/book'
import { openUrl } from './utils/open'
import { writeBook, writeBookInfor } from './utils/read-file'
import { sendMessage, sendMessageToAll } from './utils/send-message'

Expand All @@ -32,13 +32,13 @@ export async function receiveMessage(
case 'openLocal':
if (!message.data)
return
await openUrl(message.data)
await open(message.data, { wait: true })
break
case 'bookInfor':
receiveBookInfor(config, webview)
break
case 'openWebview':
openWebview(message.data, config)
openWebview(message.data)
break
case 'config':
sendMessage(webview, 'config', config)
Expand Down Expand Up @@ -82,19 +82,8 @@ async function receiveBookInfor(config: BReaderContext, webview: Webview) {
await sendMessage(webview, 'bookInfor', res)
}

async function openWebview(data: string, config: BReaderContext) {
const { setValue, getValue } = useDatabase(config)
const bookStore = await getValue<BReaderUser>(StoreKeys.user)

if (bookStore.welcome) {
await commands.executeCommand(Commands.openBookSelefWebView, data)
}
else {
await commands.executeCommand(Commands.openWelcome, data)
await setValue(StoreKeys.user, {
welcome: true,
})
}
async function openWebview(data: string) {
await commands.executeCommand(Commands.openBookSelefWebView, data)
}

async function receiveOpenBook(bookId: string, config: BReaderContext) {
Expand Down
1 change: 0 additions & 1 deletion packages/extension/src/utils/read-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export async function writeBookInfor(book: BookConfig, config: BReaderContext) {
md5: bookid,
img: '',
}
console.log('parse', _book, config);

const result = await parseBook(_book, config)

Expand Down
Loading

0 comments on commit 6182cbf

Please sign in to comment.