Skip to content

Commit

Permalink
dumili: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
bperel committed Dec 14, 2024
1 parent 422ae82 commit 7dda43f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 26 deletions.
46 changes: 30 additions & 16 deletions apps/dumili/api/services/indexation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,24 +173,30 @@ export default (io: Server) => {
if (entry?.acceptedStoryKind?.kind === STORY) {
const firstPageNumberOfEntry = getEntryPages(indexation, entryId)[0]
.pageNumber;
const ocrResults = (await prisma.page.findUnique({
include: {
image: {
include: {
aiOcrResults: true,
const ocrResults = (
await prisma.page.findUnique({
include: {
image: {
include: {
aiOcrResults: true,
},
},
},
},
where: {
imageId: {
not: null,
},
indexationId_pageNumber: {
indexationId: indexation.id,
pageNumber: firstPageNumberOfEntry,
where: {
imageId: {
not: null,
},
indexationId_pageNumber: {
indexationId: indexation.id,
pageNumber: firstPageNumberOfEntry,
},
},
},
}))!.image!.aiOcrResults;
})
)?.image?.aiOcrResults;

if (!ocrResults) {
throw new Error(`No OCR results found for this entry`);
}

const { results: searchResults } = await coaServices.searchStory(
ocrResults.map(({ text }) => text),
Expand Down Expand Up @@ -295,6 +301,9 @@ export default (io: Server) => {
},
data: {
storyKindSuggestions: {
deleteMany: {
isChosenByAi: true,
},
updateMany: {
data: {
isChosenByAi: true,
Expand Down Expand Up @@ -595,7 +604,11 @@ export default (io: Server) => {
await setInferredEntryStoryKind(entryId);

if (entry?.acceptedStoryKind?.kind === STORY) {
await createStorySuggestions(entryId);
try {
await createStorySuggestions(entryId);
} catch (error) {
console.log((error as { message: string }).message);
}
}
callback({ status: "OK" });
});
Expand Down Expand Up @@ -676,6 +689,7 @@ export default (io: Server) => {
} catch (error) {
callback({
error: error as
| "No OCR results found for this entry"
| "This entry does not have a page URL associated"
| "This entry is not a story",
errorDetails: `Entry ID: ${entryId}`,
Expand Down
1 change: 1 addition & 0 deletions apps/dumili/api/services/indexation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export default abstract class {
data: Errorable<
{ status: "OK" },
| "OCR error"
| "No OCR results found for this entry"
| "This entry is not a story"
| "This entry does not have a page URL associated"
>,
Expand Down
2 changes: 1 addition & 1 deletion apps/dumili/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"bootstrap": "^5.3.3",
"bootstrap-vue-next": "^0.26.11",
"js-cookie": "^3.0.5",
"pinia": "^2.3.0",
"pinia": "^2.2.7",
"sortablejs": "^1.15.6",
"vue": "^3.5.13",
"vue-draggable-resizable": "^3.0.0",
Expand Down
16 changes: 9 additions & 7 deletions apps/dumili/src/components/DumiliBook.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,18 @@ watch(
watch(visiblePages, () => {
for (const pageId of visiblePages.value || []) {
const img = new Image();
const pageIndex = indexation.pages.findIndex(({ id }) => id === pageId);
img.src = indexation.pages[pageIndex].image!.url;
if (indexation.pages[pageIndex].image) {
const img = new Image();
img.src = indexation.pages[pageIndex].image!.url;
img.onload = () => {
pageDimensions.value[indexation.pages[pageIndex].image!.url] = {
width: img.naturalWidth,
height: img.naturalHeight,
img.onload = () => {
pageDimensions.value[indexation.pages[pageIndex].image!.url] = {
width: img.naturalWidth,
height: img.naturalHeight,
};
};
};
}
}
});
Expand Down
6 changes: 4 additions & 2 deletions apps/dumili/src/components/Entry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ defineProps<{
const { indexationSocket } = inject(dumiliSocketInjectionKey)!;
const { indexation } = storeToRefs(suggestions());
const { loadIndexation } = suggestions();
const entry = defineModel<FullEntry>({ required: true });
Expand All @@ -109,15 +110,16 @@ watchDebounced(
entry.value.brokenpagedenominator,
entry.value.title,
]),
() => {
async () => {
const { entirepages, brokenpagenumerator, brokenpagedenominator, title } =
entry.value;
indexationSocket.value!.services.updateEntry(entry.value.id, {
await indexationSocket.value!.services.updateEntry(entry.value.id, {
entirepages,
brokenpagenumerator,
brokenpagedenominator,
title,
});
await loadIndexation();
},
{ debounce: 500, maxWait: 1000 },
);
Expand Down

0 comments on commit 7dda43f

Please sign in to comment.