1- import { getJsonLdDateField , getJsonLdLinkField , getJsonLdStringField } from './jsonld.js' ;
1+ import {
2+ getJsonLdDateField ,
3+ getJsonLdLinkField ,
4+ getJsonLdStringField ,
5+ } from './jsonld.js' ;
26
37export type Listing = {
48 created : Date ;
@@ -9,22 +13,24 @@ export type Listing = {
913 image : string ;
1014 name : string ;
1115 sameAs : string [ ] ;
12- }
13- }
16+ } ;
17+ } ;
1418export type WatchAction = {
1519 created : Date ;
1620 startTime : Date ;
1721 endTime : Date ;
1822 listingUr : string ;
19- }
23+ } ;
2024
2125export type Interpretation = {
2226 listings : Listing [ ] ;
2327 watchActions : WatchAction [ ] ;
24- }
28+ } ;
2529
26- async function getJsonLd ( uri : string ,
27- authenticatedFetcher : typeof globalThis . fetch ) : Promise < object [ ] > {
30+ async function getJsonLd (
31+ uri : string ,
32+ authenticatedFetcher : typeof globalThis . fetch ,
33+ ) : Promise < object [ ] > {
2834 const res = await authenticatedFetcher ( uri , {
2935 headers : {
3036 Accept : 'application/ld+json' ,
@@ -43,35 +49,59 @@ export async function fetchList(
4349 watchActions : [ ] ,
4450 } ;
4551
46- await Promise . all ( index . map ( async ( entry : object ) => {
47- if ( entry [ '@id' ] === folderUri ) {
48- return ;
49- }
50- const listing = await getJsonLd ( entry [ '@id' ] , aFetch ) ;
51- listing . forEach ( thing => {
52- if ( thing [ '@type' ] . indexOf ( 'https://schema.org/Movie' ) !== - 1 ) {
53- ret . listings . push ( {
54- created : getJsonLdDateField ( thing , 'http://purl.org/dc/terms/created' ) ,
55- modified : getJsonLdDateField ( thing , 'http://purl.org/dc/terms/modified' ) ,
56- movie : {
57- published : getJsonLdDateField ( thing , 'https://schema.org/datePublished' ) ,
58- description : getJsonLdStringField ( thing , 'https://schema.org/description' ) ,
59- image : getJsonLdStringField ( thing , 'https://schema.org/image' ) , // sic: string instead of link here
60- name : getJsonLdStringField ( thing , 'https://schema.org/name' ) ,
61- sameAs : thing [ 'https://schema.org/sameAs' ] . map ( x => x [ '@value' ] ) as string [ ] , // sic: string instead of link here
62- }
63- } ) ;
64- } else if ( thing [ '@type' ] . indexOf ( 'https://schema.org/WatchAction' ) !== - 1 ) {
65- ret . watchActions . push ( {
66- created : getJsonLdDateField ( thing , 'http://purl.org/dc/terms/created' ) ,
67- startTime : getJsonLdDateField ( thing , 'https://schema.org/startTime' ) ,
68- endTime : getJsonLdDateField ( thing , 'https://schema.org/endTime' ) ,
69- listingId : getJsonLdLinkField ( thing , 'https://schema.org/object' ) ,
70- } ) ;
71- } else {
72- console . log ( 'thing type not recognised' , thing ) ;
52+ await Promise . all (
53+ index . map ( async ( entry : object ) => {
54+ if ( entry [ '@id' ] === folderUri ) {
55+ return ;
7356 }
74- } )
75- } ) ) ;
57+ const listing = await getJsonLd ( entry [ '@id' ] , aFetch ) ;
58+ listing . forEach ( ( thing ) => {
59+ if ( thing [ '@type' ] . indexOf ( 'https://schema.org/Movie' ) !== - 1 ) {
60+ ret . listings . push ( {
61+ created : getJsonLdDateField (
62+ thing ,
63+ 'http://purl.org/dc/terms/created' ,
64+ ) ,
65+ modified : getJsonLdDateField (
66+ thing ,
67+ 'http://purl.org/dc/terms/modified' ,
68+ ) ,
69+ movie : {
70+ published : getJsonLdDateField (
71+ thing ,
72+ 'https://schema.org/datePublished' ,
73+ ) ,
74+ description : getJsonLdStringField (
75+ thing ,
76+ 'https://schema.org/description' ,
77+ ) ,
78+ image : getJsonLdStringField ( thing , 'https://schema.org/image' ) , // sic: string instead of link here
79+ name : getJsonLdStringField ( thing , 'https://schema.org/name' ) ,
80+ sameAs : thing [ 'https://schema.org/sameAs' ] . map (
81+ ( x ) => x [ '@value' ] ,
82+ ) as string [ ] , // sic: string instead of link here
83+ } ,
84+ } ) ;
85+ } else if (
86+ thing [ '@type' ] . indexOf ( 'https://schema.org/WatchAction' ) !== - 1
87+ ) {
88+ ret . watchActions . push ( {
89+ created : getJsonLdDateField (
90+ thing ,
91+ 'http://purl.org/dc/terms/created' ,
92+ ) ,
93+ startTime : getJsonLdDateField (
94+ thing ,
95+ 'https://schema.org/startTime' ,
96+ ) ,
97+ endTime : getJsonLdDateField ( thing , 'https://schema.org/endTime' ) ,
98+ listingId : getJsonLdLinkField ( thing , 'https://schema.org/object' ) ,
99+ } ) ;
100+ } else {
101+ console . log ( 'thing type not recognised' , thing ) ;
102+ }
103+ } ) ;
104+ } ) ,
105+ ) ;
76106 return ret ;
77107}
0 commit comments