proto-ocr

This commit is contained in:
catto 2024-04-21 17:45:08 +02:00
parent 75eb5301fd
commit d4b4bd9363
2 changed files with 20 additions and 13 deletions

View File

@ -21,6 +21,11 @@ pub fn init_db() -> Result<()> {
date TEXT NOT NULL,
tag TEXT
);
CREATE TABLE IF NOT EXISTS favourites (
fid INTEGER PRIMARY KEY AUTOINCREMENT,
nid INTEGER NOT NULL,
FOREIGN KEY (nid) REFERENCES notes (nid) ON DELETE CASCADE
);
";
match connection.execute(query_table, []) {

View File

@ -200,30 +200,32 @@ window.addEventListener("DOMContentLoaded", async () => {
// OCR
const uploadOcrImageButtonEl = document.getElementById('image-button') as HTMLButtonElement;
const ocrFileInputEl = document.getElementById('fileInput') as HTMLInputElement;
uploadOcrImageButtonEl.addEventListener('click', () => {
ocrFileInputEl.click(); // Simulate click on the file input
});
ocrFileInputEl.addEventListener('change', (event) => {
ocrFileInputEl.addEventListener('change', async (event) => {
const files = (event.target as HTMLInputElement).files;
if (files) {
console.log('Selected file:', files[0].name);
ocrFileInputEl.src = URL.createObjectURL(files[0]);
(async () => {
// TODO: change ocr language in settings
const worker = await createWorker('eng');
const ret = await worker.recognize(files[0]);
console.log(ret.data.text);
if (createNoteContentEl) [
createNoteContentEl.value += ret.data.text
]
await worker.terminate();
})();
// Assuming you have an img element to display the selected file
const imageDisplayEl = document.getElementById('imageDisplay') as HTMLImageElement;
if (imageDisplayEl) {
imageDisplayEl.src = URL.createObjectURL(files[0]);
}
const worker = await createWorker('eng');
const ret = await worker.recognize(files[0]);
console.log(ret.data.text);
if (createNoteContentEl) {
createNoteContentEl.value += ret.data.text;
}
await worker.terminate();
}
});
refreshContextMenuElements();
});