@@ -31,8 +31,10 @@ async function getETag(url: string): Promise<string> {
3131 throw new Error ( `HTTP error: ${ response . status } ` )
3232 }
3333
34- const etag = response . headers . get ( 'etag' )
35- return etag ? etag : ''
34+ /* old versions of nwjs dont report etag??
35+ * so just pick a random one to re-fetch each time */
36+ const etag = response . headers . get ( 'etag' ) || `${ Math . random ( ) } `
37+ return etag
3638 } catch ( err ) {
3739 return 'nointernet'
3840 }
@@ -90,18 +92,17 @@ export class FileCache {
9092 const ccPath : string = `${ this . cacheDir } /${ mod . database } /${ urlPathSuffix } `
9193 const imgPath = ccPath . substring ( './assets/' . length )
9294
93- if ( this . existsOnDisk . has ( ccPath ) ) {
94- return imgPath
95- } else {
96- return ( this . readingPromises [ ccPath ] ??= ( async ( ) => {
97- const data = new Uint8Array ( await ( await fetch ( url ) ) . arrayBuffer ( ) )
95+ if ( ! this . existsOnDisk . has ( ccPath ) ) {
96+ const fetchAndWrite = async ( ) => {
97+ const data = new Uint8Array ( await ( await fetch ( url , { cache : 'no-store' } ) ) . arrayBuffer ( ) )
9898
9999 await fs . promises . writeFile ( ccPath , data )
100100 this . existsOnDisk . add ( ccPath )
101-
102- return imgPath
103- } ) ( ) )
101+ delete this . readingPromises [ ccPath ]
102+ }
103+ await ( this . readingPromises [ ccPath ] ??= fetchAndWrite ( ) )
104104 }
105+ return imgPath
105106 }
106107
107108 static async checkDatabaseUrl ( url : string ) : Promise < boolean > {
@@ -124,18 +125,22 @@ export class FileCache {
124125
125126 if ( this . existsOnDisk . has ( ccPath ) ) {
126127 const readFile = async ( ) => {
127- return JSON . parse ( await fs . promises . readFile ( ccPath , 'utf8' ) )
128+ const json = JSON . parse ( await fs . promises . readFile ( ccPath , 'utf8' ) )
129+ delete this . readingPromises [ ccPath ]
130+ return json
128131 }
129132 const data : NPDatabase = await ( this . readingPromises [ ccPath ] ??= readFile ( ) )
130133
131134 if ( etag == 'nointernet' || etag == data . eTag ) return data
132135 }
133136
134137 return ( this . readingPromises [ ccPath ] ??= ( async ( ) => {
135- const data : NPDatabase = await ( await fetch ( url ) ) . json ( )
138+ const data : NPDatabase = await ( await fetch ( url , { cache : 'no-store' } ) ) . json ( )
136139 data . eTag = etag
137140
138141 await fs . promises . writeFile ( ccPath , JSON . stringify ( data ) )
142+ this . existsOnDisk . add ( ccPath )
143+ delete this . readingPromises [ ccPath ]
139144
140145 return data
141146 } ) ( ) )
0 commit comments