pub async fn from_document(db: &Database, doc: AnnotatedDoc, manifest_uri: String) -> Self {
        let page_images = doc.meta.page_images.unwrap();
        let (image_source, annotations, words) = {
            let annot_db = db.annotations();
            join!(
                db.image_source(&page_images.source),
                annot_db.on_document(&doc.meta.id),
                db.words_in_document(&doc.meta.id)
            )
        };
        let annotations = &annotations.unwrap();
        let words = &words.unwrap();
        let image_source = &image_source.unwrap().unwrap();
        let manifest_uri = &manifest_uri;
        Self::new(
            manifest_uri.clone(),
            doc.meta.title,
            "The Newberry Library".to_owned(),
            stream::iter(page_images.ids.into_iter().enumerate())
                .then(|(index, id)| async move {
                    let image_url = format!("{}/{}", image_source.url, id);
                    let info_url = format!("{}/info.json", image_url);
                    let info = reqwest::get(info_url)
                        .await
                        .unwrap()
                        .json::<ImageInfo>()
                        .await
                        .unwrap();
                    let page_num = (index + 1) as u32;
                    let page_uri = format!("{}/page/{}", manifest_uri, page_num);
                    let canvas_uri = format!("{}/canvas", page_uri);
                    let annotations_uri = format!("{}/annotations", page_uri);
                    let annotation_page = AnnotationPage {
                        items: words
                            .into_iter()
                            .filter_map(|word| {
                                if let Some(geometry) = &word.position.geometry {
                                    Some(Annotation {
                                        id: format!("{}/{}", annotations_uri, word.id),
                                        motivation: "supplementing".to_owned(),
                                        body: AnnotationBody::TextualBody(TextualBody {
                                            language: "en".to_string(),
                                            format: "text/html".to_string(),
                                            value: word.source.clone(),
                                        }),
                                        target: AnnotationTarget::Selector(TargetSelector {
                                            id: canvas_uri.clone(),
                                            selector: FragmentSelector {
                                                value: geometry.to_selector_string(),
                                            },
                                        }),
                                    })
                                } else {
                                    None
                                }
                            })
                            .chain(annotations.into_iter().filter_map(|annote| {
                                match &annote.attached_to {
                                    AnnotationAttachment::DocumentRegion(DocumentRegion {
                                        region,
                                        page: Some(annote_page),
                                        ..
                                    }) if *annote_page == page_num => Some(Annotation {
                                        id: format!("{}/{}", annotations_uri, annote.id.0),
                                        motivation: "commenting".to_owned(),
                                        body: AnnotationBody::TextualBody(TextualBody {
                                            language: "en".to_string(),
                                            format: "text/html".to_string(),
                                            value: annote.content.clone(),
                                        }),
                                        target: if let Some(region) = &region {
                                            AnnotationTarget::Selector(TargetSelector {
                                                id: canvas_uri.clone(),
                                                selector: FragmentSelector {
                                                    value: region.to_selector_string(),
                                                },
                                            })
                                        } else {
                                            AnnotationTarget::Id(canvas_uri.clone())
                                        },
                                    }),

                                    _ => None,
                                }
                            }))
                            .collect(),
                        id: annotations_uri,
                    };
                    // For each page, retrieve the size of the image to set the canvas size.
                    Canvas {
                        label: LanguageString::english(&format!("Page {}", page_num)),
                        height: info.height,
                        width: info.width,
                        items: vec![AnnotationPage {
                            items: vec![Annotation {
                                id: format!("{}/image", page_uri),
                                motivation: "painting".to_owned(),
                                body: AnnotationBody::Image(Image {
                                    id: format!("{}/full/max/0/default.jpg", image_url),
                                    width: info.width,
                                    height: info.height,
                                    format: "image/jpeg".to_owned(),
                                    service: vec![ImageService2 {
                                        id: image_url,
                                        profile: "level1".to_owned(),
                                    }],
                                }),
                                target: AnnotationTarget::Id(canvas_uri.clone()),
                            }],
                            id: page_uri,
                        }],
                        annotations: vec![annotation_page],
                        id: canvas_uri,
                    }
                })
                .collect()
                .await,
        )
    }
/// Make a IIIF manifest from the given document
Make a IIIF manifest from the given document
Make a IIIF manifest from the given document
pub async fn from_document(db: &Database, doc: AnnotatedDoc, manifest_uri: String) -> Self {
        let page_images = doc.meta.page_images.unwrap();
        let (image_source, annotations, words) = {
            let annot_db = db.annotations();
            join!(
                db.image_source(&page_images.source),
                annot_db.on_document(&doc.meta.id),
                db.words_in_document(&doc.meta.id)
            )
        };
        let annotations = &annotations.unwrap();
        let words = &words.unwrap();
        let image_source = &image_source.unwrap().unwrap();
        let manifest_uri = &manifest_uri;
        Self::new(
            manifest_uri.clone(),
            doc.meta.title,
            "The Newberry Library".to_owned(),
            stream::iter(page_images.ids.into_iter().enumerate())
                .then(|(index, id)| async move {
                    let image_url = format!("{}/{}", image_source.url, id);
                    let info_url = format!("{}/info.json", image_url);
                    let info = reqwest::get(info_url)
                        .await
                        .unwrap()
                        .json::<ImageInfo>()
                        .await
                        .unwrap();
                    let page_num = (index + 1) as u32;
                    let page_uri = format!("{}/page/{}", manifest_uri, page_num);
                    let canvas_uri = format!("{}/canvas", page_uri);
                    let annotations_uri = format!("{}/annotations", page_uri);
                    let annotation_page = AnnotationPage {
                        items: words
                            .into_iter()
                            .filter_map(|word| {
                                if let Some(geometry) = &word.position.geometry {
                                    Some(Annotation {
                                        id: format!("{}/{}", annotations_uri, word.id),
                                        motivation: "supplementing".to_owned(),
                                        body: AnnotationBody::TextualBody(TextualBody {
                                            language: "en".to_string(),
                                            format: "text/html".to_string(),
                                            value: word.source.clone(),
                                        }),
                                        target: AnnotationTarget::Selector(TargetSelector {
                                            id: canvas_uri.clone(),
                                            selector: FragmentSelector {
                                                value: geometry.to_selector_string(),
                                            },
                                        }),
                                    })
                                } else {
                                    None
                                }
                            })
                            .chain(annotations.into_iter().filter_map(|annote| {
                                match &annote.attached_to {
                                    AnnotationAttachment::DocumentRegion(DocumentRegion {
                                        region,
                                        page: Some(annote_page),
                                        ..
                                    }) if *annote_page == page_num => Some(Annotation {
                                        id: format!("{}/{}", annotations_uri, annote.id.0),
                                        motivation: "commenting".to_owned(),
                                        body: AnnotationBody::TextualBody(TextualBody {
                                            language: "en".to_string(),
                                            format: "text/html".to_string(),
                                            value: annote.content.clone(),
                                        }),
                                        target: if let Some(region) = &region {
                                            AnnotationTarget::Selector(TargetSelector {
                                                id: canvas_uri.clone(),
                                                selector: FragmentSelector {
                                                    value: region.to_selector_string(),
                                                },
                                            })
                                        } else {
                                            AnnotationTarget::Id(canvas_uri.clone())
                                        },
                                    }),
                                    _ => None,
                                }
                            }))
                            .collect(),
                        id: annotations_uri,
                    };
                    // For each page, retrieve the size of the image to set the canvas size.
                    Canvas {
                        label: LanguageString::english(&format!("Page {}", page_num)),
                        height: info.height,
                        width: info.width,
                        items: vec![AnnotationPage {
                            items: vec![Annotation {
                                id: format!("{}/image", page_uri),
                                motivation: "painting".to_owned(),
                                body: AnnotationBody::Image(Image {
                                    id: format!("{}/full/max/0/default.jpg", image_url),
                                    width: info.width,
                                    height: info.height,
                                    format: "image/jpeg".to_owned(),
                                    service: vec![ImageService2 {
                                        id: image_url,
                                        profile: "level1".to_owned(),
                                    }],
                                }),
                                target: AnnotationTarget::Id(canvas_uri.clone()),
                            }],
                            id: page_uri,
                        }],
                        annotations: vec![annotation_page],
                        id: canvas_uri,
                    }
                })
                .collect()
                .await,
        )
    }
pub async fn from_document ( db : & Database , doc : AnnotatedDoc , manifest_uri : String ) -> Self { let page_images = doc . meta . page_images . unwrap ( ) ; let ( image_source , annotations , words ) = { let annot_db = db . annotations ( ) ; join ! ( db image_source ( page_images source ) annot_db on_document ( doc meta id ) db words_in_document ( doc meta id ) ) } ; let annotations = & annotations . unwrap ( ) ; let words = & words . unwrap ( ) ; let image_source = & image_source . unwrap ( ) . unwrap ( ) ; let manifest_uri = & manifest_uri ; Self :: new ( manifest_uri . clone ( ) , doc . meta . title , " " . to_owned ( ) , stream :: iter ( page_images . ids . into_iter ( ) . enumerate ( ) ) . then ( | ( index , id ) | async move { let image_url = format ! ( " " image_source url id ) ; let info_url = format ! ( " " image_url ) ; let info = reqwest :: get ( info_url ) . await . unwrap ( ) . json :: < ImageInfo > ( ) . await . unwrap ( ) ; let page_num = ( index + 1 ) as u32 ; let page_uri = format ! ( " " manifest_uri page_num ) ; let canvas_uri = format ! ( " " page_uri ) ; let annotations_uri = format ! ( " " page_uri ) ; let annotation_page = AnnotationPage { items : words . into_iter ( ) . filter_map ( | word | { if let Some ( geometry ) = & word . position . geometry { Some ( Annotation { id : format ! ( " " annotations_uri word id ) , motivation : " " . to_owned ( ) , body : AnnotationBody :: TextualBody ( TextualBody { language : " " . to_string ( ) , format : " " . to_string ( ) , value : word . source . clone ( ) , } ) , target : AnnotationTarget :: Selector ( TargetSelector { id : canvas_uri . clone ( ) , selector : FragmentSelector { value : geometry . to_selector_string ( ) , } , } ) , } ) } else { None } } ) . chain ( annotations . into_iter ( ) . filter_map ( | annote | { match & annote . attached_to { AnnotationAttachment :: DocumentRegion ( DocumentRegion { region , page : Some ( annote_page ) , .. } ) if * annote_page == page_num => Some ( Annotation { id : format ! ( " " annotations_uri annote id 0 ) , motivation : " " . to_owned ( ) , body : AnnotationBody :: TextualBody ( TextualBody { language : " " . to_string ( ) , format : " " . to_string ( ) , value : annote . content . clone ( ) , } ) , target : if let Some ( region ) = & region { AnnotationTarget :: Selector ( TargetSelector { id : canvas_uri . clone ( ) , selector : FragmentSelector { value : region . to_selector_string ( ) , } , } ) } else { AnnotationTarget :: Id ( canvas_uri . clone ( ) ) } , } ) , _ => None , } } ) ) . collect ( ) , id : annotations_uri , } ; // For each page, retrieve the size of the image to set the canvas size. Canvas { label : LanguageString :: english ( & format ! ( " " page_num ) ) , height : info . height , width : info . width , items : vec ! [ AnnotationPage { items vec [ Annotation { id format ( " " page_uri ) motivation " " to_owned ( ) body AnnotationBody Image ( Image { id format ( " " image_url ) width info width height info height format " " to_owned ( ) service vec [ ImageService2 { id image_url profile " " to_owned ( ) } ] } ) target AnnotationTarget Id ( canvas_uri clone ( ) ) } ] id page_uri } ] , annotations : vec ! [ annotation_page ] , id : canvas_uri , } } ) . collect ( ) . await , ) }
Make a IIIF manifest from the given document
Make a IIIF manifest from the given document
db
&Database
doc
AnnotatedDoc
manifest_uri
String