这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@mosuka
Copy link
Owner

@mosuka mosuka commented Oct 16, 2025

Overview

Overview

Refactored model loading functionality and added WASM environment support.

Key improvement: Changed load_model signature from accepting &Path to &str, enabling URI-based model loading with support for http://, https://, and file:// schemes. This makes the API more flexible and enables remote model loading from web servers.

Additional improvements include reduced code duplication, improved error handling, and full WASM environment compatibility for HTTP/HTTPS-based model loading.

Main Changes

1. Model Loading Refactoring

  • Extracted common parsing logic: Added parse_model_content helper method to eliminate code duplication between load_model_from_file and load_model_from_url (approximately 33% code reduction)
  • Improved error handling: Replaced all unwrap() calls with proper error propagation (? operator, map_err), and added detailed error messages with line numbers
  • Fixed Clippy warnings:
    • Changed unnecessary format!("{}", e) to e.to_string()
    • Changed std::io::Error::new(ErrorKind::Other, ...) to std::io::Error::other(...)

2. WASM Environment Support

  • Added conditional compilation: Implemented proper branching using cfg(target_arch = "wasm32")
  • Restricted file:// scheme and local paths: Returns appropriate error messages in WASM environments
  • Optimized dependencies: Excluded rayon, tokio, tempfile, and tokio-test from WASM builds

3. Code Organization Improvements

  • Separated ModelScheme enum: Moved from adaboost.rs to util.rs to clarify module responsibilities
  • Optimized Tokio features: Removed unused time, sync, and io-util features, keeping only the necessary rt-multi-thread and macros

4. Test and Documentation Fixes

  • Fixed doctests: Updated to handle async function calls (using tokio_test::block_on)
  • Added dependencies: Added tokio-test to dev-dependencies

WASM Environment Behavior

✅ Supported Features

  • Model loading from https:// URLs
  • Model loading from http:// URLs

❌ Unsupported Features (returns appropriate error messages)

  • file:// scheme
  • Local file paths

⚠️ CORS Restrictions

When loading models from different origins in WASM environments (browsers), CORS headers must be configured on the server side:

Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET

Note: This restriction is a browser security specification and cannot be circumvented on the client side (Litsea).

@mosuka mosuka merged commit f188837 into main Oct 16, 2025
4 checks passed
@mosuka mosuka deleted the support_uri branch October 16, 2025 06:32
@mosuka mosuka mentioned this pull request Oct 16, 2025
2 tasks
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.

2 participants