#58 - PDF Indexing ok on mobile
This commit is contained in:
@@ -48,7 +48,8 @@
|
|||||||
"lodash-es": "4.17.21",
|
"lodash-es": "4.17.21",
|
||||||
"minisearch": "5.0.0",
|
"minisearch": "5.0.0",
|
||||||
"p-queue-compat": "1.0.187",
|
"p-queue-compat": "1.0.187",
|
||||||
"pako": "^2.0.4"
|
"pako": "^2.0.4",
|
||||||
|
"pure-md5": "^0.1.14"
|
||||||
},
|
},
|
||||||
"pnpm": {
|
"pnpm": {
|
||||||
"overrides": {
|
"overrides": {
|
||||||
|
|||||||
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
@@ -26,6 +26,7 @@ specifiers:
|
|||||||
pako: ^2.0.4
|
pako: ^2.0.4
|
||||||
prettier: ^2.7.1
|
prettier: ^2.7.1
|
||||||
prettier-plugin-svelte: ^2.8.0
|
prettier-plugin-svelte: ^2.8.0
|
||||||
|
pure-md5: ^0.1.14
|
||||||
rollup: ^2.79.1
|
rollup: ^2.79.1
|
||||||
rollup-plugin-base64: ^1.0.1
|
rollup-plugin-base64: ^1.0.1
|
||||||
rollup-plugin-copy: ^3.4.0
|
rollup-plugin-copy: ^3.4.0
|
||||||
@@ -44,6 +45,7 @@ dependencies:
|
|||||||
minisearch: 5.0.0
|
minisearch: 5.0.0
|
||||||
p-queue-compat: 1.0.187
|
p-queue-compat: 1.0.187
|
||||||
pako: 2.0.4
|
pako: 2.0.4
|
||||||
|
pure-md5: 0.1.14
|
||||||
|
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@babel/preset-env': 7.19.4
|
'@babel/preset-env': 7.19.4
|
||||||
@@ -4066,6 +4068,10 @@ packages:
|
|||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/pure-md5/0.1.14:
|
||||||
|
resolution: {integrity: sha512-tQ/inCmpbggbJRgJESzyhAj8weRANMMgYvBtVcqDHfTXR88fgU/Ff7YQHm8dGrcenCxkjas10SmbaFROcp2kZQ==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/querystringify/2.2.0:
|
/querystringify/2.2.0:
|
||||||
resolution: {integrity: sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==}
|
resolution: {integrity: sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==}
|
||||||
dev: true
|
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 pdfCacheFilePath = `${app.vault.configDir}/plugins/omnisearch/pdfCache.data`
|
||||||
export const historyFilePath = `${app.vault.configDir}/plugins/omnisearch/historyCache.json`
|
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 = {
|
export const EventNames = {
|
||||||
ToggleExcerpts: 'toggle-excerpts',
|
ToggleExcerpts: 'toggle-excerpts',
|
||||||
} as const
|
} as const
|
||||||
|
|||||||
@@ -2,12 +2,7 @@ import { Notice, Plugin, TFile } from 'obsidian'
|
|||||||
import * as Search from './search'
|
import * as Search from './search'
|
||||||
import { OmnisearchInFileModal, OmnisearchVaultModal } from './modals'
|
import { OmnisearchInFileModal, OmnisearchVaultModal } from './modals'
|
||||||
import { loadSettings, settings, SettingsTab, showExcerpt } from './settings'
|
import { loadSettings, settings, SettingsTab, showExcerpt } from './settings'
|
||||||
import {
|
import { eventBus, EventNames } from './globals'
|
||||||
eventBus,
|
|
||||||
EventNames,
|
|
||||||
oldNnotesCacheFilePath,
|
|
||||||
oldSearchIndexFilePath,
|
|
||||||
} from './globals'
|
|
||||||
import { registerAPI } from '@vanakat/plugin-api'
|
import { registerAPI } from '@vanakat/plugin-api'
|
||||||
import api from './api'
|
import api from './api'
|
||||||
import { loadSearchHistory } from './search-history'
|
import { loadSearchHistory } from './search-history'
|
||||||
@@ -107,11 +102,13 @@ export default class OmnisearchPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function cleanOldCacheFiles() {
|
async function cleanOldCacheFiles() {
|
||||||
|
const oldSearchIndexFilePath = `${app.vault.configDir}/plugins/omnisearch/searchIndex.json`
|
||||||
if (await app.vault.adapter.exists(oldSearchIndexFilePath)) {
|
if (await app.vault.adapter.exists(oldSearchIndexFilePath)) {
|
||||||
try {
|
try {
|
||||||
await app.vault.adapter.remove(oldSearchIndexFilePath)
|
await app.vault.adapter.remove(oldSearchIndexFilePath)
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
|
const oldNnotesCacheFilePath = `${app.vault.configDir}/plugins/omnisearch/notesCache.json`
|
||||||
if (await app.vault.adapter.exists(oldNnotesCacheFilePath)) {
|
if (await app.vault.adapter.exists(oldNnotesCacheFilePath)) {
|
||||||
try {
|
try {
|
||||||
await app.vault.adapter.remove(oldNnotesCacheFilePath)
|
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 PDFWorker from 'web-worker:./pdf-worker.ts'
|
||||||
import { pdfCacheFilePath } from './globals'
|
import { pdfCacheFilePath } from './globals'
|
||||||
import { deflate, inflate } from 'pako'
|
import { deflate, inflate } from 'pako'
|
||||||
import { md5 } from './utils'
|
import { makeMD5 } from './utils'
|
||||||
|
|
||||||
class PDFManager {
|
class PDFManager {
|
||||||
private cache: Map<string, { content: string }> = new Map()
|
private cache: Map<string, { content: string }> = new Map()
|
||||||
@@ -24,7 +24,7 @@ class PDFManager {
|
|||||||
|
|
||||||
public async getPdfText(file: TFile): Promise<string> {
|
public async getPdfText(file: TFile): Promise<string> {
|
||||||
const data = new Uint8Array(await app.vault.readBinary(file))
|
const data = new Uint8Array(await app.vault.readBinary(file))
|
||||||
const hash = md5(data)
|
const hash = makeMD5(data)
|
||||||
if (this.cache.has(hash)) {
|
if (this.cache.has(hash)) {
|
||||||
return this.cache.get(hash)!.content
|
return this.cache.get(hash)!.content
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,7 +174,6 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// PDF Indexing - not available on mobile
|
// PDF Indexing - not available on mobile
|
||||||
if (!Platform.isMobileApp) {
|
|
||||||
const indexPDFsDesc = new DocumentFragment()
|
const indexPDFsDesc = new DocumentFragment()
|
||||||
indexPDFsDesc.createSpan({}, span => {
|
indexPDFsDesc.createSpan({}, span => {
|
||||||
span.innerHTML = `Omnisearch will include PDFs in search results.
|
span.innerHTML = `Omnisearch will include PDFs in search results.
|
||||||
@@ -191,7 +190,6 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
await saveSettings(this.plugin)
|
await saveSettings(this.plugin)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
|
||||||
// #endregion Behavior
|
// #endregion Behavior
|
||||||
|
|
||||||
// #region User Interface
|
// #region User Interface
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
} from './globals'
|
} from './globals'
|
||||||
import { settings } from './settings'
|
import { settings } from './settings'
|
||||||
import { createHash, type BinaryLike } from 'crypto'
|
import { createHash, type BinaryLike } from 'crypto'
|
||||||
|
import { md5 } from 'pure-md5'
|
||||||
|
|
||||||
export function highlighter(str: string): string {
|
export function highlighter(str: string): string {
|
||||||
return `<span class="${highlightClass}">${str}</span>`
|
return `<span class="${highlightClass}">${str}</span>`
|
||||||
@@ -192,6 +193,11 @@ export function getExtension(path: string): string {
|
|||||||
return split[split.length - 1]
|
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')
|
return createHash('md5').update(data).digest('hex')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user