1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-06 23:56:13 +02:00

Desktop: Add support for OCR (#8975)

This commit is contained in:
Laurent Cozic
2023-12-13 19:24:58 +00:00
committed by GitHub
parent 0e847685ff
commit bce94f1775
79 changed files with 2381 additions and 445 deletions

View File

@ -1,6 +1,7 @@
import BaseModel from '../BaseModel';
import { SqlQuery } from '../services/database/types';
import { NoteEntity, SqlQuery } from '../services/database/types';
import BaseItem from './BaseItem';
import { LoadOptions } from './utils/types';
// - If is_associated = 1, note_resources indicates which note_id is currently associated with the given resource_id
// - If is_associated = 0, note_resources indicates which note_id *was* associated with the given resource_id
@ -76,6 +77,30 @@ export default class NoteResource extends BaseModel {
return rows.map((r: any) => r.note_id);
}
public static async associatedResourceNotes(resourceIds: string[], options: LoadOptions = null): Promise<Record<string, any>> {
if (!resourceIds.length) return {};
const fields: string[] = options && options.fields ? (options.fields as string[]).slice() : [];
fields.push('resource_id');
fields.push('note_id');
const rows = await this.modelSelectAll(`
SELECT ${this.selectFields({ ...options, fields })}
FROM note_resources
LEFT JOIN notes
ON notes.id = note_resources.note_id
WHERE resource_id IN ("${resourceIds.join('", "')}") AND is_associated = 1
`);
const output: Record<string, NoteEntity[]> = {};
for (const row of rows) {
if (!output[row.resource_id]) output[row.resource_id] = [];
output[row.resource_id].push(row);
}
return output;
}
public static async setAssociatedResources(noteId: string, resourceIds: string[]) {
const existingRows = await this.modelSelectAll('SELECT * FROM note_resources WHERE note_id = ?', [noteId]);