Skip to content

Commit

Permalink
✨ Feature: add gallery db
Browse files Browse the repository at this point in the history
  • Loading branch information
Molunerfinn committed Jul 27, 2021
1 parent c70c3af commit 6ddd660
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
5 changes: 2 additions & 3 deletions src/main/apis/app/system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from 'electron'
import uploader from 'apis/app/uploader'
import getPicBeds from '~/main/utils/getPicBeds'
import db from '~/main/apis/core/datastore'
import db, { GalleryDB } from '~/main/apis/core/datastore'
import windowManager from 'apis/app/window/windowManager'
import { IWindowList } from 'apis/app/window/constants'
import picgo from '@core/picgo'
Expand Down Expand Up @@ -221,8 +221,7 @@ export function createTray () {
setTimeout(() => {
notification.show()
}, i * 100)
// FIXME: gallery db
db.insert('uploaded', imgs[i])
await GalleryDB.getInstance().insert(imgs[i])
}
handleCopyUrl(pasteText.join('\n'))
trayWindow.webContents.send('dragFiles', imgs)
Expand Down
6 changes: 3 additions & 3 deletions src/main/apis/app/uploader/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import windowManager from 'apis/app/window/windowManager'
import { IWindowList } from 'apis/app/window/constants'
import uploader from '.'
import pasteTemplate from '#/utils/pasteTemplate'
import db from '~/main/apis/core/datastore'
import db, { GalleryDB } from '~/main/apis/core/datastore'
import { handleCopyUrl } from '~/main/utils/common'
import { handleUrlEncode } from '#/utils/common'
export const uploadClipboardFiles = async (): Promise<string> => {
Expand All @@ -23,7 +23,7 @@ export const uploadClipboardFiles = async (): Promise<string> => {
icon: img[0].imgUrl
})
notification.show()
db.insert('uploaded', img[0])
await GalleryDB.getInstance().insert(img[0])
// trayWindow just be created in mac/windows, not in linux
trayWindow?.webContents?.send('clipboardFiles', [])
trayWindow?.webContents?.send('uploadFiles', img)
Expand Down Expand Up @@ -61,7 +61,7 @@ export const uploadChoosedFiles = async (webContents: WebContents, files: IFileW
setTimeout(() => {
notification.show()
}, i * 100)
db.insert('uploaded', imgs[i])
await GalleryDB.getInstance().insert(imgs[i])
result.push(handleUrlEncode(imgs[i].imgUrl!))
}
handleCopyUrl(pasteText.join('\n'))
Expand Down
4 changes: 0 additions & 4 deletions src/main/apis/core/datastore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ class ConfigStore {
this.db = Datastore(adapter)
this.db._.mixin(LodashId)

if (!this.db.has('uploaded').value()) {
this.db.set('uploaded', []).write()
}

if (!this.db.has('picBed').value()) {
this.db.set('picBed', {
current: 'smms', // deprecated
Expand Down
4 changes: 2 additions & 2 deletions src/main/apis/gui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Notification,
ipcMain
} from 'electron'
import db from '~/main/apis/core/datastore'
import db, { GalleryDB } from '~/main/apis/core/datastore'
import uploader from 'apis/app/uploader'
import pasteTemplate from '#/utils/pasteTemplate'
import { handleCopyUrl } from '~/main/utils/common'
Expand Down Expand Up @@ -88,7 +88,7 @@ class GuiApi implements IGuiApi {
setTimeout(() => {
notification.show()
}, i * 100)
db.insert('uploaded', imgs[i])
await GalleryDB.getInstance().insert(imgs[i])
}
handleCopyUrl(pasteText.join('\n'))
webContents.send('uploadFiles', imgs)
Expand Down
4 changes: 2 additions & 2 deletions src/main/events/ipcList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import windowManager from 'apis/app/window/windowManager'
import { IWindowList } from 'apis/app/window/constants'
import uploader from 'apis/app/uploader'
import pasteTemplate from '#/utils/pasteTemplate'
import db from '~/main/apis/core/datastore'
import db, { GalleryDB } from '~/main/apis/core/datastore'
import server from '~/main/server'
import getPicBeds from '~/main/utils/getPicBeds'
import shortKeyHandler from 'apis/app/shortKey/shortKeyHandler'
Expand Down Expand Up @@ -40,7 +40,7 @@ export default {
icon: img[0].imgUrl
})
notification.show()
db.insert('uploaded', img[0])
await GalleryDB.getInstance().insert(img[0])
trayWindow.webContents.send('clipboardFiles', [])
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents.send('updateGallery')
Expand Down
6 changes: 5 additions & 1 deletion src/renderer/pages/Gallery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,14 @@ export default class extends Vue {
return this.images
.filter(item => {
let isInChoosedPicBed = true
let isIncludesSearchText = true
if (this.choosedPicBed.length > 0) {
isInChoosedPicBed = this.choosedPicBed.some(type => type === item.type)
}
return item.fileName?.includes(this.searchText) && isInChoosedPicBed
if (this.searchText) {
isIncludesSearchText = item.fileName?.includes(this.searchText) || false
}
return isIncludesSearchText && isInChoosedPicBed
})
} else {
return this.images
Expand Down

0 comments on commit 6ddd660

Please sign in to comment.