#58 - PDF Indexing ok on mobile
This commit is contained in:
@@ -48,7 +48,8 @@
|
||||
"lodash-es": "4.17.21",
|
||||
"minisearch": "5.0.0",
|
||||
"p-queue-compat": "1.0.187",
|
||||
"pako": "^2.0.4"
|
||||
"pako": "^2.0.4",
|
||||
"pure-md5": "^0.1.14"
|
||||
},
|
||||
"pnpm": {
|
||||
"overrides": {
|
||||
|
||||
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
@@ -26,6 +26,7 @@ specifiers:
|
||||
pako: ^2.0.4
|
||||
prettier: ^2.7.1
|
||||
prettier-plugin-svelte: ^2.8.0
|
||||
pure-md5: ^0.1.14
|
||||
rollup: ^2.79.1
|
||||
rollup-plugin-base64: ^1.0.1
|
||||
rollup-plugin-copy: ^3.4.0
|
||||
@@ -44,6 +45,7 @@ dependencies:
|
||||
minisearch: 5.0.0
|
||||
p-queue-compat: 1.0.187
|
||||
pako: 2.0.4
|
||||
pure-md5: 0.1.14
|
||||
|
||||
devDependencies:
|
||||
'@babel/preset-env': 7.19.4
|
||||
@@ -4066,6 +4068,10 @@ packages:
|
||||
engines: {node: '>=6'}
|
||||
dev: true
|
||||
|
||||
/pure-md5/0.1.14:
|
||||
resolution: {integrity: sha512-tQ/inCmpbggbJRgJESzyhAj8weRANMMgYvBtVcqDHfTXR88fgU/Ff7YQHm8dGrcenCxkjas10SmbaFROcp2kZQ==}
|
||||
dev: false
|
||||
|
||||
/querystringify/2.2.0:
|
||||
resolution: {integrity: sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==}
|
||||
dev: true
|
||||
|
||||
@@ -17,9 +17,6 @@ export const notesCacheFilePath = `${app.vault.configDir}/plugins/omnisearch/not
|
||||
export const pdfCacheFilePath = `${app.vault.configDir}/plugins/omnisearch/pdfCache.data`
|
||||
export const historyFilePath = `${app.vault.configDir}/plugins/omnisearch/historyCache.json`
|
||||
|
||||
export const oldSearchIndexFilePath = `${app.vault.configDir}/plugins/omnisearch/searchIndex.json`
|
||||
export const oldNnotesCacheFilePath = `${app.vault.configDir}/plugins/omnisearch/notesCache.json`
|
||||
|
||||
export const EventNames = {
|
||||
ToggleExcerpts: 'toggle-excerpts',
|
||||
} as const
|
||||
|
||||
@@ -2,12 +2,7 @@ import { Notice, Plugin, TFile } from 'obsidian'
|
||||
import * as Search from './search'
|
||||
import { OmnisearchInFileModal, OmnisearchVaultModal } from './modals'
|
||||
import { loadSettings, settings, SettingsTab, showExcerpt } from './settings'
|
||||
import {
|
||||
eventBus,
|
||||
EventNames,
|
||||
oldNnotesCacheFilePath,
|
||||
oldSearchIndexFilePath,
|
||||
} from './globals'
|
||||
import { eventBus, EventNames } from './globals'
|
||||
import { registerAPI } from '@vanakat/plugin-api'
|
||||
import api from './api'
|
||||
import { loadSearchHistory } from './search-history'
|
||||
@@ -107,11 +102,13 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
}
|
||||
|
||||
async function cleanOldCacheFiles() {
|
||||
const oldSearchIndexFilePath = `${app.vault.configDir}/plugins/omnisearch/searchIndex.json`
|
||||
if (await app.vault.adapter.exists(oldSearchIndexFilePath)) {
|
||||
try {
|
||||
await app.vault.adapter.remove(oldSearchIndexFilePath)
|
||||
} catch (e) {}
|
||||
}
|
||||
const oldNnotesCacheFilePath = `${app.vault.configDir}/plugins/omnisearch/notesCache.json`
|
||||
if (await app.vault.adapter.exists(oldNnotesCacheFilePath)) {
|
||||
try {
|
||||
await app.vault.adapter.remove(oldNnotesCacheFilePath)
|
||||
|
||||
@@ -3,7 +3,7 @@ import PQueue from 'p-queue-compat'
|
||||
import PDFWorker from 'web-worker:./pdf-worker.ts'
|
||||
import { pdfCacheFilePath } from './globals'
|
||||
import { deflate, inflate } from 'pako'
|
||||
import { md5 } from './utils'
|
||||
import { makeMD5 } from './utils'
|
||||
|
||||
class PDFManager {
|
||||
private cache: Map<string, { content: string }> = new Map()
|
||||
@@ -24,7 +24,7 @@ class PDFManager {
|
||||
|
||||
public async getPdfText(file: TFile): Promise<string> {
|
||||
const data = new Uint8Array(await app.vault.readBinary(file))
|
||||
const hash = md5(data)
|
||||
const hash = makeMD5(data)
|
||||
if (this.cache.has(hash)) {
|
||||
return this.cache.get(hash)!.content
|
||||
}
|
||||
|
||||
@@ -174,24 +174,22 @@ export class SettingsTab extends PluginSettingTab {
|
||||
)
|
||||
|
||||
// PDF Indexing - not available on mobile
|
||||
if (!Platform.isMobileApp) {
|
||||
const indexPDFsDesc = new DocumentFragment()
|
||||
indexPDFsDesc.createSpan({}, span => {
|
||||
span.innerHTML = `Omnisearch will include PDFs in search results.
|
||||
const indexPDFsDesc = new DocumentFragment()
|
||||
indexPDFsDesc.createSpan({}, span => {
|
||||
span.innerHTML = `Omnisearch will include PDFs in search results.
|
||||
This feature is currently a work-in-progress, please report slowdowns or issues that you might experience.<br>
|
||||
Each PDF can take a few seconds to be indexed, so it may not appear immediately in search results.<br>
|
||||
<strong style="color: var(--text-accent)">Needs a restart to fully take effect.</strong>`
|
||||
})
|
||||
new Setting(containerEl)
|
||||
.setName('BETA - PDF Indexing')
|
||||
.setDesc(indexPDFsDesc)
|
||||
.addToggle(toggle =>
|
||||
toggle.setValue(settings.PDFIndexing).onChange(async v => {
|
||||
settings.PDFIndexing = v
|
||||
await saveSettings(this.plugin)
|
||||
})
|
||||
)
|
||||
}
|
||||
})
|
||||
new Setting(containerEl)
|
||||
.setName('BETA - PDF Indexing')
|
||||
.setDesc(indexPDFsDesc)
|
||||
.addToggle(toggle =>
|
||||
toggle.setValue(settings.PDFIndexing).onChange(async v => {
|
||||
settings.PDFIndexing = v
|
||||
await saveSettings(this.plugin)
|
||||
})
|
||||
)
|
||||
// #endregion Behavior
|
||||
|
||||
// #region User Interface
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
} from './globals'
|
||||
import { settings } from './settings'
|
||||
import { createHash, type BinaryLike } from 'crypto'
|
||||
import { md5 } from 'pure-md5'
|
||||
|
||||
export function highlighter(str: string): string {
|
||||
return `<span class="${highlightClass}">${str}</span>`
|
||||
@@ -192,6 +193,11 @@ export function getExtension(path: string): string {
|
||||
return split[split.length - 1]
|
||||
}
|
||||
|
||||
export function md5(data: BinaryLike): string {
|
||||
export function makeMD5(data: BinaryLike): string {
|
||||
if (Platform.isMobileApp) {
|
||||
// A node-less implementation, but since we're not hashing the same data
|
||||
// (arrayBuffer vs stringified array) the hash will be different
|
||||
return md5(data.toString())
|
||||
}
|
||||
return createHash('md5').update(data).digest('hex')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user