Skip to content

Commit

Permalink
Merge pull request #34 from TankNee/rebuild/develop
Browse files Browse the repository at this point in the history
Update v0.0.12
  • Loading branch information
TankNee authored Oct 13, 2020
2 parents 91de894 + 43e8d28 commit 079a501
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src-electron/electron-flag.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// THIS FEATURE-FLAG FILE IS AUTOGENERATED,
// REMOVAL OR CHANGES WILL CAUSE RELATED TYPES TO STOP WORKING
import "quasar/dist/types/feature-flag";
import 'quasar/dist/types/feature-flag'

declare module "quasar/dist/types/feature-flag" {
declare module 'quasar/dist/types/feature-flag' {
interface QuasarFeatureFlags {
electron: true;
electron: true
}
}
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default {
},
methods: {
...mapClientActions(['initClientStore']),
...mapServerActions(['initServerStore']),
...mapServerActions(['initServerStore', 'reLogin']),
...mapServerState(['isLogin'])
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/ScheduleHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import ServerFileStorage from './utils/storage/ServerFileStorage'
const refreshWizToken = (app) => {
schedule.scheduleJob('30 * * * * *', async () => {
if (!ServerFileStorage.isKeyExistsInLocalStorage('token') || !app.isLogin) return
await api.AccountServerApi.keepTokenAlive()
try {
await api.AccountServerApi.keepTokenAlive()
} catch (e) {
await app.reLogin()
}
})
}

Expand Down
8 changes: 7 additions & 1 deletion src/components/Vditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default {
dataLoaded: function () {
return !helper.isNullOrEmpty(this.currentNote)
},
...mapServerGetters(['currentNote', 'uploadImageUrl']),
...mapServerGetters(['currentNote', 'uploadImageUrl', 'currentNoteResources', 'currentNoteResourceUrl']),
...mapServerState(['isCurrentNoteLoading', 'contentsList']),
...mapClientState(['darkMode', 'lightCodeTheme', 'darkCodeTheme'])
},
Expand Down Expand Up @@ -71,6 +71,12 @@ export default {
hljs: {
style: this.$q.dark.isActive ? this.darkCodeTheme : this.lightCodeTheme
}
// transform: (html) => {
// const imgReg = /(<img\s+([^>]*\s+)?(data-src|src)=")index_files(\/[^"]*")/ig
// const newHtml = imgReg.exec(html)
// console.log(newHtml)
// return newHtml
// }
},
upload: {
max: 5 * 1024 * 1024,
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/NoteItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default {
components: { CategoryDialog, NoteItemContextMenu },
computed: {
summary () {
if (helper.isNullOrEmpty(this.data.abstractText)) {
if (helper.isNullOrEmpty(this.data.abstractText) && !helper.isNullOrEmpty(this.data.highlight)) {
const { highlight: { text = [] } } = this.data
const summary = text.join('')
return summary.length > this.maxSummaryLength
Expand Down
2 changes: 1 addition & 1 deletion src/css/vditor.css
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@
word-wrap: break-word;
overflow: auto;
line-height: 28px;
font-size: 16px;
font-size: 19px;
word-break: break-word;
padding-bottom: 30px;
}
Expand Down
45 changes: 38 additions & 7 deletions src/store/server/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ export default {
const localStore = ClientFileStorage.getItemsFromStore(state)
commit(types.INIT, localStore)
ServerFileStorage.removeItemFromLocalStorage('token')
const [autoLogin, userId, password, url] = ClientFileStorage.getItemsFromStore([
const [
autoLogin,
userId,
password,
url
] = ClientFileStorage.getItemsFromStore([
'autoLogin',
'userId',
'password',
Expand Down Expand Up @@ -66,11 +71,33 @@ export default {

return result
},
/**
* 登出
* @param commit
* @returns {Promise<void>}
*/
async logout ({ commit }) {
await api.AccountServerApi.Logout()
ServerFileStorage.removeItemFromLocalStorage('token')
commit(types.LOGOUT)
},
/**
* 重新登录
* @param commit
* @returns {Promise<void>}
*/
async reLogin ({ commit }) {
const [userId, password, url] = ClientFileStorage.getItemsFromStore([
'userId',
'password',
'url'
])
await this.dispatch('server/login', {
userId,
password,
url
})
},
/**
* 获取指定文件夹下的笔记
* @param commit
Expand Down Expand Up @@ -185,9 +212,9 @@ export default {
let { title } = state.currentNote.info
const { resources } = state.currentNote
const isLite = category.replace(/\//g, '') === 'Lite'
const html = helper.embedMDNote(markdown, { wrapWithPreTag: isLite })
const html = helper.embedMDNote(markdown, resources, { wrapWithPreTag: isLite })

const _updateNote = async (title) => {
const _updateNote = async title => {
const result = await api.KnowledgeBaseApi.updateNote({
kbGuid,
docGuid,
Expand All @@ -197,12 +224,15 @@ export default {
kbGuid,
docGuid,
category,
resources,
resources: resources.map(r => r.name),
type: isLite ? 'lite/markdown' : 'document'
}
})

ClientFileStorage.setCachedNote({ info: result, html }, api.KnowledgeBaseApi.getCacheKey(kbGuid, docGuid))
ClientFileStorage.setCachedNote(
{ info: result, html },
api.KnowledgeBaseApi.getCacheKey(kbGuid, docGuid)
)
Notify.create({
color: 'primary',
message: i18n.t('saveNoteSuccessfully'),
Expand Down Expand Up @@ -238,7 +268,7 @@ export default {
* @returns {Promise<void>}
*/
async createNote ({ commit, state, rootState }, title) {
const { kbGuid, currentCategory } = state
const { kbGuid, currentCategory = '' } = state
const userId = ClientFileStorage.getItemFromStore('userId')
const isLite = currentCategory.replace(/\//g, '') === 'Lite'
const result = await api.KnowledgeBaseApi.createNote({
Expand All @@ -248,7 +278,7 @@ export default {
kbGuid,
title,
owner: userId,
html: helper.embedMDNote(`# ${title}`, { wrapWithPreTag: isLite }),
html: helper.embedMDNote(`# ${title}`, [], { wrapWithPreTag: isLite }),
type: isLite ? 'lite/markdown' : 'document'
}
})
Expand Down Expand Up @@ -380,6 +410,7 @@ export default {
getters.imageUrl(result, imageUploadService)
)
}
if (imageUploadService === 'wizOfficialImageUploadService') commit(types.UPDATE_CURRENT_NOTE_RESOURCE, result)
},
async moveNote ({ commit }, noteInfo) {
const { kbGuid, docGuid } = noteInfo
Expand Down
11 changes: 10 additions & 1 deletion src/store/server/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export default {
let img = ''
switch (imageUploadService) {
case 'wizOfficialImageUploadService':
img = docGuid ? `${api.KnowledgeBaseApi.getBaseUrl()}/ks/note/view/${kbGuid}/${docGuid}/${url}` : url
img = url.url
// img = docGuid ? `${api.KnowledgeBaseApi.getBaseUrl()}/ks/note/view/${kbGuid}/${docGuid}/${url.url}` : url
break
case 'smmsImageUploadService':
case 'customWebUploadService':
Expand Down Expand Up @@ -51,6 +52,14 @@ export default {
}
return helper.isNullOrEmpty(result) ? `# ${currentNote.info.title}` : result
},
currentNoteResources: ({ currentNote }) => {
const { resources } = currentNote
return resources
},
currentNoteResourceUrl: ({ currentNote }) => {
const { info: { docGuid, kbGuid } } = currentNote
return `${api.KnowledgeBaseApi.getBaseUrl()}/${kbGuid}/${docGuid}`
},
categories: ({ categories }) => {
return helper.generateCategoryNodeTree(categories)
},
Expand Down
9 changes: 9 additions & 0 deletions src/store/server/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ export default {
}
return state
},
[types.UPDATE_CURRENT_NOTE_RESOURCE] (state, newResource) {
if (state.currentNote && state.currentNote.resources) {
if (Array.isArray(newResource)) {
newResource.forEach(nr => state.currentNote.resources.push({ name: nr.name }))
} else {
state.currentNote.resources.push({ name: newResource.name })
}
}
},
[types.SAVE_TO_LOCAL_STORE_SYNC] (state, [key, value]) {
ClientFileStorage.setItemInStore(key, value)
return state
Expand Down
1 change: 1 addition & 0 deletions src/store/server/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export default {
LOGOUT: 'logout',
UPDATE_CURRENT_NOTES: 'update_current_notes',
UPDATE_CURRENT_NOTE: 'update_current_note',
UPDATE_CURRENT_NOTE_RESOURCE: 'update_current_note_resource',
INIT: 'init',
SAVE_TO_LOCAL_STORE_SYNC: 'save_to_local_store_sync',
UPDATE_ALL_CATEGORIES: 'update_all_categories',
Expand Down
12 changes: 10 additions & 2 deletions src/utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function convertHtml2Markdown (html, kbGuid, docGuid, resources) {
*/
function extractMarkdownFromMDNote (html, kbGuid, docGuid, resources = []) {
resources.forEach(resource => {
html = html.replace(`index_files/${resource.name}`, resource.url)
html = html.replace(new RegExp(`index_files/${resource.name}`, 'g'), resource.url)
})
return wizMarkdownParser.extract(html, {
convertImgTag: true,
Expand All @@ -56,10 +56,18 @@ function extractMarkdownFromMDNote (html, kbGuid, docGuid, resources = []) {
/**
* embed markdown source string to html string
* @param markdown
* @param resources
* @param options
* @returns {string}
*/
function embedMDNote (markdown, options) {
function embedMDNote (markdown, resources, options) {
resources.forEach(resource => {
const imgReg = new RegExp(`!\\[.*\\]\\(${resource.name}\\)`, 'g')
markdown = markdown.replace(resource.url, resource.name)
const result = imgReg.exec(markdown)
console.log(result)
markdown = markdown.replace(imgReg, `![](index_files/${resource.name})`)
})
return wizMarkdownParser.embed(markdown, options)
}

Expand Down
13 changes: 9 additions & 4 deletions src/utils/storage/BaseFileStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ class BaseFileStorage {
}
if (note.info.dataModified === dataModified) {
note.info = info
this.setCachedNote(note, cacheKey)
return note
this.setCachedNote(note, cacheKey, note.cachedDate)
const now = new Date().getTime()
// 没有资源文件的时候直接返回缓存,如果有资源文件但是缓存时间小于三小时的也可以使用缓存
if ((note.resources && note.resources.length === 0) || (note.cachedDate && now - note.cachedDate < 3 * 60 * 60 * 1000)) {
return note
}
} else this.removeItemFromStore(cacheKey)
return null
}
Expand All @@ -90,9 +94,10 @@ class BaseFileStorage {
* 设置笔记缓存
* @param note
* @param cacheKey
* @param {number} cachedDate
*/
setCachedNote (note, cacheKey) {
this.setItemInStore(cacheKey, note)
setCachedNote (note, cacheKey, cachedDate) {
this.setItemInStore(cacheKey, { ...note, cachedDate: cachedDate || new Date().getTime() })
}
}
export default BaseFileStorage
17 changes: 16 additions & 1 deletion src/utils/storage/ServerFileStorage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import BaseFileStorage from 'src/utils/storage/BaseFileStorage'
import Store from 'electron-store'
// import { session } from 'electron'
class ServerFileStorage extends BaseFileStorage {
constructor () {
super()
Expand All @@ -8,6 +9,7 @@ class ServerFileStorage extends BaseFileStorage {
name: 'ServerFileStorage',
encryptionKey: 'server.file.storage'
})
// this._cookie = session.defaultSession.cookies
}

// Chrome LocalStorage
Expand All @@ -16,7 +18,11 @@ class ServerFileStorage extends BaseFileStorage {
}

getValueFromLocalStorage (key) {
return JSON.parse(localStorage.getItem(key))
try {
return JSON.parse(localStorage.getItem(key))
} catch (e) {
return localStorage.getItem(key)
}
}

isKeyExistsInLocalStorage (key) {
Expand All @@ -30,5 +36,14 @@ class ServerFileStorage extends BaseFileStorage {
clearUpLocalStorage () {
return localStorage.clear()
}

/**
* 设置cookie
* @param name
* @param value
*/
setCookie (name, value) {
this._cookie.set({ name, value })
}
}
export default new ServerFileStorage()

0 comments on commit 079a501

Please sign in to comment.