Compare commits

...

1 Commits

Author SHA1 Message Date
catto d4b4bd9363 proto-ocr 2024-04-21 17:45:08 +02:00
2 changed files with 20 additions and 13 deletions

View File

@ -21,6 +21,11 @@ pub fn init_db() -> Result<()> {
date TEXT NOT NULL, date TEXT NOT NULL,
tag TEXT 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, []) { match connection.execute(query_table, []) {

View File

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