@@ -255,30 +255,30 @@ var Manifesto;
255255
256256var Manifesto ;
257257( function ( Manifesto ) {
258- class ResourceFormat extends Manifesto . StringValue {
258+ class MediaType extends Manifesto . StringValue {
259259 // todo: use getters when ES3 target is no longer required.
260260 jpg ( ) {
261- return new ResourceFormat ( ResourceFormat . JPG . toString ( ) ) ;
261+ return new MediaType ( MediaType . JPG . toString ( ) ) ;
262262 }
263263 mp4 ( ) {
264- return new ResourceFormat ( ResourceFormat . MP4 . toString ( ) ) ;
264+ return new MediaType ( MediaType . MP4 . toString ( ) ) ;
265265 }
266266 pdf ( ) {
267- return new ResourceFormat ( ResourceFormat . PDF . toString ( ) ) ;
267+ return new MediaType ( MediaType . PDF . toString ( ) ) ;
268268 }
269269 threejs ( ) {
270- return new ResourceFormat ( ResourceFormat . THREEJS . toString ( ) ) ;
270+ return new MediaType ( MediaType . THREEJS . toString ( ) ) ;
271271 }
272272 webm ( ) {
273- return new ResourceFormat ( ResourceFormat . WEBM . toString ( ) ) ;
273+ return new MediaType ( MediaType . WEBM . toString ( ) ) ;
274274 }
275275 }
276- ResourceFormat . JPG = new ResourceFormat ( "image/jpeg" ) ;
277- ResourceFormat . MP4 = new ResourceFormat ( "video/mp4" ) ;
278- ResourceFormat . PDF = new ResourceFormat ( "application/pdf" ) ;
279- ResourceFormat . THREEJS = new ResourceFormat ( "application/vnd.threejs+json" ) ;
280- ResourceFormat . WEBM = new ResourceFormat ( "video/webm" ) ;
281- Manifesto . ResourceFormat = ResourceFormat ;
276+ MediaType . JPG = new MediaType ( "image/jpeg" ) ;
277+ MediaType . MP4 = new MediaType ( "video/mp4" ) ;
278+ MediaType . PDF = new MediaType ( "application/pdf" ) ;
279+ MediaType . THREEJS = new MediaType ( "application/vnd.threejs+json" ) ;
280+ MediaType . WEBM = new MediaType ( "video/webm" ) ;
281+ Manifesto . MediaType = MediaType ;
282282} ) ( Manifesto || ( Manifesto = { } ) ) ;
283283
284284var Manifesto ;
@@ -422,7 +422,7 @@ var Manifesto;
422422 ServiceProfile . AUTHLOGOUT = new ServiceProfile ( "http://iiif.io/api/auth/0/logout" ) ;
423423 ServiceProfile . AUTHRESTRICTED = new ServiceProfile ( "http://iiif.io/api/auth/0/login/restricted" ) ;
424424 ServiceProfile . AUTHTOKEN = new ServiceProfile ( "http://iiif.io/api/auth/0/token" ) ;
425- ServiceProfile . AUTH1CLICKTHROUGH = new ServiceProfile ( "http://iiif.io/api/auth/1/login/ clickthrough" ) ;
425+ ServiceProfile . AUTH1CLICKTHROUGH = new ServiceProfile ( "http://iiif.io/api/auth/1/clickthrough" ) ;
426426 ServiceProfile . AUTH1EXTERNAL = new ServiceProfile ( "http://iiif.io/api/auth/1/external" ) ;
427427 ServiceProfile . AUTH1KIOSK = new ServiceProfile ( "http://iiif.io/api/auth/1/kiosk" ) ;
428428 ServiceProfile . AUTH1LOGIN = new ServiceProfile ( "http://iiif.io/api/auth/1/login" ) ;
@@ -649,7 +649,7 @@ var Manifesto;
649649 const rotation = 0 ;
650650 let quality = 'default' ;
651651 let width = w ;
652- var size ;
652+ let size ;
653653 // if an info.json has been loaded
654654 if ( this . externalResource && this . externalResource . data && this . externalResource . data [ '@id' ] ) {
655655 id = this . externalResource . data [ '@id' ] ;
@@ -666,16 +666,16 @@ var Manifesto;
666666 }
667667 else {
668668 // info.json hasn't been loaded yet
669- var images = this . getImages ( ) ;
669+ const images = this . getImages ( ) ;
670670 if ( images && images . length ) {
671- var firstImage = images [ 0 ] ;
672- var resource = firstImage . getResource ( ) ;
673- var services = resource . getServices ( ) ;
671+ const firstImage = images [ 0 ] ;
672+ const resource = firstImage . getResource ( ) ;
673+ const services = resource . getServices ( ) ;
674674 if ( ! width ) {
675675 width = resource . getWidth ( ) ;
676676 }
677677 if ( services . length ) {
678- var service = services [ 0 ] ;
678+ const service = services [ 0 ] ;
679679 id = service . id ;
680680 quality = Manifesto . Utils . getImageQuality ( service . getProfile ( ) ) ;
681681 }
@@ -687,7 +687,7 @@ var Manifesto;
687687 }
688688 }
689689 size = width + ',' ;
690- var uri = [ id , region , size , rotation , quality + '.jpg' ] . join ( '/' ) ;
690+ const uri = [ id , region , size , rotation , quality + '.jpg' ] . join ( '/' ) ;
691691 return uri ;
692692 }
693693 // Presentation API 3.0
@@ -705,8 +705,8 @@ var Manifesto;
705705 }
706706 const annotations = annotationPage . getItems ( ) ;
707707 for ( let i = 0 ; i < annotations . length ; i ++ ) {
708- var a = annotations [ i ] ;
709- var annotation = new Manifesto . Annotation ( a , this . options ) ;
708+ const a = annotations [ i ] ;
709+ const annotation = new Manifesto . Annotation ( a , this . options ) ;
710710 content . push ( annotation ) ;
711711 }
712712 return content ;
@@ -716,8 +716,8 @@ var Manifesto;
716716 if ( ! this . __jsonld . images )
717717 return images ;
718718 for ( let i = 0 ; i < this . __jsonld . images . length ; i ++ ) {
719- var a = this . __jsonld . images [ i ] ;
720- var annotation = new Manifesto . Annotation ( a , this . options ) ;
719+ const a = this . __jsonld . images [ i ] ;
720+ const annotation = new Manifesto . Annotation ( a , this . options ) ;
721721 images . push ( annotation ) ;
722722 }
723723 return images ;
@@ -1701,10 +1701,10 @@ var url = require("url");
17011701var Manifesto ;
17021702( function ( Manifesto ) {
17031703 class Utils {
1704- static getResourceFormat ( format ) {
1705- format = format . toLowerCase ( ) ;
1706- format = format . split ( ';' ) [ 0 ] ;
1707- return format . trim ( ) ;
1704+ static getMediaType ( type ) {
1705+ type = type . toLowerCase ( ) ;
1706+ type = type . split ( ';' ) [ 0 ] ;
1707+ return type . trim ( ) ;
17081708 }
17091709 static getImageQuality ( profile ) {
17101710 const p = profile . toString ( ) ;
@@ -1875,10 +1875,10 @@ var Manifesto;
18751875 request . end ( ) ;
18761876 } ) ;
18771877 }
1878- static loadExternalResourcesAuth1 ( resources , openContentProviderWindow , openTokenService , userInteractionWithContentProvider , getContentProviderWindow , showOutOfOptionsMessages ) {
1878+ static loadExternalResourcesAuth1 ( resources , openContentProviderInteraction , openTokenService , userInteractedWithContentProvider , getContentProviderInteraction , showOutOfOptionsMessages ) {
18791879 return new Promise ( ( resolve , reject ) => {
18801880 const promises = resources . map ( ( resource ) => {
1881- return Utils . loadExternalResourceAuth1 ( resource , openContentProviderWindow , openTokenService , userInteractionWithContentProvider , getContentProviderWindow , showOutOfOptionsMessages ) ;
1881+ return Utils . loadExternalResourceAuth1 ( resource , openContentProviderInteraction , openTokenService , userInteractedWithContentProvider , getContentProviderInteraction , showOutOfOptionsMessages ) ;
18821882 } ) ;
18831883 Promise . all ( promises )
18841884 . then ( ( ) => {
@@ -1888,16 +1888,19 @@ var Manifesto;
18881888 } ) ;
18891889 } ) ;
18901890 }
1891- static loadExternalResourceAuth1 ( resource , openContentProviderWindow , openTokenService , userInteractionWithContentProvider , getContentProviderWindow , showOutOfOptionsMessages ) {
1891+ static loadExternalResourceAuth1 ( resource , openContentProviderInteraction , openTokenService , userInteractedWithContentProvider , getContentProviderInteraction , showOutOfOptionsMessages ) {
18921892 return __awaiter ( this , void 0 , void 0 , function * ( ) {
18931893 yield resource . getData ( ) ;
18941894 if ( resource . status === HTTPStatusCode . MOVED_TEMPORARILY || resource . status === HTTPStatusCode . UNAUTHORIZED ) {
1895- yield Utils . doAuthChain ( resource , openContentProviderWindow , openTokenService , userInteractionWithContentProvider , getContentProviderWindow , showOutOfOptionsMessages ) ;
1895+ yield Utils . doAuthChain ( resource , openContentProviderInteraction , openTokenService , userInteractedWithContentProvider , getContentProviderInteraction , showOutOfOptionsMessages ) ;
18961896 }
1897- return resource ;
1897+ if ( resource . status === HTTPStatusCode . OK ) {
1898+ return resource ;
1899+ }
1900+ throw Utils . createAuthorizationFailedError ( ) ;
18981901 } ) ;
18991902 }
1900- static doAuthChain ( resource , openContentProviderWindow , openTokenService , userInteractionWithContentProvider , getContentProviderWindow , showOutOfOptionsMessages ) {
1903+ static doAuthChain ( resource , openContentProviderInteraction , openTokenService , userInteractedWithContentProvider , getContentProviderInteraction , showOutOfOptionsMessages ) {
19011904 return __awaiter ( this , void 0 , void 0 , function * ( ) {
19021905 // This function enters the flowchart at the < External? > junction
19031906 // http://iiif.io/api/auth/1.0/#workflow-from-the-browser-client-perspective
@@ -1912,30 +1915,25 @@ var Manifesto;
19121915 if ( serviceToTry ) {
19131916 serviceToTry . options = resource . options ;
19141917 lastAttempted = serviceToTry ;
1915- //let success =
19161918 yield Utils . attemptResourceWithToken ( resource , openTokenService , serviceToTry ) ;
1917- //if (success) return resource;
1919+ return resource ;
19181920 }
19191921 // Looking for kiosk pattern
19201922 serviceToTry = resource . kioskService ;
19211923 if ( serviceToTry ) {
19221924 serviceToTry . options = resource . options ;
19231925 lastAttempted = serviceToTry ;
1924- let kioskWindow = openContentProviderWindow ( serviceToTry ) ;
1925- if ( kioskWindow ) {
1926- yield userInteractionWithContentProvider ( kioskWindow ) ;
1927- //let success =
1926+ let kioskInteraction = openContentProviderInteraction ( serviceToTry ) ;
1927+ if ( kioskInteraction ) {
1928+ yield userInteractedWithContentProvider ( kioskInteraction ) ;
19281929 yield Utils . attemptResourceWithToken ( resource , openTokenService , serviceToTry ) ;
1929- //if (success) return resource;
1930- }
1931- else {
1932- // Could not open kiosk window
1930+ return resource ;
19331931 }
19341932 }
19351933 // The code for the next two patterns is identical (other than the profile name).
19361934 // The difference is in the expected behaviour of
19371935 //
1938- // await userInteractionWithContentProvider(contentProviderWindow );
1936+ // await userInteractedWithContentProvider(contentProviderInteraction );
19391937 //
19401938 // For clickthrough the opened window should close immediately having established
19411939 // a session, whereas for login the user might spend some time entering credentials etc.
@@ -1944,35 +1942,32 @@ var Manifesto;
19441942 if ( serviceToTry ) {
19451943 serviceToTry . options = resource . options ;
19461944 lastAttempted = serviceToTry ;
1947- let contentProviderWindow = yield getContentProviderWindow ( serviceToTry ) ;
1948- if ( contentProviderWindow ) {
1945+ let contentProviderInteraction = yield getContentProviderInteraction ( serviceToTry ) ;
1946+ if ( contentProviderInteraction ) {
19491947 // should close immediately
1950- yield userInteractionWithContentProvider ( contentProviderWindow ) ;
1951- //let success =
1948+ yield userInteractedWithContentProvider ( contentProviderInteraction ) ;
19521949 yield Utils . attemptResourceWithToken ( resource , openTokenService , serviceToTry ) ;
1953- //if (success) return resource;
1950+ return resource ;
19541951 }
19551952 }
19561953 // Looking for login pattern
19571954 serviceToTry = resource . loginService ;
19581955 if ( serviceToTry ) {
19591956 serviceToTry . options = resource . options ;
19601957 lastAttempted = serviceToTry ;
1961- let contentProviderWindow = yield getContentProviderWindow ( serviceToTry ) ;
1962- if ( contentProviderWindow ) {
1958+ let contentProviderInteraction = yield getContentProviderInteraction ( serviceToTry ) ;
1959+ if ( contentProviderInteraction ) {
19631960 // we expect the user to spend some time interacting
1964- yield userInteractionWithContentProvider ( contentProviderWindow ) ;
1965- //let success =
1961+ yield userInteractedWithContentProvider ( contentProviderInteraction ) ;
19661962 yield Utils . attemptResourceWithToken ( resource , openTokenService , serviceToTry ) ;
1967- //if (success) return resource;
1963+ return resource ;
19681964 }
19691965 }
19701966 // nothing worked! Use the most recently tried service as the source of
19711967 // messages to show to the user.
19721968 if ( lastAttempted ) {
19731969 showOutOfOptionsMessages ( lastAttempted ) ;
19741970 }
1975- return resource ;
19761971 } ) ;
19771972 }
19781973 static attemptResourceWithToken ( resource , openTokenService , authService ) {
@@ -1983,11 +1978,10 @@ var Manifesto;
19831978 // found token service: " + tokenService["@id"]);
19841979 let tokenMessage = yield openTokenService ( tokenService ) ;
19851980 if ( tokenMessage && tokenMessage . accessToken ) {
1986- yield resource . getData ( ) ;
1981+ yield resource . getData ( tokenMessage ) ;
1982+ return resource ;
19871983 }
19881984 }
1989- // Didn't get a 200 info response.
1990- return resource ;
19911985 } ) ;
19921986 }
19931987 static loadExternalResourcesAuth09 ( resources , tokenStorageStrategy , clickThrough , restricted , login , getAccessToken , storeAccessToken , getStoredAccessToken , handleResourceResponse , options ) {
@@ -2389,9 +2383,9 @@ global.manifesto = global.Manifesto = module.exports = {
23892383 ElementType : new Manifesto . ElementType ( ) ,
23902384 IIIFResourceType : new Manifesto . IIIFResourceType ( ) ,
23912385 ManifestType : new Manifesto . ManifestType ( ) ,
2386+ MediaType : new Manifesto . MediaType ( ) ,
23922387 MetadataItem : Manifesto . MetadataItem ,
23932388 RenderingFormat : new Manifesto . RenderingFormat ( ) ,
2394- ResourceFormat : new Manifesto . ResourceFormat ( ) ,
23952389 ResourceType : new Manifesto . ResourceType ( ) ,
23962390 ServiceProfile : new Manifesto . ServiceProfile ( ) ,
23972391 Translation : Manifesto . Translation ,
@@ -2467,7 +2461,7 @@ var Manifesto;
24672461 getFormat ( ) {
24682462 const format = this . getProperty ( 'format' ) ;
24692463 if ( format ) {
2470- return new Manifesto . ResourceFormat ( Manifesto . Utils . getResourceFormat ( format ) ) ;
2464+ return new Manifesto . MediaType ( Manifesto . Utils . getMediaType ( format ) ) ;
24712465 }
24722466 return null ;
24732467 }
@@ -2524,7 +2518,7 @@ var Manifesto;
25242518 getFormat ( ) {
25252519 const format = this . getProperty ( 'format' ) ;
25262520 if ( format ) {
2527- return new Manifesto . ResourceFormat ( format . toLowerCase ( ) ) ;
2521+ return new Manifesto . MediaType ( format . toLowerCase ( ) ) ;
25282522 }
25292523 return null ;
25302524 }
0 commit comments