Skip to content

Conversation

@kinboyw
Copy link

@kinboyw kinboyw commented Dec 18, 2025

Summary

This PR adds support for splitting large CSS files into multiple chunks to resolve timeout issues when serving large CSS files (>8MB). It also includes improvements to Docker build configuration and HTTP server timeout settings.

Problem

When serving large CSS files (e.g., 8MB+), the server would timeout after ~6 seconds due to:

  1. Default keep-alive timeout being too short (5 seconds)
  2. Single large CSS file causing connection drops during transfer
  3. No mechanism to split large CSS files into manageable chunks

Solution

1. Multiple CSS File Chunks Support

  • New API format: Support template.css?: Array<{ url: string, hash: string }> format
  • CSS file upload: Automatically generates unique filenames for CSS chunks using pattern {userUID}{hashPrefix8chars}
  • File lookup: Optimized queries using hash + filename prefix matching
  • Backward compatible: Falls back to single CSS file logic if no array is provided

Key changes:

  • File.initFile(): Supports multiple CSS chunks with hash-based deduplication
  • File.createNote(): Processes CSS array format from template
  • File.checkCss(): Returns array of CSS files instead of single object
  • File.checkFiles(): Returns CSS files as array format
  • File.checkFile(): Supports finding CSS chunks by hash
  • WebNote.setCss(): Supports both array and string formats
  • note.html template: Updated to allow multiple CSS link tags

2. HTTP Server Timeout Configuration

  • Increased default server timeout to 10 minutes (600000ms)
  • Configured keepAliveTimeout, requestTimeout, and headersTimeout
  • Configurable via SERVER_TIMEOUT environment variable

3. Docker Build Improvements

  • Fixed GitHub CI Actions platform compatibility issue with node:lts-alpine
  • Added build dependencies (python3, make, g++) for better-sqlite3 compilation
  • Updated CI workflow to build for linux/amd64 and linux/arm64 platforms only
  • Removed unnecessary --build-from-source option

4. Bug Fixes

  • Fixed Buffer to ArrayBuffer conversion in sha1() helper function

Technical Details

CSS Chunk Storage

CSS chunks are stored with filenames following the pattern:

{userUID}{hashPrefix8chars}

Example: 25debd7fa5ea0e4b82be9a39663d4a61 (user UID) + abc12345 (hash prefix) = 25debd7fa5ea0e4b82be9a39663d4a61abc12345

File Lookup Optimization

Multiple CSS files are queried using SQL LIKE pattern matching:

SELECT filename, hash, filetype 
FROM files 
WHERE filetype = 'css' 
AND filename LIKE '{userUID}%'
ORDER BY filename

API Response Format

All CSS-related APIs now return array format:

{
  success: true,
  css: [
    { url: "https://example.com/css/25/xxx.css", hash: "abc123..." },
    { url: "https://example.com/css/25/xxx-2.css", hash: "def456..." }
  ]
}

Testing

  • Tested with single CSS file (backward compatibility)
  • Tested with multiple CSS chunks
  • Verified timeout configuration works for large files
  • Tested Docker build on multiple platforms
  • Verified CSS file deduplication by hash

Breaking Changes

None - fully backward compatible. The changes maintain backward compatibility with existing single CSS file format.

Files Changed

  • app/src/v1/File.ts - CSS handling logic for upload, check, and note creation
  • app/src/v1/WebNote.ts - setCss() method to support arrays
  • app/src/v1/templates/note.html - Removed hardcoded link tag, use placeholder
  • app/src/index.ts - HTTP server timeout configuration
  • app/src/v1/helpers.ts - Buffer to ArrayBuffer conversion fix
  • Dockerfile - Build dependencies and configuration
  • .github/workflows/ci.yaml - Platform compatibility fixes

Related Issues

Fixes timeout issues when serving large CSS files (>8MB).

This commit consolidates fixes for Docker build issues and HTTP server
timeout problems when serving large files.

Docker build improvements:
- Fix GitHub CI Actions platform compatibility issue with node:lts-alpine
- Remove --build-from-source option from Dockerfile (not needed)
- Add build dependencies (python3, make, g++) for better-sqlite3 compilation
- Update CI workflow to only build for linux/amd64 and linux/arm64 platforms

HTTP server timeout fixes:
- Increase default server timeout to 10 minutes (600000ms) to handle large CSS files
- Configure keepAliveTimeout, requestTimeout, and headersTimeout
- Fix Buffer to ArrayBuffer conversion in sha1() helper function
- Update docker-compose.yml image version

These changes resolve timeout issues when serving large CSS files (>8MB)
and improve Docker build reliability across different platforms.

fix: timeout issues

fix: github ci actions node:lts-alpine platform issue

fix: remove --build-from-source options
Add support for splitting large CSS files into multiple chunks to avoid
timeout issues when serving large CSS files (>8MB).

Key changes:
- Support CSS file array format: template.css?: Array<{ url: string, hash: string }>
- CSS file upload supports multiple chunks with unique filenames (user UID + hash prefix)
- checkCss() and checkFiles() return CSS files as arrays instead of single objects
- checkFile() supports finding CSS chunks by hash and user UID prefix
- WebNote.setCss() supports both array and string formats for backward compatibility
- HTML template updated to allow multiple CSS link tags via placeholder

Technical implementation:
- CSS chunks stored with filenames: {userUID}{hashPrefix8chars}
- Multiple CSS files queried by filename prefix matching (LIKE pattern)
- Backward compatible: falls back to single CSS file logic if no array provided
- CSS file lookup optimized for chunked files using hash + filename prefix

Files modified:
- app/src/v1/File.ts: CSS handling for upload, check, and note creation
- app/src/v1/WebNote.ts: setCss() method to support arrays
- app/src/v1/templates/note.html: removed hardcoded link tag, use placeholder
- app/src/index.ts: HTTP server timeout configuration
- app/src/v1/helpers.ts: Buffer to ArrayBuffer conversion fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant