@@ -6,7 +6,8 @@ export class DigiShelf extends Shelf {
66 static id = 'digi' ;
77
88 private constructor ( ) {
9- super ( 'https://digi4school.at/books' ) ;
9+ super ( 'https://digi4school.at/' ) ;
10+ this . origins . push ( 'https://a.digi4school.at/' ) ;
1011 }
1112
1213 static async load ( options : InitOptions ) {
@@ -15,7 +16,7 @@ export class DigiShelf extends Shelf {
1516
1617 protected async login ( ) {
1718 await this . formLogin (
18- '/' ,
19+ '/login ' ,
1920 '#ion-input-0' ,
2021 '#ion-input-1' ,
2122 'ion-button[color="primary"]' ,
@@ -25,59 +26,39 @@ export class DigiShelf extends Shelf {
2526 . waitForNavigation ( { timeout : this . options . timeout } )
2627 . then ( ( ) => true ) ,
2728 page
28- . waitForFunction (
29- ( ) =>
30- document
31- . querySelector ( 'div[role="dialog"]' )
32- ?. innerHTML . includes ( 'Problem' ) ,
33- { timeout : this . options . timeout }
34- )
29+ . waitForFunction ( ( ) => ! ! document . querySelector ( 'ion-alert' ) , {
30+ timeout : this . options . timeout ,
31+ } )
3532 . then ( ( ) => false ) ,
3633 ] )
3734 ) ;
3835 }
3936
4037 async getItems ( ) : Promise < ItemRef [ ] > {
38+ let books : { code : number ; title : string } [ ] ;
39+
4140 const page = await this . browser . newPage ( ) ;
4241 try {
43- await page . goto ( new URL ( '/books' , this . origin ) . toString ( ) ) ;
44- await page . waitForSelector ( '#ebooksGrid > ion-row > ion-col' , {
45- timeout : this . options . timeout ,
46- } ) ;
47-
48- const itemLinks = await page . $$ ( '#ebooksGrid > ion-row > ion-col' ) ;
49-
50- return await Promise . all (
51- itemLinks . map ( async ( itemLink ) => {
52- const tempSelector = await itemLink . $ ( 'ion-thumbnail' ) ;
53-
54- const uniqueSelector = await page . evaluate ( ( el ) => {
55- let path = '' ;
56- while ( el . parentElement ) {
57- const tag = el . tagName . toLowerCase ( ) ;
58- const siblings = Array . from ( el . parentElement . children ) ;
59- const index = siblings . indexOf ( el ) + 1 ;
60- path = ` > ${ tag } :nth-child(${ index } )` + path ;
61- el = el . parentElement ;
62- }
63- return path . slice ( 3 ) ;
64- } , itemLink ) ;
65-
66- const title = await tempSelector ?. evaluate ( ( el ) =>
67- el . getAttribute ( 'title' )
68- ) ;
69-
70- if ( ! title ) {
71- throw new ScrapeError (
72- `Could not find the title of item with url ${ 'test' } .`
73- ) ;
74- }
75-
76- return new ItemRef ( this , uniqueSelector , title ) ;
77- } )
42+ const res = await page . goto (
43+ new URL ( '/br/xhr/v2/synch' , this . origin ) . toString ( ) ,
44+ { waitUntil : 'domcontentloaded' }
7845 ) ;
46+ if ( ! res || ! res . ok || res . status ( ) === 260 ) {
47+ throw new ScrapeError ( 'Could to retrieve list of books from the API.' ) ;
48+ }
49+ const data = await res . json ( ) ;
50+ books = data . books ;
7951 } finally {
8052 await page . close ( ) ;
8153 }
54+
55+ return books . map (
56+ ( book ) =>
57+ new ItemRef (
58+ this ,
59+ new URL ( `/ebook/${ book . code } ` , this . origin ) . toString ( ) ,
60+ book . title
61+ )
62+ ) ;
8263 }
8364}
0 commit comments