Monorepo for wisp.place. A static site hosting service built on top of the AT Protocol. wisp.place

dont cache as gzip if not web text asset

Changed files
+28 -2
hosting-service
src
lib
+28 -2
hosting-service/src/lib/utils.ts
··· 296 296 mkdirSync(fileDir, { recursive: true }); 297 297 } 298 298 299 + // Determine if this is a web asset that should remain compressed 300 + const webAssetTypes = [ 301 + 'text/html', 'text/css', 'application/javascript', 'text/javascript', 302 + 'application/json', 'text/xml', 'application/xml' 303 + ]; 304 + 305 + const isWebAsset = mimeType && webAssetTypes.some(type => 306 + mimeType.toLowerCase().startsWith(type) || mimeType.toLowerCase() === type 307 + ); 308 + 309 + // Decompress non-web assets that are gzipped 310 + if (encoding === 'gzip' && !isWebAsset && content.length >= 2 && 311 + content[0] === 0x1f && content[1] === 0x8b) { 312 + console.log(`[DEBUG] ${filePath}: decompressing non-web asset (${mimeType}) before caching`); 313 + try { 314 + const { gunzipSync } = await import('zlib'); 315 + const decompressed = gunzipSync(content); 316 + console.log(`[DEBUG] ${filePath}: decompressed from ${content.length} to ${decompressed.length} bytes`); 317 + content = decompressed; 318 + // Clear the encoding flag since we're storing decompressed 319 + encoding = undefined; 320 + } catch (error) { 321 + console.log(`[DEBUG] ${filePath}: failed to decompress, storing original gzipped content`); 322 + } 323 + } 324 + 299 325 await writeFile(cacheFile, content); 300 326 301 - // Store metadata if file is compressed 327 + // Store metadata only if file is still compressed (web assets) 302 328 if (encoding === 'gzip' && mimeType) { 303 329 const metaFile = `${cacheFile}.meta`; 304 330 await writeFile(metaFile, JSON.stringify({ encoding, mimeType })); 305 331 console.log('Cached file', filePath, content.length, 'bytes (gzipped,', mimeType + ')'); 306 332 } else { 307 - console.log('Cached file', filePath, content.length, 'bytes'); 333 + console.log('Cached file', filePath, content.length, 'bytes (decompressed)'); 308 334 } 309 335 } 310 336