@@ -22,10 +22,10 @@ import * as path from "path";
22
22
import { LogService } from "matrix-bot-sdk" ;
23
23
import { PretalxSchema as PretalxData , parseFromJSON } from "./PretalxParser" ;
24
24
import { readFile , writeFile } from "fs/promises" ;
25
- import { PretalxApiClient , PretalxSpeaker , PretalxTalk } from "./PretalxApiClient" ;
25
+ import { PretalxApiClient } from "./PretalxApiClient" ;
26
+ import { PentabarfParser } from "../penta/PentabarfParser" ;
26
27
27
28
export class PretalxScheduleBackend implements IScheduleBackend {
28
- private speakerCache = new Map < string , PretalxSpeaker > ( ) ;
29
29
private readonly apiClient : PretalxApiClient ;
30
30
private constructor (
31
31
private readonly cfg : IPretalxScheduleBackendConfig ,
@@ -41,23 +41,23 @@ export class PretalxScheduleBackend implements IScheduleBackend {
41
41
}
42
42
43
43
private static async loadConferenceFromCfg ( dataPath : string , cfg : IPretalxScheduleBackendConfig , prefixCfg : IPrefixConfig , allowUseCache : boolean ) : Promise < { data : PretalxData , cached : boolean } > {
44
- let jsonDesc ;
44
+ let jsonOrXMLDesc ;
45
45
let cached = false ;
46
46
47
47
const cachedSchedulePath = path . join ( dataPath , 'cached_schedule.json' ) ;
48
48
49
49
try {
50
50
if ( cfg . scheduleDefinition . startsWith ( "http" ) ) {
51
51
// Fetch the JSON track over the network
52
- jsonDesc = await fetch ( cfg . scheduleDefinition ) . then ( r => r . text ( ) ) ;
52
+ jsonOrXMLDesc = await fetch ( cfg . scheduleDefinition ) . then ( r => r . text ( ) ) ;
53
53
} else {
54
54
// Load the JSON from disk
55
- jsonDesc = await readFile ( cfg . scheduleDefinition , 'utf-8' ) ;
55
+ jsonOrXMLDesc = await readFile ( cfg . scheduleDefinition , 'utf-8' ) ;
56
56
}
57
57
58
58
// Save a cached copy.
59
59
try {
60
- await writeFile ( cachedSchedulePath , jsonDesc ) ;
60
+ await writeFile ( cachedSchedulePath , jsonOrXMLDesc ) ;
61
61
} catch ( ex ) {
62
62
// Allow this to fail,
63
63
LogService . warn ( "PretalxScheduleBackend" , "Failed to cache copy of schedule." , ex ) ;
@@ -70,7 +70,7 @@ export class PretalxScheduleBackend implements IScheduleBackend {
70
70
71
71
LogService . error ( "PretalxScheduleBackend" , "Unable to load XML schedule, will use cached copy if available." , e . body ?? e ) ;
72
72
try {
73
- jsonDesc = await readFile ( cachedSchedulePath , 'utf-8' ) ;
73
+ jsonOrXMLDesc = await readFile ( cachedSchedulePath , 'utf-8' ) ;
74
74
} catch ( e ) {
75
75
if ( e . code === 'ENOENT' ) {
76
76
// No file
@@ -84,8 +84,21 @@ export class PretalxScheduleBackend implements IScheduleBackend {
84
84
throw "Double fault whilst trying to load JSON schedule" ;
85
85
}
86
86
}
87
-
88
- const data = await parseFromJSON ( jsonDesc , prefixCfg ) ;
87
+ let data : PretalxData ;
88
+ // For FOSDEM we prefer to use the pentabarf format as it contains
89
+ // extra information not found in the JSON format. This may change
90
+ // in the future.
91
+ if ( cfg . scheduleFormat === "pentabarf" ) {
92
+ const pentaData = new PentabarfParser ( jsonOrXMLDesc , prefixCfg ) ;
93
+ data = {
94
+ talks : new Map ( pentaData . talks . map ( v => [ v . id , v ] ) ) ,
95
+ auditoriums : new Map ( pentaData . auditoriums . map ( v => [ v . name , v ] ) ) ,
96
+ interestRooms : new Map ( pentaData . interestRooms . map ( v => [ v . id , v ] ) ) ,
97
+ title : pentaData . conference . title ,
98
+ }
99
+ } else {
100
+ data = await parseFromJSON ( jsonOrXMLDesc , prefixCfg ) ;
101
+ }
89
102
90
103
return { data, cached} ;
91
104
}
0 commit comments