diff options
Diffstat (limited to 'src/client/views')
| -rw-r--r-- | src/client/views/collections/CollectionCardDeckView.tsx | 72 | ||||
| -rw-r--r-- | src/client/views/collections/collectionSchema/CollectionSchemaView.tsx | 2 | ||||
| -rw-r--r-- | src/client/views/pdf/PDFViewer.tsx | 2 |
3 files changed, 65 insertions, 11 deletions
diff --git a/src/client/views/collections/CollectionCardDeckView.tsx b/src/client/views/collections/CollectionCardDeckView.tsx index 561b9f806..e7e2cba4a 100644 --- a/src/client/views/collections/CollectionCardDeckView.tsx +++ b/src/client/views/collections/CollectionCardDeckView.tsx @@ -18,9 +18,9 @@ import { DocumentType } from '../../documents/DocumentTypes'; import { forEach } from 'lodash'; import { SnappingManager } from '../../util/SnappingManager'; import { List } from '../../../fields/List'; -import { gptAPICall } from '../../apis/gpt/GPT'; +import { gptAPICall, gptImageLabel } from '../../apis/gpt/GPT'; import { GPTCallType } from '../../apis/gpt/GPT'; -import { ImageField } from '../../../fields/URLField'; +import { ImageField, PdfField, URLField } from '../../../fields/URLField'; @observer export class CollectionCardView extends CollectionSubView() { @@ -253,7 +253,7 @@ export class CollectionCardView extends CollectionSubView() { return this.sort(sorted, 'custom', desc); case 'chat': - this.smartSort() + this.getImageDesc() docs = this.myChildLayoutPairs; return {docs} @@ -493,28 +493,83 @@ export class CollectionCardView extends CollectionSubView() { // const - const imgurlperchance = Cast(this.childDocs[1].data, ImageField, null)?.url; + const imgurlperchance = Cast(this.childDocs[1].data, ImageField, null)?.url.href; + const perchance = this.imageUrlToBase64(imgurlperchance) + // const imgurlperchance = Cast(this.childDocs[1].data, PdfField, null)?.url.; - console.log('Print Front of cards: ' + RTFCast(DocCast(this.dataDoc[this.fieldKey + '_0']).text)?.Text); - console.log('Print Back of cards: ' + RTFCast(DocCast(this.dataDoc[this.fieldKey + '_1']).text)?.Text); + // console.log('Print Front of cards: ' + RTFCast(DocCast(this.dataDoc[this.fieldKey + '_0']).text)?.Text); + // console.log('Print Back of cards: ' + RTFCast(DocCast(this.dataDoc[this.fieldKey + '_1']).text)?.Text); + + // const perchance = StrCast(this.childDocs[0].text); + + + + // const pdf = (StrCast(this.myChildLayoutPairs[0].layout.text)); //pdf + // const queryText = (RTFCast(this.myChildLayoutPairs[0].layout.text)); //everything else - // const queryText = (RTFCast(this.myChildLayoutPairs[0].layout.text)).Text; // const queryText = RTFCast(DocCast(this.dataDoc[this.fieldKey + '_1']).text)?.Text; - console.log(imgurlperchance ?? "sad") + console.log(perchance ?? "sad") } childPairStringList () { let string = "" for (let i=0; i < this.myChildLayoutPairs.length; i++){ + + + let text = StrCast((RTFCast(this.myChildLayoutPairs[i].layout.text)).Text) string += StrCast((RTFCast(this.myChildLayoutPairs[i].layout.text)).Text) + ", " + this.textToDoc.has() } return string } @observable isLoading = false + imageUrlToBase64 = async (imageUrl: string): Promise<string> => { + try { + const response = await fetch(imageUrl); + const blob = await response.blob(); + + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.readAsDataURL(blob); + reader.onloadend = () => resolve(reader.result as string); + reader.onerror = error => reject(error); + }); + } catch (error) { + console.error('Error:', error); + throw error; + } + }; + + textToDoc = new Map<string, Doc>() + gptProccessedImages = new Set<Doc>() + + @action async getImageDesc(){ + const images = this.childDocs.filter(d => d.type == DocumentType.IMG).filter(d=> !this.gptProccessedImages.has(d)); + images.map(doc => { + let href = (doc['data'] as URLField).url.href; + let hrefParts = href.split('.'); + let hrefComplete = `${hrefParts[0]}_o.${hrefParts[1]}`; + return this.imageUrlToBase64(hrefComplete).then(hrefBase64 => { + return gptImageLabel(hrefBase64).then(response => { + this.textToDoc.set(response, doc) + this.gptProccessedImages.add(doc) + console.log(response); + + }); + }); + }); + } + + + + //a set of all the images that have already been given desc + //a map from the text to the Doc (for everything) + + @action async smartSort() { this.isLoading = true; console.log("loading") @@ -536,7 +591,6 @@ export class CollectionCardView extends CollectionSubView() { // If GPT call failed console.error('GPT call failed'); } else if (res != null) { - // If GPT call succeeded, set htmlCode;;; TODO: check if valid html console.log(res) } this.isLoading = false; diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx index 6a956f2ac..731ea1235 100644 --- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx +++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx @@ -51,7 +51,7 @@ export const FInfotoColType: { [key: string]: ColumnType } = { enumeration: ColumnType.Enumeration, }; -const defaultColumnKeys: string[] = ['title', 'type', 'author', 'author_date', 'text']; +const defaultColumnKeys: string[] = ['title', 'type', 'author', 'author_date', 'text']; @observer export class CollectionSchemaView extends CollectionSubView() { diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx index aaff2a342..b87e29d4e 100644 --- a/src/client/views/pdf/PDFViewer.tsx +++ b/src/client/views/pdf/PDFViewer.tsx @@ -30,7 +30,7 @@ const _global = (window /* browser */ || global) /* node */ as any; //pdfjsLib.GlobalWorkerOptions.workerSrc = `/assets/pdf.worker.js`; // The workerSrc property shall be specified. -Pdfjs.GlobalWorkerOptions.workerSrc = 'https://unpkg.com/pdfjs-dist@4.1.392/build/pdf.worker.mjs'; +Pdfjs.GlobalWorkerOptions.workerSrc = 'https://unpkg.com/pdfjs-dist@4.2.67/build/pdf.worker.mjs'; interface IViewerProps extends FieldViewProps { pdfBox: PDFBox; |
