Compare commits
15
Commits
master
...
7b772bb1bb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b772bb1bb | ||
|
|
057bba0c56 | ||
|
|
a5e7b766ac | ||
|
|
1ebb16c15f | ||
|
|
ae885f3780 | ||
|
|
975258d70e | ||
|
|
29f06b197e | ||
|
|
2b8821bc77 | ||
|
|
b5af6e7e2c | ||
|
|
43dafb57da | ||
|
|
83be780243 | ||
|
|
78f22f65f4 | ||
|
|
4adb291592 | ||
|
|
fc96a10397 | ||
|
|
eb51afaea8 |
No files matched your search
@@ -37,7 +37,7 @@ PlugSnatcher/
|
|||||||
|
|
||||||
### 1. Feature Planning
|
### 1. Feature Planning
|
||||||
|
|
||||||
1. **Consult Roadmap**: Check the `ROADMAP.md` file to identify the next feature to implement
|
1. **Consult Roadmap**: ALWAYS Check the [ROADMAP.md](mdc:ROADMAP.md) file to identify the next feature to implement
|
||||||
2. **Define Scope**: Clearly define what the feature will do and identify any dependencies
|
2. **Define Scope**: Clearly define what the feature will do and identify any dependencies
|
||||||
3. **Update Roadmap**: Mark features as "In Progress" when starting work
|
3. **Update Roadmap**: Mark features as "In Progress" when starting work
|
||||||
|
|
||||||
|
|||||||
@@ -79,6 +79,8 @@ Description
|
|||||||
|
|
||||||
Authors
|
Authors
|
||||||
|
|
||||||
|
Website (from plugin.yml)
|
||||||
|
|
||||||
API version
|
API version
|
||||||
|
|
||||||
Source URL (if embedded or in plugin.yml)
|
Source URL (if embedded or in plugin.yml)
|
||||||
@@ -202,3 +204,30 @@ No consistent plugin metadata across sites (we'll brute force it)
|
|||||||
|
|
||||||
API rate limits (user token support for GitHub)
|
API rate limits (user token support for GitHub)
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
### GitHub API Token (Optional)
|
||||||
|
|
||||||
|
To avoid GitHub API rate limits when checking for updates for plugins hosted on GitHub, you can provide a [Personal Access Token (PAT)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-tokens).
|
||||||
|
|
||||||
|
1. **Create a PAT:** Go to your GitHub settings > Developer settings > Personal access tokens > Tokens (classic). Generate a new token (classic). No specific scopes are required for reading public repository information.
|
||||||
|
2. **Set Environment Variable:** Set the `GITHUB_API_TOKEN` environment variable to the value of your generated token before running PlugSnatcher.
|
||||||
|
|
||||||
|
* **Windows (PowerShell):**
|
||||||
|
```powershell
|
||||||
|
$env:GITHUB_API_TOKEN="your_github_pat_here"
|
||||||
|
npm run tauri dev
|
||||||
|
```
|
||||||
|
* **Windows (Command Prompt):**
|
||||||
|
```cmd
|
||||||
|
set GITHUB_API_TOKEN=your_github_pat_here
|
||||||
|
npm run tauri dev
|
||||||
|
```
|
||||||
|
* **Linux/macOS:**
|
||||||
|
```bash
|
||||||
|
export GITHUB_API_TOKEN="your_github_pat_here"
|
||||||
|
npm run tauri dev
|
||||||
|
```
|
||||||
|
|
||||||
|
If this environment variable is not set, PlugSnatcher will still attempt to check GitHub, but you may encounter `403 Forbidden` errors if you check many plugins frequently.
|
||||||
|
|
||||||
+83
-20
@@ -4,43 +4,100 @@
|
|||||||
- [x] Create project roadmap
|
- [x] Create project roadmap
|
||||||
- [x] Initialize Tauri + React project
|
- [x] Initialize Tauri + React project
|
||||||
- [x] Setup basic project structure
|
- [x] Setup basic project structure
|
||||||
- [ ] Create GitHub repository (optional)
|
- [x] Create Remote repository (optional)
|
||||||
|
|
||||||
## Core Infrastructure (In Progress)
|
## Core Infrastructure (Completed) ✅
|
||||||
- [x] Setup SQLite or JSON storage for plugin data
|
- [x] Setup SQLite or JSON storage for plugin data
|
||||||
- [x] Create core data models
|
- [x] Create core data models
|
||||||
- [x] Build server/plugin directory scanner (basic implementation)
|
- [x] Build server/plugin directory scanner (basic implementation)
|
||||||
|
- [x] Implement asynchronous server scanning (non-blocking)
|
||||||
- [x] Implement JAR file parser for plugin.yml extraction
|
- [x] Implement JAR file parser for plugin.yml extraction
|
||||||
|
|
||||||
## Plugin Discovery (In Progress)
|
## Plugin Discovery (Completed) ✅
|
||||||
- [x] Create server type detection (Paper, Spigot, etc.)
|
- [x] Improve server type detection (Paper/Spigot distinction, etc.)
|
||||||
- [x] Implement plugins folder detection logic
|
- [x] Implement plugins folder detection logic
|
||||||
- [x] Design plugin metadata extraction system
|
- [x] Design plugin metadata extraction system
|
||||||
|
- [x] Extract basic fields (name, version, author, etc.)
|
||||||
|
- [x] Extract website field from plugin.yml
|
||||||
- [x] Build plugin hash identification system
|
- [x] Build plugin hash identification system
|
||||||
|
- [x] Create plugin matching algorithm
|
||||||
|
|
||||||
## Web Crawler Development (Upcoming)
|
## Web Crawler Development (Mostly Completed)
|
||||||
- [ ] Create base web crawler architecture
|
- [x] Create base web crawler architecture
|
||||||
- [ ] Implement HangarMC crawler
|
- [x] Implement HangarMC crawler
|
||||||
- [ ] Implement SpigotMC crawler
|
- [x] Implement SpigotMC data source using SpiGet API
|
||||||
- [ ] Implement Modrinth crawler
|
- [x] Basic implementation
|
||||||
- [ ] Implement GitHub releases crawler
|
- [x] Fix version information retrieval issues
|
||||||
- [ ] Create plugin matching algorithm
|
- [ ] Reduce version warning logs and improve caching
|
||||||
|
- [x] Handle rate limiting and 403 errors
|
||||||
|
- [x] Implement Modrinth crawler
|
||||||
|
- [x] Basic implementation
|
||||||
|
- [x] Version compatibility checking
|
||||||
|
- [x] Fix version number display issues
|
||||||
|
- [ ] Handle rate limit issues
|
||||||
|
- [x] Implement GitHub releases crawler
|
||||||
|
- [x] Basic implementation
|
||||||
|
- [x] Enable GitHub search functionality
|
||||||
|
- [ ] Add GitHub API authentication for higher rate limits
|
||||||
|
|
||||||
## Update Management (Upcoming)
|
## Update Management (Mostly Completed)
|
||||||
- [ ] Build update detection system
|
- [x] Build update detection system (Basic logic)
|
||||||
- [ ] Implement changelog extraction
|
- [x] Improve update detection reliability
|
||||||
- [ ] Create plugin backup functionality
|
- [x] Correctly fetch detailed version information from repositories
|
||||||
- [ ] Develop plugin replacement logic
|
- [x] Implement robust version comparison logic (handling non-SemVer, suffixes, etc.)
|
||||||
- [ ] Add server restart capabilities (optional)
|
- [x] Implement proper request headers (User-Agent, etc.) to mimic browser behavior
|
||||||
|
- [x] Add delays between API requests to mitigate rate limiting
|
||||||
|
- [x] Implement automatic retry logic for rate limits (429) and network errors
|
||||||
|
- [x] Implement API response caching (reduce requests, improve performance)
|
||||||
|
- [x] Implement intelligent name variation searches for plugins
|
||||||
|
- [x] Fix SpigotMC version retrieval issues
|
||||||
|
- [x] Fix update check progress getting stuck
|
||||||
|
- [x] Complete Modrinth integration
|
||||||
|
- [x] Fix incorrect plugin matching issues
|
||||||
|
- [x] Improve matching algorithm to reduce false positives
|
||||||
|
- [x] Complete GitHub integration
|
||||||
|
- [ ] Add GitHub API authentication for higher rate limits (environment variable support exists)
|
||||||
|
- [ ] Fix command parameter naming issues for update checks
|
||||||
|
- [ ] Optimize duplicate plugin search results (e.g., ViaVersion plugin)
|
||||||
|
- [x] Implement changelog extraction
|
||||||
|
- [x] Create plugin backup functionality
|
||||||
|
- [x] Develop plugin replacement logic
|
||||||
|
- [x] Implement plugin source persistence (store identified repo/ID to avoid searching)
|
||||||
|
- [ ] Allow manual setting/clearing of persistent source
|
||||||
|
- [x] Add plugin update UI integration
|
||||||
|
- [x] Add update buttons to plugin listing and details view
|
||||||
|
- [x] Show update progress with loading indicators
|
||||||
|
- [x] Handle file access errors gracefully
|
||||||
|
- [x] Ensure correct version numbering in filenames
|
||||||
|
- [x] Display up-to-date version information for all plugins
|
||||||
|
- [x] Handle premium plugins with user guidance for manual downloads
|
||||||
|
- [ ] Present multiple potential matches for ambiguous plugins
|
||||||
|
- [ ] Make version numbers clickable links to repository sources
|
||||||
|
- [ ] Allow user selection of correct plugin match when multiple are found
|
||||||
|
- [ ] Server platform compatibility matching (High Priority)
|
||||||
|
- [ ] Detect server platform and version accurately (Paper, Spigot, Forge, NeoForge, Fabric, etc.)
|
||||||
|
- [ ] Filter plugin updates to match the server platform
|
||||||
|
- [ ] Prevent incompatible version updates
|
||||||
|
- [ ] Add platform indicators in the UI for available updates
|
||||||
|
- [ ] Allow manual selection of target platform when multiple are available
|
||||||
|
|
||||||
## UI Development (In Progress)
|
## UI Development (In Progress)
|
||||||
- [x] Design and implement main dashboard
|
- [x] Design and implement main dashboard
|
||||||
- [x] Create plugin list view with version indicators
|
- [x] Refine plugin list view styling and layout
|
||||||
|
- [x] Add progress indicator for server scanning
|
||||||
- [x] Build server folder selection interface
|
- [x] Build server folder selection interface
|
||||||
- [x] Implement plugin detail view
|
- [x] Implement plugin detail view
|
||||||
- [x] Add update notification system
|
- [x] Add update notification system
|
||||||
|
- [x] Add per-plugin update check button & loading indicator
|
||||||
|
- [x] Add visual feedback for bulk update check (progress, loading state)
|
||||||
|
- [x] Implement error handling in UI with user-friendly messages
|
||||||
|
- [x] Add premium plugin detection & manual download guidance
|
||||||
- [ ] Create settings panel
|
- [ ] Create settings panel
|
||||||
- [x] Implement dark mode
|
- [x] Implement dark mode
|
||||||
|
- [ ] Implement plugin matching disambiguation UI
|
||||||
|
- [ ] Add clickable version links to repository pages
|
||||||
|
- [ ] Add error recovery UI for failed updates
|
||||||
|
- [ ] Add detailed progress logging in UI for debugging
|
||||||
|
|
||||||
## Security Features (Upcoming)
|
## Security Features (Upcoming)
|
||||||
- [ ] Implement sandboxing for network requests
|
- [ ] Implement sandboxing for network requests
|
||||||
@@ -49,14 +106,18 @@
|
|||||||
|
|
||||||
## Testing & Refinement (Upcoming)
|
## Testing & Refinement (Upcoming)
|
||||||
- [ ] Comprehensive testing with various server setups
|
- [ ] Comprehensive testing with various server setups
|
||||||
- [ ] Performance optimization
|
- [ ] Performance optimization (especially concurrent requests)
|
||||||
- [ ] Error handling improvements
|
- [ ] Error handling improvements (parsing, network, etc.)
|
||||||
- [ ] User acceptance testing
|
- [ ] User acceptance testing
|
||||||
|
- [ ] Add automated tests for critical functionality
|
||||||
|
- [ ] Add error telemetry (optional)
|
||||||
|
|
||||||
## Documentation (Upcoming)
|
## Documentation (Upcoming)
|
||||||
- [ ] Create user documentation
|
- [ ] Create user documentation
|
||||||
- [ ] Write developer documentation
|
- [ ] Write developer documentation
|
||||||
- [ ] Create installation guide
|
- [ ] Create installation guide
|
||||||
|
- [ ] Add troubleshooting guide
|
||||||
|
- [ ] Document known limitations and workarounds
|
||||||
|
|
||||||
## Deployment (Upcoming)
|
## Deployment (Upcoming)
|
||||||
- [ ] Prepare release process
|
- [ ] Prepare release process
|
||||||
@@ -73,3 +134,5 @@
|
|||||||
- [ ] Rollback system
|
- [ ] Rollback system
|
||||||
- [ ] Plugin recommendation system
|
- [ ] Plugin recommendation system
|
||||||
- [ ] Discord webhook integration
|
- [ ] Discord webhook integration
|
||||||
|
- [ ] Plugin search and browse functionality
|
||||||
|
- [ ] Plugin install from repository
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
# Server Platform Compatibility in PlugSnatcher
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
PlugSnatcher now has enhanced platform compatibility checking to ensure that plugins you download and update are compatible with your specific server type. This feature prevents potential issues like downloading a NeoForge version of a plugin for a Paper server or vice versa.
|
||||||
|
|
||||||
|
## Supported Server Types
|
||||||
|
|
||||||
|
PlugSnatcher automatically detects and supports the following server types:
|
||||||
|
|
||||||
|
- **Paper** - Can use plugins built for Paper, Spigot, and Bukkit
|
||||||
|
- **Spigot** - Can use plugins built for Spigot and Bukkit
|
||||||
|
- **Bukkit** - Can use plugins built for Bukkit only
|
||||||
|
- **Forge** - Can use plugins built for Forge
|
||||||
|
- **Fabric** - Can use plugins built for Fabric
|
||||||
|
- **Velocity** - Can use plugins built for Velocity
|
||||||
|
- **BungeeCord** - Can use plugins built for BungeeCord
|
||||||
|
- **Waterfall** - Can use plugins built for Waterfall and BungeeCord
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
1. **Server Type Detection**: When you scan a server directory, PlugSnatcher automatically determines the server type based on file patterns and configuration files.
|
||||||
|
|
||||||
|
2. **Platform-Aware Updates**: When checking for updates, PlugSnatcher filters plugin versions based on your server type. For example, if you're running a Paper server, PlugSnatcher will prioritize Paper/Spigot/Bukkit versions and avoid Forge/Fabric versions.
|
||||||
|
|
||||||
|
3. **Compatible Version Selection**: When multiple versions of a plugin are available (e.g., Paper, Forge, and Fabric versions), PlugSnatcher automatically selects the one compatible with your server.
|
||||||
|
|
||||||
|
4. **Warning System**: If no compatible version is found, PlugSnatcher will warn you before allowing you to proceed with an update that might not work on your server.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
- **Plugin with multiple versions**: For plugins like LuckPerms that have versions for various platforms (Paper, Forge, NeoForge, Fabric), PlugSnatcher will automatically select the version that matches your server type.
|
||||||
|
|
||||||
|
- **Universal plugins**: Some plugins work across multiple platforms without specific builds. In these cases, PlugSnatcher will consider them compatible with all server types.
|
||||||
|
|
||||||
|
## Technical Details
|
||||||
|
|
||||||
|
This feature primarily affects plugins downloaded from repositories that provide platform information, such as:
|
||||||
|
|
||||||
|
- **Modrinth**: Provides detailed platform compatibility information through "loaders" metadata
|
||||||
|
- **Hangar**: Includes platform tags for each plugin version
|
||||||
|
- **GitHub**: May or may not include platform information depending on the repository structure
|
||||||
|
|
||||||
|
For repositories without explicit platform tagging (like SpigotMC), PlugSnatcher will use the general repository focus (e.g., SpigotMC is for Bukkit/Spigot/Paper servers) to determine compatibility.
|
||||||
|
|
||||||
|
## Current Limitations
|
||||||
|
|
||||||
|
- Some repositories don't provide structured platform compatibility information
|
||||||
|
- Plugin naming conventions aren't always consistent, making it difficult to determine platform compatibility from filenames alone
|
||||||
|
- Some custom/niche server types may not be properly detected or matched
|
||||||
|
|
||||||
|
## Future Improvements
|
||||||
|
|
||||||
|
- Allow manual override of detected server type
|
||||||
|
- Add compatibility visualization in the UI
|
||||||
|
- Improve detection of platform from plugin filename patterns
|
||||||
|
- Support for more server types and platforms
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# Frontend/Backend Synchronization Checklist
|
||||||
|
|
||||||
|
This checklist tracks the necessary changes to ensure `src/App.tsx` works correctly with the refactored Rust backend.
|
||||||
|
|
||||||
|
## Backend Changes (`src-tauri/`)
|
||||||
|
|
||||||
|
- [ ] **Create `load_plugin_data` Command:**
|
||||||
|
- Implement a command `load_plugin_data(app_handle: AppHandle, server_path: String) -> Result<Vec<Plugin>, String>`.
|
||||||
|
- Use `get_plugin_data_path` from `scanner.rs` to find the correct `plugins.json`.
|
||||||
|
- Read and deserialize `plugins.json`.
|
||||||
|
- Return `Ok(plugins)` or an appropriate `Err(String)`.
|
||||||
|
- Register the command in `lib.rs`.
|
||||||
|
- [ ] **Create `save_plugin_data` Command:**
|
||||||
|
- Implement a command `save_plugin_data(app_handle: AppHandle, plugins: Vec<Plugin>, server_path: String) -> Result<(), String>`.
|
||||||
|
- Use `get_plugin_data_path` from `scanner.rs`.
|
||||||
|
- Serialize the `plugins` vector to JSON.
|
||||||
|
- Write the JSON to `plugins.json`, creating the directory if needed.
|
||||||
|
- Return `Ok(())` or an appropriate `Err(String)`.
|
||||||
|
- Register the command in `lib.rs`.
|
||||||
|
- [ ] **Align Bulk Update Events/Logic:**
|
||||||
|
- In `update_checker.rs` (`check_for_plugin_updates`), rename the emitted event from `"update_check_started"` to `"bulk_update_start"`.
|
||||||
|
- In `update_checker.rs` (`check_for_plugin_updates`), remove the `app_handle.emit("update_check_completed", ())` call. The result should be handled via the command's return value.
|
||||||
|
|
||||||
|
## Frontend Changes (`src/App.tsx`)
|
||||||
|
|
||||||
|
- [ ] **Align `Plugin` Interface Nullability:**
|
||||||
|
- Ensure `depend`, `soft_depend`, and `load_before` fields consistently use `string[] | null`.
|
||||||
|
- [ ] **Rename Command Invokes:**
|
||||||
|
- Change `invoke("check_single_plugin_update", ...)` to `invoke("check_single_plugin_update_command", ...)`.
|
||||||
|
- Change `invoke("set_plugin_repository_source", ...)` to `invoke("set_plugin_repository", ...)`.
|
||||||
|
- [ ] **Refactor `checkForUpdates` Result Handling:**
|
||||||
|
- Modify the `checkForUpdates` async function to `await` the `invoke("check_plugin_updates", ...)` call.
|
||||||
|
- Use a `try...catch` block or `.then().catch()` to handle the `Result<Vec<Plugin>, String>`.
|
||||||
|
- On success (`Ok(updatedPlugins)`), call `setPlugins(updatedPlugins)` and clear errors/loading states.
|
||||||
|
- On error (`Err(error)`), call `setUpdateError(error)` and clear loading states.
|
||||||
|
- [ ] **Adjust/Remove Event Listeners:**
|
||||||
|
- In `useEffect`, rename the listener for `"update_check_started"` to `"bulk_update_start"`.
|
||||||
|
- In `useEffect`, remove the listeners for `"bulk_update_complete"` and `"bulk_update_error"`.
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,34 @@
|
|||||||
|
## Backend Changes (`src-tauri/`)
|
||||||
|
|
||||||
|
- [x] **Create `load_plugin_data` Command:**
|
||||||
|
- Implement a command `load_plugin_data(app_handle: AppHandle, server_path: String) -> Result<Vec<Plugin>, String>`.
|
||||||
|
- Use `get_plugin_data_path` from `scanner.rs` to find the correct `plugins.json`.
|
||||||
|
- Read and deserialize `plugins.json`.
|
||||||
|
- Return `Ok(plugins)` or an appropriate `Err(String)`.
|
||||||
|
- Register the command in `lib.rs`.
|
||||||
|
- [x] **Create `save_plugin_data` Command:**
|
||||||
|
- Implement a command `save_plugin_data(app_handle: AppHandle, plugins: Vec<Plugin>, server_path: String) -> Result<(), String>`.
|
||||||
|
- Use `get_plugin_data_path` from `scanner.rs`.
|
||||||
|
- Serialize the `plugins` vector to JSON.
|
||||||
|
- Write the JSON to `plugins.json`, creating the directory if needed.
|
||||||
|
- Return `Ok(())` or an appropriate `Err(String)`.
|
||||||
|
- Register the command in `lib.rs`.
|
||||||
|
- [x] **Align Bulk Update Events/Logic:**
|
||||||
|
- In `update_checker.rs` (`check_for_plugin_updates`), rename the emitted event from `"update_check_started"` to `"bulk_update_start"`.
|
||||||
|
- In `update_checker.rs` (`check_for_plugin_updates`), remove the `app_handle.emit("update_check_completed", ())` call. The result should be handled via the command's return value.
|
||||||
|
|
||||||
|
## Frontend Changes (`src/App.tsx`)
|
||||||
|
|
||||||
|
- [x] **Align `Plugin` Interface Nullability:**
|
||||||
|
- Ensure `depend`, `soft_depend`, and `load_before` fields consistently use `string[] | null`.
|
||||||
|
- [x] **Rename Command Invokes:**
|
||||||
|
- Change `invoke("check_single_plugin_update", ...)` to `invoke("check_single_plugin_update_command", ...)`.
|
||||||
|
- Change `invoke("set_plugin_repository_source", ...)` to `invoke("set_plugin_repository", ...)`.
|
||||||
|
- [x] **Refactor `checkForUpdates` Result Handling:**
|
||||||
|
- Modify the `checkForUpdates` async function to `await` the `invoke("check_plugin_updates", ...)` call.
|
||||||
|
- Use a `try...catch` block or `.then().catch()` to handle the `Result<Vec<Plugin>, String>`.
|
||||||
|
- On success (`Ok(updatedPlugins)`), call `setPlugins(updatedPlugins)` and clear errors/loading states.
|
||||||
|
- On error (`Err(error)`), call `setUpdateError(error)` and clear loading states.
|
||||||
|
- [x] **Adjust/Remove Event Listeners:**
|
||||||
|
- In `useEffect`, rename the listener for `"update_check_started"` to `"bulk_update_start"`.
|
||||||
|
- In `useEffect`, remove the listeners for `"bulk_update_complete"` and `"bulk_update_error"`.
|
||||||
Generated
+364
-8
@@ -28,6 +28,18 @@ dependencies = [
|
|||||||
"cpufeatures",
|
"cpufeatures",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ahash"
|
||||||
|
version = "0.8.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"once_cell",
|
||||||
|
"version_check",
|
||||||
|
"zerocopy 0.7.35",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aho-corasick"
|
name = "aho-corasick"
|
||||||
version = "1.1.3"
|
version = "1.1.3"
|
||||||
@@ -52,6 +64,12 @@ dependencies = [
|
|||||||
"alloc-no-stdlib",
|
"alloc-no-stdlib",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "allocator-api2"
|
||||||
|
version = "0.2.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "android-tzdata"
|
name = "android-tzdata"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
@@ -97,7 +115,7 @@ version = "0.7.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "435a87a52755b8f27fcf321ac4f04b2802e337c8c4872923137471ec39c37532"
|
checksum = "435a87a52755b8f27fcf321ac4f04b2802e337c8c4872923137471ec39c37532"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"event-listener",
|
"event-listener 5.4.0",
|
||||||
"event-listener-strategy",
|
"event-listener-strategy",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
@@ -164,11 +182,20 @@ version = "3.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18"
|
checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"event-listener",
|
"event-listener 5.4.0",
|
||||||
"event-listener-strategy",
|
"event-listener-strategy",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "async-mutex"
|
||||||
|
version = "1.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "479db852db25d9dbf6204e6cb6253698f175c15726470f78af0d918e99d6156e"
|
||||||
|
dependencies = [
|
||||||
|
"event-listener 2.5.3",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-process"
|
name = "async-process"
|
||||||
version = "2.3.0"
|
version = "2.3.0"
|
||||||
@@ -182,7 +209,7 @@ dependencies = [
|
|||||||
"async-task",
|
"async-task",
|
||||||
"blocking",
|
"blocking",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"event-listener",
|
"event-listener 5.4.0",
|
||||||
"futures-lite",
|
"futures-lite",
|
||||||
"rustix 0.38.44",
|
"rustix 0.38.44",
|
||||||
"tracing",
|
"tracing",
|
||||||
@@ -425,6 +452,42 @@ dependencies = [
|
|||||||
"pkg-config",
|
"pkg-config",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cached"
|
||||||
|
version = "0.52.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a8466736fe5dbcaf8b8ee24f9bbefe43c884dc3e9ff7178da70f55bffca1133c"
|
||||||
|
dependencies = [
|
||||||
|
"ahash",
|
||||||
|
"async-trait",
|
||||||
|
"cached_proc_macro",
|
||||||
|
"cached_proc_macro_types",
|
||||||
|
"futures",
|
||||||
|
"hashbrown 0.14.5",
|
||||||
|
"instant",
|
||||||
|
"once_cell",
|
||||||
|
"thiserror 1.0.69",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cached_proc_macro"
|
||||||
|
version = "0.22.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "575f32e012222055211b70f5b0601f951f84523410a0e65c81f2744a6042450d"
|
||||||
|
dependencies = [
|
||||||
|
"darling",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.100",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cached_proc_macro_types"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ade8366b8bd5ba243f0a58f036cc0ca8a2f069cff1a2351ef1cac6b083e16fc0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cairo-rs"
|
name = "cairo-rs"
|
||||||
version = "0.18.5"
|
version = "0.18.5"
|
||||||
@@ -977,6 +1040,12 @@ dependencies = [
|
|||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "event-listener"
|
||||||
|
version = "2.5.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "event-listener"
|
name = "event-listener"
|
||||||
version = "5.4.0"
|
version = "5.4.0"
|
||||||
@@ -994,7 +1063,7 @@ version = "0.5.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93"
|
checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"event-listener",
|
"event-listener 5.4.0",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1085,6 +1154,21 @@ dependencies = [
|
|||||||
"new_debug_unreachable",
|
"new_debug_unreachable",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures"
|
||||||
|
version = "0.3.31"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876"
|
||||||
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
|
"futures-core",
|
||||||
|
"futures-executor",
|
||||||
|
"futures-io",
|
||||||
|
"futures-sink",
|
||||||
|
"futures-task",
|
||||||
|
"futures-util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-channel"
|
name = "futures-channel"
|
||||||
version = "0.3.31"
|
version = "0.3.31"
|
||||||
@@ -1092,6 +1176,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"
|
checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
"futures-sink",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1159,6 +1244,7 @@ version = "0.3.31"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
|
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-io",
|
"futures-io",
|
||||||
"futures-macro",
|
"futures-macro",
|
||||||
@@ -1306,8 +1392,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
|
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
|
"js-sys",
|
||||||
"libc",
|
"libc",
|
||||||
"wasi 0.11.0+wasi-snapshot-preview1",
|
"wasi 0.11.0+wasi-snapshot-preview1",
|
||||||
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1317,9 +1405,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0"
|
checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
|
"js-sys",
|
||||||
"libc",
|
"libc",
|
||||||
"r-efi",
|
"r-efi",
|
||||||
"wasi 0.14.2+wasi-0.2.4",
|
"wasi 0.14.2+wasi-0.2.4",
|
||||||
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1482,6 +1572,16 @@ version = "0.12.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashbrown"
|
||||||
|
version = "0.14.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||||
|
dependencies = [
|
||||||
|
"ahash",
|
||||||
|
"allocator-api2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.15.2"
|
version = "0.15.2"
|
||||||
@@ -1594,6 +1694,24 @@ dependencies = [
|
|||||||
"want",
|
"want",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hyper-rustls"
|
||||||
|
version = "0.27.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2d191583f3da1305256f22463b9bb0471acad48a4e534a5218b9963e9c1f59b2"
|
||||||
|
dependencies = [
|
||||||
|
"futures-util",
|
||||||
|
"http",
|
||||||
|
"hyper",
|
||||||
|
"hyper-util",
|
||||||
|
"rustls",
|
||||||
|
"rustls-pki-types",
|
||||||
|
"tokio",
|
||||||
|
"tokio-rustls",
|
||||||
|
"tower-service",
|
||||||
|
"webpki-roots",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper-util"
|
name = "hyper-util"
|
||||||
version = "0.1.10"
|
version = "0.1.10"
|
||||||
@@ -1832,6 +1950,15 @@ dependencies = [
|
|||||||
"generic-array",
|
"generic-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "instant"
|
||||||
|
version = "0.1.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ipnet"
|
name = "ipnet"
|
||||||
version = "2.11.0"
|
version = "2.11.0"
|
||||||
@@ -2779,7 +2906,14 @@ dependencies = [
|
|||||||
name = "plugsnatcher"
|
name = "plugsnatcher"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"async-mutex",
|
||||||
|
"async-trait",
|
||||||
|
"base64 0.21.7",
|
||||||
|
"cached",
|
||||||
|
"futures",
|
||||||
"regex",
|
"regex",
|
||||||
|
"reqwest",
|
||||||
|
"semver",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sha2",
|
"sha2",
|
||||||
@@ -2787,6 +2921,9 @@ dependencies = [
|
|||||||
"tauri-build",
|
"tauri-build",
|
||||||
"tauri-plugin-dialog",
|
"tauri-plugin-dialog",
|
||||||
"tauri-plugin-opener",
|
"tauri-plugin-opener",
|
||||||
|
"tokio",
|
||||||
|
"url",
|
||||||
|
"urlencoding",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
"yaml-rust",
|
"yaml-rust",
|
||||||
"zip",
|
"zip",
|
||||||
@@ -2832,7 +2969,7 @@ version = "0.2.21"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
|
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"zerocopy",
|
"zerocopy 0.8.24",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2917,6 +3054,60 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quinn"
|
||||||
|
version = "0.11.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c3bd15a6f2967aef83887dcb9fec0014580467e33720d073560cf015a5683012"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"cfg_aliases",
|
||||||
|
"pin-project-lite",
|
||||||
|
"quinn-proto",
|
||||||
|
"quinn-udp",
|
||||||
|
"rustc-hash",
|
||||||
|
"rustls",
|
||||||
|
"socket2",
|
||||||
|
"thiserror 2.0.12",
|
||||||
|
"tokio",
|
||||||
|
"tracing",
|
||||||
|
"web-time",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quinn-proto"
|
||||||
|
version = "0.11.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b820744eb4dc9b57a3398183639c511b5a26d2ed702cedd3febaa1393caa22cc"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"getrandom 0.3.2",
|
||||||
|
"rand 0.9.0",
|
||||||
|
"ring",
|
||||||
|
"rustc-hash",
|
||||||
|
"rustls",
|
||||||
|
"rustls-pki-types",
|
||||||
|
"slab",
|
||||||
|
"thiserror 2.0.12",
|
||||||
|
"tinyvec",
|
||||||
|
"tracing",
|
||||||
|
"web-time",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quinn-udp"
|
||||||
|
version = "0.5.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "541d0f57c6ec747a90738a52741d3221f7960e8ac2f0ff4b1a63680e033b4ab5"
|
||||||
|
dependencies = [
|
||||||
|
"cfg_aliases",
|
||||||
|
"libc",
|
||||||
|
"once_cell",
|
||||||
|
"socket2",
|
||||||
|
"tracing",
|
||||||
|
"windows-sys 0.59.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.40"
|
version = "1.0.40"
|
||||||
@@ -2965,7 +3156,7 @@ checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"rand_chacha 0.9.0",
|
"rand_chacha 0.9.0",
|
||||||
"rand_core 0.9.3",
|
"rand_core 0.9.3",
|
||||||
"zerocopy",
|
"zerocopy 0.8.24",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3112,6 +3303,7 @@ dependencies = [
|
|||||||
"http-body",
|
"http-body",
|
||||||
"http-body-util",
|
"http-body-util",
|
||||||
"hyper",
|
"hyper",
|
||||||
|
"hyper-rustls",
|
||||||
"hyper-util",
|
"hyper-util",
|
||||||
"ipnet",
|
"ipnet",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
@@ -3120,11 +3312,16 @@ dependencies = [
|
|||||||
"once_cell",
|
"once_cell",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
|
"quinn",
|
||||||
|
"rustls",
|
||||||
|
"rustls-pemfile",
|
||||||
|
"rustls-pki-types",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_urlencoded",
|
"serde_urlencoded",
|
||||||
"sync_wrapper",
|
"sync_wrapper",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tokio-rustls",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
"tower",
|
"tower",
|
||||||
"tower-service",
|
"tower-service",
|
||||||
@@ -3133,6 +3330,7 @@ dependencies = [
|
|||||||
"wasm-bindgen-futures",
|
"wasm-bindgen-futures",
|
||||||
"wasm-streams",
|
"wasm-streams",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
|
"webpki-roots",
|
||||||
"windows-registry",
|
"windows-registry",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -3161,12 +3359,32 @@ dependencies = [
|
|||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ring"
|
||||||
|
version = "0.17.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"cfg-if",
|
||||||
|
"getrandom 0.2.15",
|
||||||
|
"libc",
|
||||||
|
"untrusted",
|
||||||
|
"windows-sys 0.52.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-demangle"
|
name = "rustc-demangle"
|
||||||
version = "0.1.24"
|
version = "0.1.24"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
|
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc-hash"
|
||||||
|
version = "2.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc_version"
|
name = "rustc_version"
|
||||||
version = "0.4.1"
|
version = "0.4.1"
|
||||||
@@ -3202,6 +3420,49 @@ dependencies = [
|
|||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustls"
|
||||||
|
version = "0.23.25"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "822ee9188ac4ec04a2f0531e55d035fb2de73f18b41a63c70c2712503b6fb13c"
|
||||||
|
dependencies = [
|
||||||
|
"once_cell",
|
||||||
|
"ring",
|
||||||
|
"rustls-pki-types",
|
||||||
|
"rustls-webpki",
|
||||||
|
"subtle",
|
||||||
|
"zeroize",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustls-pemfile"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50"
|
||||||
|
dependencies = [
|
||||||
|
"rustls-pki-types",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustls-pki-types"
|
||||||
|
version = "1.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c"
|
||||||
|
dependencies = [
|
||||||
|
"web-time",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustls-webpki"
|
||||||
|
version = "0.103.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fef8b8769aaccf73098557a87cd1816b4f9c7c16811c9c77142aa695c16f2c03"
|
||||||
|
dependencies = [
|
||||||
|
"ring",
|
||||||
|
"rustls-pki-types",
|
||||||
|
"untrusted",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustversion"
|
name = "rustversion"
|
||||||
version = "1.0.20"
|
version = "1.0.20"
|
||||||
@@ -4131,6 +4392,21 @@ dependencies = [
|
|||||||
"zerovec",
|
"zerovec",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tinyvec"
|
||||||
|
version = "1.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "09b3661f17e86524eccd4371ab0429194e0d7c008abb45f7a7495b1719463c71"
|
||||||
|
dependencies = [
|
||||||
|
"tinyvec_macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tinyvec_macros"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio"
|
name = "tokio"
|
||||||
version = "1.44.1"
|
version = "1.44.1"
|
||||||
@@ -4141,13 +4417,36 @@ dependencies = [
|
|||||||
"bytes",
|
"bytes",
|
||||||
"libc",
|
"libc",
|
||||||
"mio",
|
"mio",
|
||||||
|
"parking_lot",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"signal-hook-registry",
|
"signal-hook-registry",
|
||||||
"socket2",
|
"socket2",
|
||||||
|
"tokio-macros",
|
||||||
"tracing",
|
"tracing",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio-macros"
|
||||||
|
version = "2.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.100",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio-rustls"
|
||||||
|
version = "0.26.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e727b36a1a0e8b74c376ac2211e40c2c8af09fb4013c60d910495810f008e9b"
|
||||||
|
dependencies = [
|
||||||
|
"rustls",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-util"
|
name = "tokio-util"
|
||||||
version = "0.7.14"
|
version = "0.7.14"
|
||||||
@@ -4379,6 +4678,12 @@ version = "1.12.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493"
|
checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "untrusted"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "url"
|
name = "url"
|
||||||
version = "2.5.4"
|
version = "2.5.4"
|
||||||
@@ -4391,6 +4696,12 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "urlencoding"
|
||||||
|
version = "2.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "urlpattern"
|
name = "urlpattern"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
@@ -4597,6 +4908,16 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "web-time"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb"
|
||||||
|
dependencies = [
|
||||||
|
"js-sys",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "webkit2gtk"
|
name = "webkit2gtk"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
@@ -4641,6 +4962,15 @@ dependencies = [
|
|||||||
"system-deps",
|
"system-deps",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "webpki-roots"
|
||||||
|
version = "0.26.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2210b291f7ea53617fbafcc4939f10914214ec15aace5ba62293a668f322c5c9"
|
||||||
|
dependencies = [
|
||||||
|
"rustls-pki-types",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "webview2-com"
|
name = "webview2-com"
|
||||||
version = "0.36.0"
|
version = "0.36.0"
|
||||||
@@ -5305,7 +5635,7 @@ dependencies = [
|
|||||||
"async-trait",
|
"async-trait",
|
||||||
"blocking",
|
"blocking",
|
||||||
"enumflags2",
|
"enumflags2",
|
||||||
"event-listener",
|
"event-listener 5.4.0",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-lite",
|
"futures-lite",
|
||||||
"hex",
|
"hex",
|
||||||
@@ -5352,13 +5682,33 @@ dependencies = [
|
|||||||
"zvariant",
|
"zvariant",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy"
|
||||||
|
version = "0.7.35"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
|
||||||
|
dependencies = [
|
||||||
|
"zerocopy-derive 0.7.35",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zerocopy"
|
name = "zerocopy"
|
||||||
version = "0.8.24"
|
version = "0.8.24"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879"
|
checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"zerocopy-derive",
|
"zerocopy-derive 0.8.24",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy-derive"
|
||||||
|
version = "0.7.35"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.100",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -5393,6 +5743,12 @@ dependencies = [
|
|||||||
"synstructure",
|
"synstructure",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zeroize"
|
||||||
|
version = "1.8.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zerovec"
|
name = "zerovec"
|
||||||
version = "0.10.4"
|
version = "0.10.4"
|
||||||
|
|||||||
+19
-2
@@ -25,7 +25,24 @@ serde = { version = "1", features = ["derive"] }
|
|||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
zip = "0.6"
|
zip = "0.6"
|
||||||
yaml-rust = "0.4"
|
yaml-rust = "0.4"
|
||||||
walkdir = "2.4"
|
# walkdir = "2.4" # Not currently used, commented out
|
||||||
regex = "1.10"
|
regex = "1.10" # Still needed elsewhere in the codebase
|
||||||
sha2 = "0.10"
|
sha2 = "0.10"
|
||||||
|
reqwest = { version = "0.12", features = ["json", "rustls-tls"], default-features = false } # Updated version, enabled rustls
|
||||||
|
# scraper = "0.19.0" # No longer used for SpigotMCCrawler
|
||||||
|
urlencoding = "2.1.3" # Reverted version
|
||||||
|
semver = "1.0"
|
||||||
|
url = "2.5"
|
||||||
|
futures = "0.3"
|
||||||
|
async-trait = "0.1"
|
||||||
|
tokio = { version = "1", features = ["rt-multi-thread", "macros", "time"] } # Changed features from "full"
|
||||||
|
# --- Add Caching Dependencies ---
|
||||||
|
cached = { version = "0.52", features = ["proc_macro", "async", "tokio"] }
|
||||||
|
async-mutex = "1.4" # For locking cache access within HttpClient
|
||||||
|
# --- End Caching Dependencies ---
|
||||||
|
base64 = "0.21" # For decoding SpigotMC changelog data
|
||||||
|
walkdir = "2.5.0"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
# default = ["custom-protocol"]
|
||||||
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod plugin_commands;
|
||||||
|
pub mod scan_commands;
|
||||||
@@ -0,0 +1,336 @@
|
|||||||
|
use tauri::{command, AppHandle};
|
||||||
|
use crate::models::repository::RepositorySource;
|
||||||
|
use crate::models::server::ServerType;
|
||||||
|
use crate::models::plugin::Plugin;
|
||||||
|
use crate::services::update_manager::{compare_plugin_versions, backup_plugin, replace_plugin};
|
||||||
|
|
||||||
|
/// Search for plugins in specified repositories
|
||||||
|
#[command]
|
||||||
|
pub async fn search_plugins(query: String, repositories: Vec<RepositorySource>) -> Result<Vec<crate::models::repository::RepositoryPlugin>, String> {
|
||||||
|
crate::lib_search_plugins_in_repositories(&query, repositories).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get plugin details from a repository
|
||||||
|
#[command]
|
||||||
|
pub async fn get_plugin_details(
|
||||||
|
plugin_id: String,
|
||||||
|
repository: RepositorySource,
|
||||||
|
server_type_str: Option<String>,
|
||||||
|
) -> Result<crate::models::repository::RepositoryPlugin, String> {
|
||||||
|
// Convert server_type_str to ServerType if provided
|
||||||
|
let server_type = if let Some(type_str) = server_type_str {
|
||||||
|
match type_str.as_str() {
|
||||||
|
"paper" => Some(crate::models::server::ServerType::Paper),
|
||||||
|
"spigot" => Some(crate::models::server::ServerType::Spigot),
|
||||||
|
"bukkit" => Some(crate::models::server::ServerType::Bukkit),
|
||||||
|
"velocity" => Some(crate::models::server::ServerType::Velocity),
|
||||||
|
"bungeecord" => Some(crate::models::server::ServerType::BungeeCord),
|
||||||
|
"waterfall" => Some(crate::models::server::ServerType::Waterfall),
|
||||||
|
"forge" => Some(crate::models::server::ServerType::Forge),
|
||||||
|
"fabric" => Some(crate::models::server::ServerType::Fabric),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
crate::lib_get_plugin_details_from_repository(&plugin_id, repository, server_type.as_ref()).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Download a plugin from a repository
|
||||||
|
#[command]
|
||||||
|
pub async fn download_plugin(
|
||||||
|
plugin_id: String,
|
||||||
|
version: String,
|
||||||
|
repository: String,
|
||||||
|
destination: String,
|
||||||
|
server_type_str: Option<String>
|
||||||
|
) -> Result<String, String> {
|
||||||
|
// Convert repository string to RepositorySource
|
||||||
|
let repo_source = match repository.to_lowercase().as_str() {
|
||||||
|
"hangarmc" => RepositorySource::HangarMC,
|
||||||
|
"spigotmc" => RepositorySource::SpigotMC,
|
||||||
|
"modrinth" => RepositorySource::Modrinth,
|
||||||
|
"github" => RepositorySource::GitHub,
|
||||||
|
"bukkitdev" => RepositorySource::BukkitDev,
|
||||||
|
_ => RepositorySource::Custom(repository.clone()),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Convert server_type_str to ServerType if provided
|
||||||
|
let server_type = if let Some(type_str) = server_type_str {
|
||||||
|
match type_str.as_str() {
|
||||||
|
"paper" => Some(ServerType::Paper),
|
||||||
|
"spigot" => Some(ServerType::Spigot),
|
||||||
|
"bukkit" => Some(ServerType::Bukkit),
|
||||||
|
"velocity" => Some(ServerType::Velocity),
|
||||||
|
"bungeecord" => Some(ServerType::BungeeCord),
|
||||||
|
"waterfall" => Some(ServerType::Waterfall),
|
||||||
|
"forge" => Some(ServerType::Forge),
|
||||||
|
"fabric" => Some(ServerType::Fabric),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
crate::lib_download_plugin_from_repository(&plugin_id, &version, repo_source, &destination, server_type.as_ref()).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update a plugin with a new version
|
||||||
|
#[command]
|
||||||
|
pub async fn update_plugin(
|
||||||
|
app_handle: AppHandle,
|
||||||
|
plugin_id: String,
|
||||||
|
version: String,
|
||||||
|
repository: String,
|
||||||
|
current_file_path: String,
|
||||||
|
server_type_str: Option<String>
|
||||||
|
) -> Result<String, String> {
|
||||||
|
// Convert repository string to RepositorySource
|
||||||
|
let repo_source = match repository.to_lowercase().as_str() {
|
||||||
|
"hangarmc" => RepositorySource::HangarMC,
|
||||||
|
"spigotmc" => RepositorySource::SpigotMC,
|
||||||
|
"modrinth" => RepositorySource::Modrinth,
|
||||||
|
"github" => RepositorySource::GitHub,
|
||||||
|
"bukkitdev" => RepositorySource::BukkitDev,
|
||||||
|
_ => RepositorySource::Custom(repository.clone()),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Convert server_type_str to ServerInfo if provided
|
||||||
|
let server_info = if let Some(type_str) = server_type_str {
|
||||||
|
let server_type = match type_str.as_str() {
|
||||||
|
"paper" => ServerType::Paper,
|
||||||
|
"spigot" => ServerType::Spigot,
|
||||||
|
"bukkit" => ServerType::Bukkit,
|
||||||
|
"velocity" => ServerType::Velocity,
|
||||||
|
"bungeecord" => ServerType::BungeeCord,
|
||||||
|
"waterfall" => ServerType::Waterfall,
|
||||||
|
"forge" => ServerType::Forge,
|
||||||
|
"fabric" => ServerType::Fabric,
|
||||||
|
_ => ServerType::Unknown,
|
||||||
|
};
|
||||||
|
|
||||||
|
Some(crate::models::server::ServerInfo {
|
||||||
|
server_type,
|
||||||
|
minecraft_version: None,
|
||||||
|
plugins_directory: "".to_string(),
|
||||||
|
plugins_count: 0,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
// Replace the plugin
|
||||||
|
replace_plugin(plugin_id, version, repo_source, current_file_path, server_info).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check for updates for multiple plugins
|
||||||
|
#[command]
|
||||||
|
pub async fn check_plugin_updates(
|
||||||
|
app_handle: AppHandle,
|
||||||
|
plugins: Vec<Plugin>,
|
||||||
|
repositories: Vec<String>
|
||||||
|
) -> Result<Vec<Plugin>, String> {
|
||||||
|
// Convert repository strings to RepositorySource
|
||||||
|
let repos: Vec<RepositorySource> = repositories.into_iter()
|
||||||
|
.map(|repo| match repo.to_lowercase().as_str() {
|
||||||
|
"hangarmc" => RepositorySource::HangarMC,
|
||||||
|
"spigotmc" => RepositorySource::SpigotMC,
|
||||||
|
"modrinth" => RepositorySource::Modrinth,
|
||||||
|
"github" => RepositorySource::GitHub,
|
||||||
|
"bukkitdev" => RepositorySource::BukkitDev,
|
||||||
|
_ => RepositorySource::Custom(repo),
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
crate::services::update_manager::check_for_plugin_updates(app_handle, plugins, repos).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check for updates for a single plugin
|
||||||
|
#[command]
|
||||||
|
pub async fn check_single_plugin_update_command(
|
||||||
|
app_handle: AppHandle,
|
||||||
|
plugin: Plugin,
|
||||||
|
repositories: Vec<String>
|
||||||
|
) -> Result<(), String> {
|
||||||
|
// Convert repository strings to RepositorySource
|
||||||
|
let repos: Vec<RepositorySource> = repositories.into_iter()
|
||||||
|
.map(|repo| match repo.to_lowercase().as_str() {
|
||||||
|
"hangarmc" => RepositorySource::HangarMC,
|
||||||
|
"spigotmc" => RepositorySource::SpigotMC,
|
||||||
|
"modrinth" => RepositorySource::Modrinth,
|
||||||
|
"github" => RepositorySource::GitHub,
|
||||||
|
"bukkitdev" => RepositorySource::BukkitDev,
|
||||||
|
_ => RepositorySource::Custom(repo),
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
crate::services::update_manager::check_single_plugin_update(app_handle, plugin, repos).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a backup of a plugin file
|
||||||
|
#[command]
|
||||||
|
pub async fn backup_plugin_command(plugin_file_path: String) -> Result<String, String> {
|
||||||
|
backup_plugin(plugin_file_path).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set repository source for a plugin
|
||||||
|
#[command]
|
||||||
|
pub async fn set_plugin_repository(
|
||||||
|
app_handle: AppHandle,
|
||||||
|
plugin_file_path: String,
|
||||||
|
repository: String,
|
||||||
|
repository_id: String,
|
||||||
|
page_url: String,
|
||||||
|
server_path: String
|
||||||
|
) -> Result<Plugin, String> {
|
||||||
|
// Convert repository string to RepositorySource
|
||||||
|
let repo_source = match repository.to_lowercase().as_str() {
|
||||||
|
"hangarmc" => RepositorySource::HangarMC,
|
||||||
|
"spigotmc" => RepositorySource::SpigotMC,
|
||||||
|
"modrinth" => RepositorySource::Modrinth,
|
||||||
|
"github" => RepositorySource::GitHub,
|
||||||
|
"bukkitdev" => RepositorySource::BukkitDev,
|
||||||
|
_ => RepositorySource::Custom(repository.clone()),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Load the plugin data
|
||||||
|
let plugins = crate::services::plugin_scanner::perform_scan(&app_handle, &server_path).await?.plugins;
|
||||||
|
|
||||||
|
// Find the specific plugin
|
||||||
|
let mut plugin = plugins.into_iter()
|
||||||
|
.find(|p| p.file_path == plugin_file_path)
|
||||||
|
.ok_or_else(|| format!("Plugin not found: {}", plugin_file_path))?;
|
||||||
|
|
||||||
|
// Update repository information
|
||||||
|
plugin.repository_source = Some(repo_source);
|
||||||
|
plugin.repository_id = Some(repository_id);
|
||||||
|
plugin.repository_url = Some(page_url);
|
||||||
|
|
||||||
|
// Trigger an update check
|
||||||
|
if let Some(repo_id) = &plugin.repository_id {
|
||||||
|
if let Some(repo_source) = &plugin.repository_source {
|
||||||
|
match crate::lib_get_plugin_details_from_repository(repo_id, repo_source.clone(), None).await {
|
||||||
|
Ok(repo_plugin) => {
|
||||||
|
// Set latest version if newer
|
||||||
|
if repo_plugin.version != plugin.version {
|
||||||
|
let has_update = compare_plugin_versions(&plugin.version, &repo_plugin.version);
|
||||||
|
plugin.latest_version = Some(repo_plugin.version);
|
||||||
|
plugin.has_update = has_update;
|
||||||
|
plugin.changelog = repo_plugin.changelog;
|
||||||
|
} else {
|
||||||
|
plugin.has_update = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
println!("Error checking for updates: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(plugin)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Load saved plugin data for a specific server
|
||||||
|
#[command]
|
||||||
|
pub async fn load_plugin_data(
|
||||||
|
app_handle: AppHandle,
|
||||||
|
server_path: String,
|
||||||
|
) -> Result<Vec<Plugin>, String> {
|
||||||
|
let data_dir = crate::services::plugin_scanner::get_plugin_data_path(&app_handle, &server_path)?;
|
||||||
|
let data_path = data_dir.join("plugins.json");
|
||||||
|
|
||||||
|
if !data_path.exists() {
|
||||||
|
// If the file doesn't exist, it's not an error, just return empty list
|
||||||
|
return Ok(Vec::new());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the file content
|
||||||
|
let json_data = std::fs::read_to_string(&data_path)
|
||||||
|
.map_err(|e| format!("Failed to read plugin data file: {}", e))?;
|
||||||
|
|
||||||
|
// Deserialize the JSON data
|
||||||
|
let plugins: Vec<Plugin> = serde_json::from_str(&json_data)
|
||||||
|
.map_err(|e| format!("Failed to deserialize plugin data: {}", e))?;
|
||||||
|
|
||||||
|
Ok(plugins)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Save plugin data for a specific server
|
||||||
|
#[command]
|
||||||
|
pub async fn save_plugin_data(
|
||||||
|
app_handle: AppHandle,
|
||||||
|
plugins: Vec<Plugin>,
|
||||||
|
server_path: String,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
let data_dir = crate::services::plugin_scanner::get_plugin_data_path(&app_handle, &server_path)?;
|
||||||
|
|
||||||
|
// Create directory if it doesn't exist
|
||||||
|
if !data_dir.exists() {
|
||||||
|
std::fs::create_dir_all(&data_dir)
|
||||||
|
.map_err(|e| format!("Failed to create plugin data directory: {}", e))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save plugins data
|
||||||
|
let data_path = data_dir.join("plugins.json");
|
||||||
|
let json_data = serde_json::to_string_pretty(&plugins)
|
||||||
|
.map_err(|e| format!("Failed to serialize plugin data for saving: {}", e))?;
|
||||||
|
|
||||||
|
std::fs::write(&data_path, json_data)
|
||||||
|
.map_err(|e| format!("Failed to write plugin data file: {}", e))?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get versions for a plugin from a repository
|
||||||
|
#[command]
|
||||||
|
pub async fn get_plugin_versions(
|
||||||
|
plugin_id: String,
|
||||||
|
repository: String
|
||||||
|
) -> Result<Vec<String>, String> {
|
||||||
|
// This is a placeholder - would need to implement the actual repository API call
|
||||||
|
Ok(vec!["1.0.0".to_string(), "1.1.0".to_string(), "1.2.0".to_string()])
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get potential matches for a plugin from repositories
|
||||||
|
#[command]
|
||||||
|
pub async fn get_potential_plugin_matches(
|
||||||
|
app_handle: AppHandle,
|
||||||
|
plugin: Plugin,
|
||||||
|
repositories: Vec<String>
|
||||||
|
) -> Result<Vec<crate::models::repository::PotentialPluginMatch>, String> {
|
||||||
|
// Convert repository strings to RepositorySource
|
||||||
|
let repos: Vec<RepositorySource> = repositories.into_iter()
|
||||||
|
.map(|repo| match repo.to_lowercase().as_str() {
|
||||||
|
"hangarmc" => RepositorySource::HangarMC,
|
||||||
|
"spigotmc" => RepositorySource::SpigotMC,
|
||||||
|
"modrinth" => RepositorySource::Modrinth,
|
||||||
|
"github" => RepositorySource::GitHub,
|
||||||
|
"bukkitdev" => RepositorySource::BukkitDev,
|
||||||
|
_ => RepositorySource::Custom(repo),
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
// This is a placeholder - would need to implement actual search
|
||||||
|
Ok(Vec::new())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Compare two version strings
|
||||||
|
#[command]
|
||||||
|
pub fn compare_versions(version1: String, version2: String) -> bool {
|
||||||
|
compare_plugin_versions(&version1, &version2)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check if a plugin is compatible with a specific Minecraft version
|
||||||
|
#[command]
|
||||||
|
pub fn is_plugin_compatible(plugin_version: String, minecraft_version: String) -> bool {
|
||||||
|
// This is a placeholder - would need to implement actual compatibility check
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Simple greeting function for testing
|
||||||
|
#[command]
|
||||||
|
pub fn greet(name: &str) -> String {
|
||||||
|
format!("Hello, {}! Welcome to PlugSnatcher.", name)
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
use tauri::{command, AppHandle};
|
||||||
|
use crate::services::plugin_scanner::{scan_server_directory, perform_scan};
|
||||||
|
|
||||||
|
/// Scan a server directory for plugins
|
||||||
|
#[command]
|
||||||
|
pub async fn scan_server_dir(app_handle: AppHandle, path: String) -> Result<(), String> {
|
||||||
|
scan_server_directory(app_handle, path).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Scan a server directory and return the result immediately
|
||||||
|
#[command]
|
||||||
|
pub async fn scan_server_dir_sync(app_handle: AppHandle, path: String) -> Result<crate::models::server::ScanResult, String> {
|
||||||
|
perform_scan(&app_handle, &path).await
|
||||||
|
}
|
||||||
@@ -0,0 +1,229 @@
|
|||||||
|
use std::error::Error;
|
||||||
|
use std::path::Path;
|
||||||
|
use serde::{Serialize, Deserialize};
|
||||||
|
use crate::{HttpClient, RepositorySource};
|
||||||
|
use urlencoding;
|
||||||
|
use async_trait::async_trait;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use crate::models::repository::RepositoryPlugin;
|
||||||
|
use crate::crawlers::Repository;
|
||||||
|
|
||||||
|
// GitHub API response structures (Based on https://docs.github.com/en/rest/releases/releases)
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct GitHubRelease {
|
||||||
|
// Structure for release details
|
||||||
|
tag_name: String,
|
||||||
|
name: Option<String>,
|
||||||
|
body: Option<String>,
|
||||||
|
published_at: String,
|
||||||
|
assets: Vec<GitHubAsset>,
|
||||||
|
html_url: String, // URL to the release page
|
||||||
|
prerelease: bool,
|
||||||
|
draft: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct GitHubAsset {
|
||||||
|
// Structure for release asset details
|
||||||
|
name: String,
|
||||||
|
browser_download_url: String,
|
||||||
|
size: u64,
|
||||||
|
updated_at: String,
|
||||||
|
download_count: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
struct GitHubRepo {
|
||||||
|
// Structure for repository details (used for searching potentially)
|
||||||
|
id: u64,
|
||||||
|
name: String,
|
||||||
|
full_name: String, // "owner/repo"
|
||||||
|
owner: GitHubUser,
|
||||||
|
description: Option<String>,
|
||||||
|
html_url: String,
|
||||||
|
stargazers_count: u64, // Can use this as a proxy for rating/popularity
|
||||||
|
updated_at: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
struct GitHubUser {
|
||||||
|
login: String,
|
||||||
|
avatar_url: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct GitHubSearchResponse {
|
||||||
|
// Structure for repository search results
|
||||||
|
items: Vec<GitHubRepo>,
|
||||||
|
// Ignoring total_count, incomplete_results for now
|
||||||
|
}
|
||||||
|
|
||||||
|
// GitHub crawler implementation
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct GitHubCrawler {
|
||||||
|
client: Arc<HttpClient>,
|
||||||
|
api_base_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inherent methods for GitHubCrawler
|
||||||
|
impl GitHubCrawler {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
GitHubCrawler {
|
||||||
|
client: Arc::new(HttpClient::new()),
|
||||||
|
api_base_url: "https://api.github.com".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to get the latest release for a repo, now async
|
||||||
|
async fn get_latest_release_details(&self, repo_full_name: &str) -> Result<GitHubRelease, Box<dyn Error + Send + Sync>> {
|
||||||
|
let url = format!("{}/repos/{}/releases/latest", self.api_base_url, repo_full_name);
|
||||||
|
let response_body = self.client.get(&url).await?;
|
||||||
|
let release: GitHubRelease = serde_json::from_str(&response_body)?;
|
||||||
|
Ok(release)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to get all releases, now async
|
||||||
|
async fn get_all_release_details(&self, repo_full_name: &str) -> Result<Vec<GitHubRelease>, Box<dyn Error + Send + Sync>> {
|
||||||
|
let url = format!("{}/repos/{}/releases?per_page=100", self.api_base_url, repo_full_name);
|
||||||
|
let response_body = self.client.get(&url).await?;
|
||||||
|
let releases: Vec<GitHubRelease> = serde_json::from_str(&response_body)?;
|
||||||
|
Ok(releases)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to get repo details, now async
|
||||||
|
async fn get_repo_details(&self, repo_full_name: &str) -> Result<GitHubRepo, Box<dyn Error + Send + Sync>> {
|
||||||
|
let repo_url = format!("{}/repos/{}", self.api_base_url, repo_full_name);
|
||||||
|
let repo_response_body = self.client.get(&repo_url).await?;
|
||||||
|
let repo: GitHubRepo = serde_json::from_str(&repo_response_body)?;
|
||||||
|
Ok(repo)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_plugin_versions(&self, repo_full_name: &str) -> Result<Vec<String>, String> {
|
||||||
|
let releases = match self.get_all_release_details(repo_full_name).await {
|
||||||
|
Ok(r) => r,
|
||||||
|
Err(e) => return Err(format!("Failed GitHub get releases for versions: {}", e)),
|
||||||
|
};
|
||||||
|
let versions = releases.into_iter()
|
||||||
|
.filter(|r| !r.draft && !r.prerelease && r.assets.iter().any(|a| a.name.ends_with(".jar")))
|
||||||
|
.map(|r| r.tag_name)
|
||||||
|
.collect();
|
||||||
|
Ok(versions)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl Repository for GitHubCrawler {
|
||||||
|
fn get_repository_name(&self) -> String {
|
||||||
|
"GitHub".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn search(&self, query: &str) -> Result<Vec<RepositoryPlugin>, String> {
|
||||||
|
let search_terms = format!("{} topic:minecraft-plugin topic:spigot topic:paper topic:bukkit fork:false", query);
|
||||||
|
let encoded_query = urlencoding::encode(&search_terms);
|
||||||
|
let url = format!(
|
||||||
|
"{}/search/repositories?q={}&sort=stars&order=desc",
|
||||||
|
self.api_base_url,
|
||||||
|
encoded_query
|
||||||
|
);
|
||||||
|
|
||||||
|
let response_body = match self.client.get(&url).await {
|
||||||
|
Ok(body) => body,
|
||||||
|
Err(e) => return Err(format!("GitHub search request failed: {}", e)),
|
||||||
|
};
|
||||||
|
let search_response: GitHubSearchResponse = match serde_json::from_str(&response_body) {
|
||||||
|
Ok(res) => res,
|
||||||
|
Err(e) => return Err(format!("Failed to parse GitHub search results: {}", e)),
|
||||||
|
};
|
||||||
|
|
||||||
|
let fetch_tasks = search_response.items.into_iter().map(|repo| {
|
||||||
|
let self_clone = self.clone();
|
||||||
|
async move {
|
||||||
|
self_clone.get_plugin_details(&repo.full_name).await
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let results: Vec<RepositoryPlugin> = futures::future::join_all(fetch_tasks).await
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|result| match result {
|
||||||
|
Ok(plugin) => Some(plugin),
|
||||||
|
Err(e) => {
|
||||||
|
println!("Error fetching details during search: {}", e);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
Ok(results)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_plugin_details(&self, plugin_id: &str) -> Result<RepositoryPlugin, String> {
|
||||||
|
let repo_full_name = plugin_id;
|
||||||
|
let repo = match self.get_repo_details(repo_full_name).await {
|
||||||
|
Ok(r) => r,
|
||||||
|
Err(e) => return Err(format!("Failed GitHub get repo details: {}", e)),
|
||||||
|
};
|
||||||
|
let mut releases = match self.get_all_release_details(repo_full_name).await {
|
||||||
|
Ok(r) => r,
|
||||||
|
Err(e) => return Err(format!("Failed GitHub get releases: {}", e)),
|
||||||
|
};
|
||||||
|
|
||||||
|
releases.sort_by(|a, b| b.published_at.cmp(&a.published_at));
|
||||||
|
|
||||||
|
let latest_valid_release = releases.into_iter()
|
||||||
|
.filter(|r| !r.draft && !r.prerelease)
|
||||||
|
.find(|r| r.assets.iter().any(|a| a.name.ends_with(".jar")));
|
||||||
|
|
||||||
|
if let Some(release) = latest_valid_release {
|
||||||
|
if let Some(asset) = release.assets.iter().find(|a| a.name.ends_with(".jar")) {
|
||||||
|
Ok(RepositoryPlugin {
|
||||||
|
id: repo_full_name.to_string(),
|
||||||
|
name: repo.name,
|
||||||
|
version: release.tag_name,
|
||||||
|
description: repo.description,
|
||||||
|
authors: vec![repo.owner.login],
|
||||||
|
download_url: asset.browser_download_url.clone(),
|
||||||
|
repository: RepositorySource::GitHub,
|
||||||
|
page_url: repo.html_url,
|
||||||
|
download_count: Some(asset.download_count),
|
||||||
|
last_updated: Some(release.published_at),
|
||||||
|
icon_url: repo.owner.avatar_url,
|
||||||
|
minecraft_versions: Vec::new(),
|
||||||
|
categories: Vec::new(),
|
||||||
|
rating: Some(repo.stargazers_count as f32),
|
||||||
|
file_size: Some(asset.size),
|
||||||
|
file_hash: None,
|
||||||
|
changelog: release.body,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Err(format!("No suitable JAR asset found in the latest valid release for {}", repo_full_name))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(format!("No valid release with a JAR asset found for {}", repo_full_name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn download_plugin(&self, plugin_id: &str, version_number_str: &str, destination: &Path) -> Result<String, String> {
|
||||||
|
let repo_full_name = plugin_id;
|
||||||
|
let tag_name = version_number_str;
|
||||||
|
|
||||||
|
let release_url = format!("{}/repos/{}/releases/tags/{}", self.api_base_url, repo_full_name, tag_name);
|
||||||
|
let release_response_body = match self.client.get(&release_url).await {
|
||||||
|
Ok(body) => body,
|
||||||
|
Err(e) => return Err(format!("GitHub get release by tag failed: {}", e)),
|
||||||
|
};
|
||||||
|
let release: GitHubRelease = match serde_json::from_str(&release_response_body) {
|
||||||
|
Ok(r) => r,
|
||||||
|
Err(e) => return Err(format!("Failed to parse GitHub release by tag: {}", e)),
|
||||||
|
};
|
||||||
|
|
||||||
|
let asset = release.assets.iter()
|
||||||
|
.find(|a| a.name.ends_with(".jar"))
|
||||||
|
.ok_or_else(|| format!("No suitable JAR asset found in release tag '{}' for {}", tag_name, repo_full_name))?;
|
||||||
|
|
||||||
|
match self.client.download(&asset.browser_download_url, destination).await {
|
||||||
|
Ok(_) => Ok(destination.to_string_lossy().to_string()),
|
||||||
|
Err(e) => Err(format!("Failed to download from GitHub: {}", e))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,220 @@
|
|||||||
|
use std::error::Error;
|
||||||
|
use std::path::Path;
|
||||||
|
use serde::{Serialize, Deserialize};
|
||||||
|
use crate::HttpClient;
|
||||||
|
use crate::models::repository::{RepositoryPlugin, RepositorySource};
|
||||||
|
use crate::crawlers::Repository;
|
||||||
|
use urlencoding;
|
||||||
|
use async_trait::async_trait;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
// HangarMC API response structures
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct HangarProjectsResponse {
|
||||||
|
pagination: HangarPagination,
|
||||||
|
result: Vec<HangarProject>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct HangarPagination {
|
||||||
|
limit: u32,
|
||||||
|
offset: u32,
|
||||||
|
count: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct HangarProject {
|
||||||
|
id: String,
|
||||||
|
name: String,
|
||||||
|
namespace: HangarNamespace,
|
||||||
|
category: String,
|
||||||
|
description: Option<String>,
|
||||||
|
stats: HangarStats,
|
||||||
|
last_updated: String,
|
||||||
|
icon_url: Option<String>,
|
||||||
|
created_at: String,
|
||||||
|
visibility: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct HangarNamespace {
|
||||||
|
owner: String,
|
||||||
|
slug: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct HangarStats {
|
||||||
|
views: u64,
|
||||||
|
downloads: u64,
|
||||||
|
recent_views: u64,
|
||||||
|
recent_downloads: u64,
|
||||||
|
stars: u64,
|
||||||
|
watchers: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct HangarVersionsResponse {
|
||||||
|
pagination: HangarPagination,
|
||||||
|
result: Vec<HangarVersion>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct HangarVersion {
|
||||||
|
name: String,
|
||||||
|
created_at: String,
|
||||||
|
description: Option<String>,
|
||||||
|
downloads: u64,
|
||||||
|
file_size: u64,
|
||||||
|
platform_versions: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hangar crawler implementation
|
||||||
|
pub struct HangarCrawler {
|
||||||
|
client: Arc<HttpClient>,
|
||||||
|
api_base_url: String,
|
||||||
|
web_base_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HangarCrawler {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
HangarCrawler {
|
||||||
|
client: Arc::new(HttpClient::new()),
|
||||||
|
api_base_url: "https://hangar.papermc.io/api/v1".to_string(),
|
||||||
|
web_base_url: "https://hangar.papermc.io".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_project_details_internal(&self, author: &str, slug: &str) -> Result<HangarProject, Box<dyn Error + Send + Sync>> {
|
||||||
|
let url = format!("{}/projects/{}/{}", self.api_base_url, author, slug);
|
||||||
|
let response_body = self.client.get(&url).await?;
|
||||||
|
let project: HangarProject = serde_json::from_str(&response_body)?;
|
||||||
|
Ok(project)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_project_versions_internal(&self, author: &str, slug: &str) -> Result<Vec<HangarVersion>, Box<dyn Error + Send + Sync>> {
|
||||||
|
let url = format!("{}/projects/{}/{}/versions?limit=25&offset=0", self.api_base_url, author, slug);
|
||||||
|
let response_body = self.client.get(&url).await?;
|
||||||
|
let versions_result: HangarVersionsResponse = serde_json::from_str(&response_body)?;
|
||||||
|
Ok(versions_result.result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl Repository for HangarCrawler {
|
||||||
|
fn get_repository_name(&self) -> String {
|
||||||
|
"HangarMC".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn search(&self, query: &str) -> Result<Vec<RepositoryPlugin>, String> {
|
||||||
|
let encoded_query = urlencoding::encode(query);
|
||||||
|
let url = format!(
|
||||||
|
"{}/projects?q={}",
|
||||||
|
self.api_base_url,
|
||||||
|
encoded_query
|
||||||
|
);
|
||||||
|
|
||||||
|
let response_body = match self.client.get(&url).await {
|
||||||
|
Ok(body) => body,
|
||||||
|
Err(e) => return Err(format!("Failed to search HangarMC: {}", e)),
|
||||||
|
};
|
||||||
|
|
||||||
|
let search_response: HangarProjectsResponse = match serde_json::from_str(&response_body) {
|
||||||
|
Ok(res) => res,
|
||||||
|
Err(e) => return Err(format!("Failed to parse HangarMC search results: {}", e)),
|
||||||
|
};
|
||||||
|
|
||||||
|
let results: Vec<RepositoryPlugin> = search_response.result.into_iter().map(|proj| {
|
||||||
|
let page_url = format!("{}/{}/{}", self.web_base_url, proj.namespace.owner, proj.namespace.slug);
|
||||||
|
let version = "Unknown".to_string();
|
||||||
|
RepositoryPlugin {
|
||||||
|
id: format!("{}/{}", proj.namespace.owner, proj.namespace.slug),
|
||||||
|
name: proj.name,
|
||||||
|
version,
|
||||||
|
description: proj.description.clone(),
|
||||||
|
authors: vec![proj.namespace.owner],
|
||||||
|
download_url: String::new(),
|
||||||
|
repository: RepositorySource::HangarMC,
|
||||||
|
page_url,
|
||||||
|
download_count: Some(proj.stats.downloads),
|
||||||
|
last_updated: Some(proj.last_updated),
|
||||||
|
icon_url: proj.icon_url.clone(),
|
||||||
|
minecraft_versions: Vec::new(),
|
||||||
|
categories: vec![proj.category.to_string()],
|
||||||
|
rating: Some(proj.stats.stars as f32),
|
||||||
|
file_size: None,
|
||||||
|
file_hash: None,
|
||||||
|
changelog: None,
|
||||||
|
}
|
||||||
|
}).collect();
|
||||||
|
|
||||||
|
Ok(results)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_plugin_details(&self, plugin_id: &str) -> Result<RepositoryPlugin, String> {
|
||||||
|
let parts: Vec<&str> = plugin_id.split('/').collect();
|
||||||
|
if parts.len() != 2 {
|
||||||
|
return Err(format!("Invalid Hangar plugin ID format: {}. Expected 'author/slug'.", plugin_id));
|
||||||
|
}
|
||||||
|
let author = parts[0];
|
||||||
|
let slug = parts[1];
|
||||||
|
|
||||||
|
let project = match self.get_project_details_internal(author, slug).await {
|
||||||
|
Ok(p) => p,
|
||||||
|
Err(e) => return Err(format!("Failed to get Hangar project details: {}", e)),
|
||||||
|
};
|
||||||
|
|
||||||
|
let versions = match self.get_project_versions_internal(author, slug).await {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(e) => return Err(format!("Failed to get Hangar project versions: {}", e)),
|
||||||
|
};
|
||||||
|
|
||||||
|
let latest_version_name = versions.first().map_or("Unknown".to_string(), |v| v.name.clone());
|
||||||
|
|
||||||
|
let page_url = format!("{}/{}/{}", self.web_base_url, author, slug);
|
||||||
|
|
||||||
|
Ok(RepositoryPlugin {
|
||||||
|
id: plugin_id.to_string(),
|
||||||
|
name: project.name,
|
||||||
|
version: latest_version_name,
|
||||||
|
description: project.description.clone(),
|
||||||
|
authors: vec![project.namespace.owner],
|
||||||
|
download_url: String::new(),
|
||||||
|
repository: RepositorySource::HangarMC,
|
||||||
|
page_url,
|
||||||
|
download_count: Some(project.stats.downloads),
|
||||||
|
last_updated: Some(project.last_updated),
|
||||||
|
icon_url: project.icon_url.clone(),
|
||||||
|
minecraft_versions: versions.first().map_or(Vec::new(), |v| v.platform_versions.clone()),
|
||||||
|
categories: vec![project.category.to_string()],
|
||||||
|
rating: Some(project.stats.stars as f32),
|
||||||
|
file_size: versions.first().map(|v| v.file_size),
|
||||||
|
file_hash: None,
|
||||||
|
changelog: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn download_plugin(&self, plugin_id: &str, version: &str, destination: &Path) -> Result<String, String> {
|
||||||
|
let parts: Vec<&str> = plugin_id.split('/').collect();
|
||||||
|
if parts.len() != 2 {
|
||||||
|
return Err(format!("Invalid Hangar plugin ID format: {}. Expected 'author/slug'.", plugin_id));
|
||||||
|
}
|
||||||
|
let author = parts[0];
|
||||||
|
let slug = parts[1];
|
||||||
|
|
||||||
|
let platform_str = "PAPER";
|
||||||
|
|
||||||
|
let download_url = format!(
|
||||||
|
"{}/projects/{}/{}/versions/{}/{}/download",
|
||||||
|
self.api_base_url,
|
||||||
|
author,
|
||||||
|
slug,
|
||||||
|
version,
|
||||||
|
platform_str
|
||||||
|
);
|
||||||
|
|
||||||
|
match self.client.download(&download_url, destination).await {
|
||||||
|
Ok(_) => Ok(destination.to_string_lossy().to_string()),
|
||||||
|
Err(e) => Err(format!("Failed to download plugin: {}", e))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
pub mod hangar;
|
||||||
|
pub mod spigotmc;
|
||||||
|
pub mod modrinth;
|
||||||
|
pub mod github;
|
||||||
|
|
||||||
|
use std::path::Path;
|
||||||
|
use crate::models::repository::RepositoryPlugin;
|
||||||
|
use crate::models::server::ServerType;
|
||||||
|
use async_trait::async_trait;
|
||||||
|
|
||||||
|
/// Common interface for all repository crawlers
|
||||||
|
#[async_trait]
|
||||||
|
pub trait Repository {
|
||||||
|
/// Get the name of the repository
|
||||||
|
fn get_repository_name(&self) -> String;
|
||||||
|
|
||||||
|
/// Search for plugins in the repository
|
||||||
|
async fn search(&self, query: &str) -> Result<Vec<RepositoryPlugin>, String>;
|
||||||
|
|
||||||
|
/// Get plugin details from the repository
|
||||||
|
async fn get_plugin_details(&self, plugin_id: &str) -> Result<RepositoryPlugin, String>;
|
||||||
|
|
||||||
|
/// Get plugin details with server type consideration
|
||||||
|
async fn get_plugin_details_with_server_type(&self, plugin_id: &str, server_type: Option<&ServerType>) -> Result<RepositoryPlugin, String> {
|
||||||
|
// Default implementation just calls the regular get_plugin_details
|
||||||
|
self.get_plugin_details(plugin_id).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Download a plugin from the repository
|
||||||
|
async fn download_plugin(&self, plugin_id: &str, version: &str, destination: &Path) -> Result<String, String>;
|
||||||
|
|
||||||
|
/// Download a plugin with server type consideration
|
||||||
|
async fn download_plugin_with_server_type(&self, plugin_id: &str, version: &str, destination: &Path, server_type: Option<&ServerType>) -> Result<String, String> {
|
||||||
|
// Default implementation calls the regular download_plugin
|
||||||
|
self.download_plugin(plugin_id, version, destination).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Re-export the crawler implementations
|
||||||
|
pub use hangar::HangarCrawler;
|
||||||
|
pub use spigotmc::SpigotMCCrawler;
|
||||||
|
pub use modrinth::ModrinthCrawler;
|
||||||
|
pub use github::GitHubCrawler;
|
||||||
@@ -0,0 +1,353 @@
|
|||||||
|
use std::error::Error;
|
||||||
|
use std::path::Path;
|
||||||
|
use serde::{Serialize, Deserialize};
|
||||||
|
use crate::{HttpClient, ServerType};
|
||||||
|
use crate::models::repository::{RepositoryPlugin, RepositorySource};
|
||||||
|
use crate::platform_matcher::is_version_compatible_with_server;
|
||||||
|
use urlencoding;
|
||||||
|
use async_trait::async_trait;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use crate::crawlers::Repository;
|
||||||
|
|
||||||
|
// Modrinth API response structures (Based on https://docs.modrinth.com/api-spec/)
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct ModrinthSearchResponse {
|
||||||
|
hits: Vec<ModrinthSearchHit>,
|
||||||
|
// Omitting pagination fields (offset, limit, total_hits) for simplicity
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct ModrinthSearchHit {
|
||||||
|
project_id: String,
|
||||||
|
slug: String, // Use this or project_id for details requests
|
||||||
|
project_type: String, // e.g., "mod", "plugin"
|
||||||
|
author: String, // Sometimes different from the project owner
|
||||||
|
title: String,
|
||||||
|
description: String,
|
||||||
|
categories: Vec<String>,
|
||||||
|
versions: Vec<String>, // List of supported Minecraft versions
|
||||||
|
downloads: u64,
|
||||||
|
icon_url: Option<String>,
|
||||||
|
latest_version: Option<String>, // Version number of the latest version
|
||||||
|
date_modified: String,
|
||||||
|
// Omitting client_side, server_side, display_categories, gallery, featured_gallery, license, follows
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct ModrinthProject {
|
||||||
|
id: String,
|
||||||
|
slug: String,
|
||||||
|
project_type: String,
|
||||||
|
team: String, // Team ID, need another call potentially for author names?
|
||||||
|
title: String,
|
||||||
|
description: String,
|
||||||
|
body: String, // Full description
|
||||||
|
categories: Vec<String>,
|
||||||
|
game_versions: Vec<String>,
|
||||||
|
downloads: u64,
|
||||||
|
icon_url: Option<String>,
|
||||||
|
published: String,
|
||||||
|
updated: String,
|
||||||
|
// Omitting donation_urls, license, client_side, server_side, gallery, status, moderator_message, versions
|
||||||
|
// We might need the 'versions' array (list of version IDs) for getting specific version details
|
||||||
|
}
|
||||||
|
|
||||||
|
// Structure for the response from /project/{id}/version
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct ModrinthVersion {
|
||||||
|
id: String,
|
||||||
|
project_id: String,
|
||||||
|
author_id: String, // User ID, need another call for name?
|
||||||
|
name: String, // Version title
|
||||||
|
version_number: String,
|
||||||
|
changelog: Option<String>,
|
||||||
|
date_published: String,
|
||||||
|
downloads: u64,
|
||||||
|
version_type: String, // e.g., "release", "beta", "alpha"
|
||||||
|
files: Vec<ModrinthVersionFile>,
|
||||||
|
game_versions: Vec<String>,
|
||||||
|
loaders: Vec<String>,
|
||||||
|
// Omitting dependencies, featured, status, requested_status
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct ModrinthVersionFile {
|
||||||
|
hashes: ModrinthHashes,
|
||||||
|
url: String,
|
||||||
|
filename: String,
|
||||||
|
primary: bool,
|
||||||
|
size: u64,
|
||||||
|
// Omitting file_type (useful if filtering non-JARs)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct ModrinthHashes {
|
||||||
|
sha1: String,
|
||||||
|
sha512: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modrinth crawler implementation
|
||||||
|
pub struct ModrinthCrawler {
|
||||||
|
client: Arc<HttpClient>,
|
||||||
|
api_base_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ModrinthCrawler {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
ModrinthCrawler {
|
||||||
|
client: Arc::new(HttpClient::new()),
|
||||||
|
api_base_url: "https://api.modrinth.com/v2".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper to get versions, now async
|
||||||
|
async fn get_project_versions_internal(&self, plugin_id: &str) -> Result<Vec<ModrinthVersion>, Box<dyn Error + Send + Sync>> {
|
||||||
|
let url = format!("{}/project/{}/version", self.api_base_url, plugin_id);
|
||||||
|
let response_body = self.client.get(&url).await?;
|
||||||
|
let versions: Vec<ModrinthVersion> = serde_json::from_str(&response_body)?;
|
||||||
|
Ok(versions)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper to get compatible versions for a server type
|
||||||
|
async fn get_compatible_versions(&self, plugin_id: &str, server_type: Option<&ServerType>) -> Result<Vec<ModrinthVersion>, Box<dyn Error + Send + Sync>> {
|
||||||
|
let all_versions = self.get_project_versions_internal(plugin_id).await?;
|
||||||
|
|
||||||
|
// If no server type provided, return all versions
|
||||||
|
if server_type.is_none() {
|
||||||
|
return Ok(all_versions);
|
||||||
|
}
|
||||||
|
|
||||||
|
let server_type = server_type.unwrap();
|
||||||
|
let compatible_versions: Vec<ModrinthVersion> = all_versions.into_iter()
|
||||||
|
.filter(|version| {
|
||||||
|
// Check if this version is compatible with our server
|
||||||
|
is_version_compatible_with_server(&version.loaders, server_type)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
// If no compatible versions found, log a warning
|
||||||
|
if compatible_versions.is_empty() {
|
||||||
|
println!("[ModrinthCrawler::get_compatible_versions] Warning: No versions compatible with server type {:?} for plugin {}", server_type, plugin_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(compatible_versions)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper to get user details from ID, now async
|
||||||
|
async fn get_user_details(&self, user_id: &str) -> Result<ModrinthUser, Box<dyn Error + Send + Sync>> {
|
||||||
|
let url = format!("{}/user/{}", self.api_base_url, user_id);
|
||||||
|
let response_body = self.client.get(&url).await?;
|
||||||
|
let user: ModrinthUser = serde_json::from_str(&response_body)?;
|
||||||
|
Ok(user)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct ModrinthUser {
|
||||||
|
username: String,
|
||||||
|
// other fields like id, name, avatar_url etc. are available if needed
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ModrinthCrawler {
|
||||||
|
pub async fn get_plugin_details_with_server_type(&self, plugin_id: &str, server_type: Option<&ServerType>) -> Result<RepositoryPlugin, String> {
|
||||||
|
let project_url = format!("{}/project/{}", self.api_base_url, plugin_id);
|
||||||
|
let project_response_body = match self.client.get(&project_url).await {
|
||||||
|
Ok(body) => body,
|
||||||
|
Err(e) => return Err(format!("Modrinth project request failed: {}", e)),
|
||||||
|
};
|
||||||
|
let project: ModrinthProject = match serde_json::from_str(&project_response_body) {
|
||||||
|
Ok(p) => p,
|
||||||
|
Err(e) => return Err(format!("Failed to parse Modrinth project: {}", e)),
|
||||||
|
};
|
||||||
|
|
||||||
|
let page_url = format!("https://modrinth.com/plugin/{}", project.slug);
|
||||||
|
|
||||||
|
// Fetch compatible versions
|
||||||
|
let versions = match self.get_compatible_versions(&project.id, server_type).await {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to fetch Modrinth versions for {}: {}", plugin_id, e);
|
||||||
|
Vec::new() // Continue with empty versions if fetch fails
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let latest_version_opt = versions.first();
|
||||||
|
|
||||||
|
// Explicitly use version_number instead of id
|
||||||
|
let latest_version_number = latest_version_opt.map_or("Unknown".to_string(), |v| {
|
||||||
|
// Always use the version_number field which is the actual semantic version
|
||||||
|
// not the internal Modrinth ID
|
||||||
|
v.version_number.clone()
|
||||||
|
});
|
||||||
|
|
||||||
|
let changelog = latest_version_opt.and_then(|v| v.changelog.clone());
|
||||||
|
let author_id = latest_version_opt.map(|v| v.author_id.clone());
|
||||||
|
|
||||||
|
// Fetch author name if ID is available
|
||||||
|
let author_name = if let Some(id) = author_id {
|
||||||
|
match self.get_user_details(&id).await {
|
||||||
|
Ok(user) => user.username,
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to fetch Modrinth author details for ID {}: {}", id, e);
|
||||||
|
"Unknown Author".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
project.team.clone() // Fallback to team ID if no version author found
|
||||||
|
};
|
||||||
|
|
||||||
|
let primary_file = latest_version_opt.and_then(|v| v.files.iter().find(|f| f.primary));
|
||||||
|
|
||||||
|
Ok(RepositoryPlugin {
|
||||||
|
id: project.id.clone(),
|
||||||
|
name: project.title,
|
||||||
|
version: latest_version_number,
|
||||||
|
description: Some(project.description),
|
||||||
|
authors: vec![author_name],
|
||||||
|
download_url: primary_file.map_or(String::new(), |f| f.url.clone()),
|
||||||
|
repository: RepositorySource::Modrinth,
|
||||||
|
page_url,
|
||||||
|
download_count: Some(project.downloads),
|
||||||
|
last_updated: Some(project.updated),
|
||||||
|
icon_url: project.icon_url,
|
||||||
|
minecraft_versions: latest_version_opt.map_or(project.game_versions.clone(), |v| v.game_versions.clone()),
|
||||||
|
categories: project.categories,
|
||||||
|
rating: None, // Modrinth API doesn't provide rating directly
|
||||||
|
file_size: primary_file.map(|f| f.size),
|
||||||
|
file_hash: primary_file.map(|f| f.hashes.sha512.clone()), // Use SHA512
|
||||||
|
changelog,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn download_plugin_with_server_type(&self, plugin_id: &str, version_number_str: &str, destination: &Path, server_type: Option<&ServerType>) -> Result<String, String> {
|
||||||
|
// First try to get compatible versions for the server type
|
||||||
|
let versions = match self.get_compatible_versions(plugin_id, server_type).await {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(e) => return Err(format!("Failed to get Modrinth versions for download: {}", e)),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Try to find a version that matches the requested version number among compatible versions
|
||||||
|
let mut version_to_download = versions.into_iter().find(|v| v.version_number == version_number_str);
|
||||||
|
|
||||||
|
// If no compatible version found, but we have a server type filter (meaning we actually filtered)
|
||||||
|
if version_to_download.is_none() && server_type.is_some() {
|
||||||
|
println!("No compatible version '{}' found for server type {:?}, attempting to find version without server compatibility check",
|
||||||
|
version_number_str, server_type);
|
||||||
|
|
||||||
|
// Try to get all versions without server type filtering
|
||||||
|
match self.get_project_versions_internal(plugin_id).await {
|
||||||
|
Ok(all_versions) => {
|
||||||
|
// Look for the specific version number in all versions
|
||||||
|
version_to_download = all_versions.into_iter().find(|v| v.version_number == version_number_str);
|
||||||
|
|
||||||
|
if version_to_download.is_some() {
|
||||||
|
println!("Found version '{}' without server compatibility check, proceeding with download", version_number_str);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
println!("Error getting all versions: {}", e);
|
||||||
|
// Continue with empty versions list, which will return an error below
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we still don't have a target version, return an error
|
||||||
|
let version = match version_to_download {
|
||||||
|
Some(v) => v,
|
||||||
|
None => return Err(format!("Version '{}' not found or not compatible for plugin {}", version_number_str, plugin_id)),
|
||||||
|
};
|
||||||
|
|
||||||
|
let primary_file = match version.files.iter().find(|f| f.primary) {
|
||||||
|
Some(f) => f,
|
||||||
|
None => return Err(format!("No primary file found for version '{}' of plugin {}", version_number_str, plugin_id)),
|
||||||
|
};
|
||||||
|
|
||||||
|
match self.client.download(&primary_file.url, destination).await {
|
||||||
|
Ok(_) => Ok(destination.to_string_lossy().to_string()),
|
||||||
|
Err(e) => Err(format!("Failed to download from Modrinth: {}", e)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl Repository for ModrinthCrawler {
|
||||||
|
fn get_repository_name(&self) -> String {
|
||||||
|
"Modrinth".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn search(&self, query: &str) -> Result<Vec<RepositoryPlugin>, String> {
|
||||||
|
let encoded_query = urlencoding::encode(query);
|
||||||
|
// Corrected format string with proper quoting for facets
|
||||||
|
let url = format!(
|
||||||
|
"{}/search?query={}&facets=[[\"project_type:plugin\"]]&limit=20",
|
||||||
|
self.api_base_url,
|
||||||
|
encoded_query
|
||||||
|
);
|
||||||
|
|
||||||
|
let response_body = match self.client.get(&url).await {
|
||||||
|
Ok(body) => body,
|
||||||
|
Err(e) => return Err(format!("Modrinth search request failed: {}", e)),
|
||||||
|
};
|
||||||
|
|
||||||
|
let search_response: ModrinthSearchResponse = match serde_json::from_str(&response_body) {
|
||||||
|
Ok(sr) => sr,
|
||||||
|
Err(e) => return Err(format!("Failed to parse Modrinth search results: {}", e)),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut results = Vec::new();
|
||||||
|
for hit in search_response.hits {
|
||||||
|
// For search results, we don't have version_number directly,
|
||||||
|
// so we need to fetch the latest version for each project
|
||||||
|
let version_info = if let Some(latest_version) = &hit.latest_version {
|
||||||
|
// If latest_version looks like an ID (no dots and long), fetch the real version number
|
||||||
|
if latest_version.len() >= 8 && !latest_version.contains('.') {
|
||||||
|
match self.get_project_versions_internal(&hit.project_id).await {
|
||||||
|
Ok(versions) if !versions.is_empty() => {
|
||||||
|
versions[0].version_number.clone()
|
||||||
|
},
|
||||||
|
_ => latest_version.clone()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
latest_version.clone()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
"Unknown".to_string()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create a simplified repository plugin from the search hit
|
||||||
|
let repo_plugin = RepositoryPlugin {
|
||||||
|
id: hit.project_id.clone(),
|
||||||
|
name: hit.title,
|
||||||
|
version: version_info,
|
||||||
|
description: Some(hit.description),
|
||||||
|
authors: vec![hit.author],
|
||||||
|
download_url: String::new(), // Will be filled in when getting specific version
|
||||||
|
repository: RepositorySource::Modrinth,
|
||||||
|
page_url: format!("https://modrinth.com/plugin/{}", hit.slug),
|
||||||
|
download_count: Some(hit.downloads),
|
||||||
|
last_updated: Some(hit.date_modified),
|
||||||
|
icon_url: hit.icon_url,
|
||||||
|
minecraft_versions: hit.versions,
|
||||||
|
categories: hit.categories,
|
||||||
|
rating: None,
|
||||||
|
file_size: None,
|
||||||
|
file_hash: None,
|
||||||
|
changelog: None,
|
||||||
|
};
|
||||||
|
results.push(repo_plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(results)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_plugin_details(&self, plugin_id: &str) -> Result<RepositoryPlugin, String> {
|
||||||
|
// Just delegate to our server-type aware version with None
|
||||||
|
self.get_plugin_details_with_server_type(plugin_id, None).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn download_plugin(&self, plugin_id: &str, version_number_str: &str, destination: &Path) -> Result<String, String> {
|
||||||
|
// Just delegate to our server-type aware version with None
|
||||||
|
self.download_plugin_with_server_type(plugin_id, version_number_str, destination, None).await
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,420 @@
|
|||||||
|
use serde::Deserialize; // Added Serialize for potential use, Deserialize is essential
|
||||||
|
use std::error::Error;
|
||||||
|
use std::path::Path;
|
||||||
|
use crate::{HttpClient};
|
||||||
|
use crate::models::repository::{RepositoryPlugin, RepositorySource};
|
||||||
|
use urlencoding;
|
||||||
|
use async_trait::async_trait;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::time::SystemTime; // For converting timestamp
|
||||||
|
use base64::{Engine as _, engine::general_purpose::STANDARD}; // Correct import with Engine trait
|
||||||
|
use serde_json::Value; // Import Value
|
||||||
|
use crate::crawlers::Repository; // Use the correct trait import
|
||||||
|
|
||||||
|
// --- Structs for SpiGet API Deserialization ---
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct SpiGetIcon {
|
||||||
|
url: Option<String>,
|
||||||
|
// data: Option<String>, // Base64 data not typically needed if URL is present
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct SpiGetRating {
|
||||||
|
average: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct SpiGetAuthor {
|
||||||
|
id: u32,
|
||||||
|
name: Option<String>, // SpiGet might not always return name in all contexts
|
||||||
|
// icon: Option<SpiGetIcon>, // Icon data might be available in author details endpoint
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct SpiGetFile {
|
||||||
|
// #[serde(rename = "type")]
|
||||||
|
// file_type: Option<String>, // e.g. ".jar"
|
||||||
|
size: Option<Value>, // Use Value to accept string or number from API
|
||||||
|
size_unit: Option<String>, // e.g. "MB"
|
||||||
|
url: Option<String>, // Link to the spigotmc resource page, *not* a direct download
|
||||||
|
// externalUrl: Option<String> // Field from docs, maybe add if needed later
|
||||||
|
}
|
||||||
|
|
||||||
|
// Represents a version summary, often nested or in arrays
|
||||||
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct SpiGetVersion {
|
||||||
|
id: u32,
|
||||||
|
name: Option<String>, // Make optional: The actual version string e.g., "1.19.4" or "v2.1"
|
||||||
|
uuid: Option<String>,
|
||||||
|
release_date: Option<u64>, // Timestamp
|
||||||
|
downloads: Option<u32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct SpiGetUpdate {
|
||||||
|
|
||||||
|
description: String, // Base64 encoded HTML description
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct IdReference { // Used for arrays containing only IDs
|
||||||
|
id: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct SpiGetResource {
|
||||||
|
id: u32,
|
||||||
|
name: Option<String>, // Make name optional to handle potential missing field in search results
|
||||||
|
tag: Option<String>, // Make tag optional as well for robustness
|
||||||
|
version: SpiGetVersion, // Represents the *latest* version details here
|
||||||
|
author: SpiGetAuthor, // Contains author ID, maybe name
|
||||||
|
downloads: u32,
|
||||||
|
tested_versions: Vec<String>, // List of MC versions plugin is tested against
|
||||||
|
rating: SpiGetRating,
|
||||||
|
icon: SpiGetIcon, // Contains URL to icon
|
||||||
|
update_date: u64, // Timestamp
|
||||||
|
file: SpiGetFile, // Details about the main file download
|
||||||
|
external: bool, // If true, download link points externally
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- SpigotMC Crawler Implementation (using SpiGet API) ---
|
||||||
|
|
||||||
|
pub struct SpigotMCCrawler {
|
||||||
|
client: Arc<HttpClient>,
|
||||||
|
base_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SpigotMCCrawler {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
SpigotMCCrawler {
|
||||||
|
client: Arc::new(HttpClient::new()),
|
||||||
|
base_url: "https://api.spiget.org/v2".to_string(), // Use SpiGet API base URL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper to convert SpiGetResource to RepositoryPlugin
|
||||||
|
fn map_resource_to_plugin(&self, resource: &SpiGetResource) -> RepositoryPlugin {
|
||||||
|
// Construct SpigotMC page URL
|
||||||
|
let page_url = format!("https://www.spigotmc.org/resources/{}", resource.id);
|
||||||
|
|
||||||
|
// Construct potential download URL (may differ for external resources)
|
||||||
|
let download_url = if resource.external {
|
||||||
|
// For external resources, the 'url' in file info is the download link
|
||||||
|
resource.file.url.clone().unwrap_or_default()
|
||||||
|
} else {
|
||||||
|
// For internal resources, use the SpiGet download endpoint for the *latest* version
|
||||||
|
format!("{}/resources/{}/download", self.base_url, resource.id)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Format update date
|
||||||
|
let last_updated = SystemTime::UNIX_EPOCH
|
||||||
|
.checked_add(std::time::Duration::from_secs(resource.update_date))
|
||||||
|
.map(|_st| { // Remove chrono formatting for now
|
||||||
|
// Simple ISO 8601 format or similar - requires chrono for better formatting
|
||||||
|
// For now, just return the timestamp as string for simplicity
|
||||||
|
format!("{}", resource.update_date)
|
||||||
|
});
|
||||||
|
|
||||||
|
// Safely get author name
|
||||||
|
let author_name = resource.author.name.clone().unwrap_or_else(|| format!("#{}", resource.author.id));
|
||||||
|
|
||||||
|
// Convert file size, handling potential string in 'size' field
|
||||||
|
let file_size_bytes = resource.file.size.as_ref().and_then(|s| s.as_f64()).map(|s_num| {
|
||||||
|
match resource.file.size_unit.as_deref() {
|
||||||
|
Some("KB") => (s_num * 1024.0) as u64,
|
||||||
|
Some("MB") => (s_num * 1024.0 * 1024.0) as u64,
|
||||||
|
Some("GB") => (s_num * 1024.0 * 1024.0 * 1024.0) as u64,
|
||||||
|
_ => s_num as u64, // Assume bytes if unit is missing or unknown
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Prepend base URL to icon URL if it's relative (SpiGet usually provides full URL)
|
||||||
|
let icon_url = resource.icon.url.clone();
|
||||||
|
|
||||||
|
// Use id as fallback if name is missing
|
||||||
|
let plugin_name = resource.name.clone().unwrap_or_else(|| format!("Unnamed Resource #{}", resource.id));
|
||||||
|
|
||||||
|
// Extract version information properly
|
||||||
|
let version_name = resource.version.name.clone().unwrap_or_else(|| {
|
||||||
|
println!("[SpigotMCCrawler::map_resource_to_plugin] Warning: Missing version name for resource ID: {}", resource.id);
|
||||||
|
// DO NOT use tested Minecraft versions as fallbacks for plugin versions
|
||||||
|
// since they are different types of versions
|
||||||
|
"Unknown".to_string()
|
||||||
|
});
|
||||||
|
|
||||||
|
println!("[SpigotMCCrawler::map_resource_to_plugin] Version for {}: {}", plugin_name, version_name);
|
||||||
|
|
||||||
|
RepositoryPlugin {
|
||||||
|
id: resource.id.to_string(),
|
||||||
|
name: plugin_name, // Use the potentially fallback name
|
||||||
|
version: version_name, // Use the potentially fallback version name
|
||||||
|
description: resource.tag.clone(), // Use tagline as description (already Option<String>)
|
||||||
|
authors: vec![author_name],
|
||||||
|
download_url,
|
||||||
|
repository: RepositorySource::SpigotMC,
|
||||||
|
page_url,
|
||||||
|
download_count: Some(resource.downloads as u64),
|
||||||
|
last_updated,
|
||||||
|
icon_url, // Use the potentially prefixed URL
|
||||||
|
minecraft_versions: resource.tested_versions.clone(),
|
||||||
|
categories: Vec::new(), // SpiGet only gives category ID, fetching name requires another call
|
||||||
|
rating: Some(resource.rating.average),
|
||||||
|
file_size: file_size_bytes,
|
||||||
|
file_hash: None, // SpiGet does not provide hashes
|
||||||
|
changelog: None, // Needs separate call to /updates/latest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper to fetch and decode the latest update's description as changelog
|
||||||
|
async fn get_latest_changelog(&self, resource_id: &str) -> Result<Option<String>, Box<dyn Error + Send + Sync>> {
|
||||||
|
let url = format!("{}/resources/{}/updates/latest", self.base_url, resource_id);
|
||||||
|
match self.client.get(&url).await {
|
||||||
|
Ok(body) => {
|
||||||
|
match serde_json::from_str::<SpiGetUpdate>(&body) {
|
||||||
|
Ok(update) => {
|
||||||
|
// Description is Base64 encoded HTML
|
||||||
|
match STANDARD.decode(&update.description) {
|
||||||
|
Ok(decoded_bytes) => {
|
||||||
|
// Convert bytes to string (assuming UTF-8)
|
||||||
|
// decoded_bytes is now a Vec<u8>, which implements Sized
|
||||||
|
Ok(Some(String::from_utf8_lossy(&decoded_bytes).to_string()))
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to decode base64 changelog for {}: {}", resource_id, e);
|
||||||
|
Ok(None) // Return None if decoding fails
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to parse latest update JSON for {}: {}", resource_id, e);
|
||||||
|
Ok(None) // Return None if parsing fails
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
// If the request itself fails (e.g., 404 if no updates), treat as no changelog
|
||||||
|
println!("Failed to fetch latest update for {}: {}", resource_id, e);
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Moved get_plugin_versions back here as it's not part of the Repository trait
|
||||||
|
async fn get_plugin_versions(&self, plugin_id: &str) -> Result<Vec<String>, String> {
|
||||||
|
println!("Fetching versions for resource ID: {}", plugin_id);
|
||||||
|
let url = format!("{}/resources/{}/versions?sort=-releaseDate&size=10", self.base_url, plugin_id);
|
||||||
|
|
||||||
|
let body = match self.client.get(&url).await {
|
||||||
|
Ok(b) => b,
|
||||||
|
Err(e) => return Err(format!("Failed SpiGet versions request: {}", e))
|
||||||
|
};
|
||||||
|
|
||||||
|
match serde_json::from_str::<Vec<SpiGetVersion>>(&body) {
|
||||||
|
Ok(versions) => {
|
||||||
|
let version_names: Vec<String> = versions.into_iter()
|
||||||
|
.filter_map(|v| v.name)
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if version_names.is_empty() {
|
||||||
|
// If no version names available, try to extract from the version ID
|
||||||
|
println!("No named versions found for resource {}. Trying alternate methods.", plugin_id);
|
||||||
|
|
||||||
|
// Try to get full resource details for version info
|
||||||
|
let resource_url = format!("{}/resources/{}", self.base_url, plugin_id);
|
||||||
|
match self.client.get(&resource_url).await {
|
||||||
|
Ok(resource_body) => {
|
||||||
|
match serde_json::from_str::<SpiGetResource>(&resource_body) {
|
||||||
|
Ok(resource) => {
|
||||||
|
// Check if we can get a version from the resource directly
|
||||||
|
if let Some(name) = resource.version.name {
|
||||||
|
println!("Found version from resource details: {}", name);
|
||||||
|
return Ok(vec![name]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => println!("Failed to parse resource details: {}", e)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => println!("Failed to fetch resource details: {}", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If still no version, return a fallback
|
||||||
|
println!("Using fallback version for resource ID: {}", plugin_id);
|
||||||
|
Ok(vec!["Unknown".to_string()])
|
||||||
|
} else {
|
||||||
|
println!("Found {} versions for resource ID: {}", version_names.len(), plugin_id);
|
||||||
|
Ok(version_names)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to parse versions JSON: {}. Body: {}", e, body);
|
||||||
|
Err(format!("Failed to parse SpiGet versions: {}", e))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl Repository for SpigotMCCrawler {
|
||||||
|
fn get_repository_name(&self) -> String {
|
||||||
|
"SpigotMC".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn search(&self, query: &str) -> Result<Vec<RepositoryPlugin>, String> {
|
||||||
|
let encoded_query = urlencoding::encode(query);
|
||||||
|
let url = format!(
|
||||||
|
"{}/search/resources/{}?field=name&fields=name,tag,author,version,downloads,rating,icon,updateDate,premium,file,external,testedVersions",
|
||||||
|
self.base_url,
|
||||||
|
encoded_query
|
||||||
|
);
|
||||||
|
|
||||||
|
let body = match self.client.get(&url).await {
|
||||||
|
Ok(b) => b,
|
||||||
|
Err(e) => return Err(format!("Failed SpiGet search request: {}", e))
|
||||||
|
};
|
||||||
|
|
||||||
|
match serde_json::from_str::<Vec<SpiGetResource>>(&body) {
|
||||||
|
Ok(resources) => {
|
||||||
|
let mut results = Vec::new();
|
||||||
|
for res in &resources {
|
||||||
|
let mut plugin = self.map_resource_to_plugin(res);
|
||||||
|
// Try fetching versions if missing
|
||||||
|
if plugin.version == "Unknown" {
|
||||||
|
println!("Searching for version information for resource ID: {}", plugin.id);
|
||||||
|
match self.get_plugin_versions(&plugin.id).await {
|
||||||
|
Ok(versions) => {
|
||||||
|
if let Some(latest) = versions.first() {
|
||||||
|
println!("Found version for {}: {}", plugin.name, latest);
|
||||||
|
plugin.version = latest.clone();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => println!("Failed to fetch versions for {}: {}", plugin.id, e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
results.push(plugin);
|
||||||
|
}
|
||||||
|
Ok(results)
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
// Handle case where search returns a single object instead of array (e.g., direct ID match?)
|
||||||
|
// Or just return the parsing error
|
||||||
|
Err(format!("Failed to parse SpiGet search results: {}. Body: {}", e, body))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_plugin_details(&self, plugin_id: &str) -> Result<RepositoryPlugin, String> {
|
||||||
|
let url = format!(
|
||||||
|
"{}/resources/{}?fields=name,tag,author,version,downloads,rating,icon,updateDate,premium,file,external,testedVersions",
|
||||||
|
self.base_url,
|
||||||
|
plugin_id
|
||||||
|
);
|
||||||
|
|
||||||
|
let body = match self.client.get(&url).await {
|
||||||
|
Ok(b) => b,
|
||||||
|
Err(e) => return Err(format!("Failed SpiGet details request: {}", e))
|
||||||
|
};
|
||||||
|
|
||||||
|
match serde_json::from_str::<SpiGetResource>(&body) {
|
||||||
|
Ok(resource) => {
|
||||||
|
let mut plugin = self.map_resource_to_plugin(&resource);
|
||||||
|
// Fetch changelog
|
||||||
|
match self.get_latest_changelog(&plugin.id).await {
|
||||||
|
Ok(changelog_opt) => plugin.changelog = changelog_opt,
|
||||||
|
Err(e) => println!("Failed to fetch changelog for {}: {}", plugin.id, e),
|
||||||
|
}
|
||||||
|
// Try fetching versions if missing
|
||||||
|
if plugin.version == "Unknown" {
|
||||||
|
println!("Fetching versions for detail view of resource ID: {}", plugin.id);
|
||||||
|
match self.get_plugin_versions(&plugin.id).await {
|
||||||
|
Ok(versions) => {
|
||||||
|
if let Some(latest) = versions.first() {
|
||||||
|
println!("Found version for {} in detail view: {}", plugin.name, latest);
|
||||||
|
plugin.version = latest.clone();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => println!("Failed to fetch versions for {} in detail view: {}", plugin.id, e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(plugin)
|
||||||
|
}
|
||||||
|
Err(e) => Err(format!("Failed to parse SpiGet resource details: {}. Body: {}", e, body))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn download_plugin(&self, plugin_id: &str, version: &str, destination: &Path) -> Result<String, String> {
|
||||||
|
// First, get the plugin details
|
||||||
|
let details = self.get_plugin_details(plugin_id).await?;
|
||||||
|
|
||||||
|
// Get the plugin page URL for potential manual download instructions
|
||||||
|
let plugin_page_url = details.page_url.clone();
|
||||||
|
|
||||||
|
// Use the SpigotMC direct download URL instead of SpiGet
|
||||||
|
// SpigotMC has a direct download URL pattern for resources
|
||||||
|
let direct_download_url = format!("https://www.spigotmc.org/resources/{}/download", plugin_id);
|
||||||
|
|
||||||
|
// Log the download attempt
|
||||||
|
println!("Attempting to download plugin from SpigotMC direct URL: {}", direct_download_url);
|
||||||
|
println!("Requested version: {} (Note: SpigotMC usually provides latest version only)", version);
|
||||||
|
|
||||||
|
// Try to download using direct SpigotMC URL
|
||||||
|
match self.client.download(&direct_download_url, destination).await {
|
||||||
|
Ok(_) => {
|
||||||
|
println!("Successfully downloaded plugin from SpigotMC direct URL");
|
||||||
|
Ok(destination.to_string_lossy().to_string())
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
// If direct download fails with 403, it might be a premium resource
|
||||||
|
let error_message = format!("{}", e);
|
||||||
|
if error_message.contains("403 Forbidden") {
|
||||||
|
println!("Plugin appears to be a premium/protected resource on SpigotMC");
|
||||||
|
|
||||||
|
// Try the SpiGet URL as a fallback just to be sure
|
||||||
|
let download_url = &details.download_url;
|
||||||
|
if download_url.is_empty() {
|
||||||
|
return Err(format!("PREMIUM_RESOURCE:{}", plugin_page_url));
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Falling back to SpiGet download URL: {}", download_url);
|
||||||
|
|
||||||
|
match self.client.download(download_url, destination).await {
|
||||||
|
Ok(_) => Ok(destination.to_string_lossy().to_string()),
|
||||||
|
Err(spiget_err) => {
|
||||||
|
// If both methods fail, this is very likely a premium plugin
|
||||||
|
if format!("{}", spiget_err).contains("404 Not Found") {
|
||||||
|
println!("Confirmed premium resource - both direct and SpiGet downloads failed");
|
||||||
|
Err(format!("PREMIUM_RESOURCE:{}", plugin_page_url))
|
||||||
|
} else {
|
||||||
|
Err(format!("Failed to download from SpiGet: {}", spiget_err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// For other errors with direct download, try SpiGet
|
||||||
|
println!("Direct SpigotMC download failed: {}. Trying SpiGet URL as fallback...", e);
|
||||||
|
|
||||||
|
let download_url = &details.download_url;
|
||||||
|
if download_url.is_empty() {
|
||||||
|
return Err(format!("No download URL found for SpigotMC resource {}", plugin_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Falling back to SpiGet download URL: {}", download_url);
|
||||||
|
|
||||||
|
match self.client.download(download_url, destination).await {
|
||||||
|
Ok(_) => Ok(destination.to_string_lossy().to_string()),
|
||||||
|
Err(e) => Err(format!("Failed to download from SpiGet: {}", e))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+290
-577
@@ -1,614 +1,327 @@
|
|||||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||||
use serde::{Serialize, Deserialize};
|
|
||||||
|
// Standard library imports
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::fs;
|
use std::env;
|
||||||
use std::io::Read;
|
|
||||||
use tauri::command;
|
|
||||||
use zip::ZipArchive;
|
|
||||||
use yaml_rust::{YamlLoader, Yaml};
|
|
||||||
use std::fs::File;
|
|
||||||
use sha2::{Sha256, Digest};
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
// Serde for serialization/deserialization
|
||||||
pub enum ServerType {
|
|
||||||
Paper,
|
// Tauri related imports
|
||||||
Spigot,
|
|
||||||
Bukkit,
|
// Internal modules
|
||||||
Vanilla,
|
pub mod models;
|
||||||
Forge,
|
pub mod services;
|
||||||
Fabric,
|
pub mod commands;
|
||||||
Velocity,
|
pub mod crawlers;
|
||||||
BungeeCord,
|
pub mod platform_matcher;
|
||||||
Waterfall,
|
|
||||||
Unknown,
|
// Import our models
|
||||||
|
pub use models::server::{ServerType, ServerInfo, ScanResult, ScanProgress};
|
||||||
|
pub use models::plugin::{Plugin, PluginMeta};
|
||||||
|
pub use models::repository::{RepositorySource, RepositoryPlugin, PotentialPluginMatch};
|
||||||
|
|
||||||
|
// Import our services
|
||||||
|
pub use services::http::HttpClient;
|
||||||
|
pub use services::plugin_scanner::{scan_server_directory, perform_scan, extract_plugin_metadata, calculate_file_hash, is_file_locked};
|
||||||
|
pub use services::update_manager::{check_for_plugin_updates, check_single_plugin_update, backup_plugin, replace_plugin, normalize_version, compare_plugin_versions};
|
||||||
|
|
||||||
|
// Import our commands
|
||||||
|
pub use commands::plugin_commands::*;
|
||||||
|
pub use commands::scan_commands::*;
|
||||||
|
|
||||||
|
// Import our crawlers
|
||||||
|
pub use crawlers::HangarCrawler;
|
||||||
|
pub use crawlers::SpigotMCCrawler;
|
||||||
|
pub use crawlers::ModrinthCrawler;
|
||||||
|
pub use crawlers::GitHubCrawler;
|
||||||
|
pub use crawlers::Repository;
|
||||||
|
|
||||||
|
// Import platform matchers
|
||||||
|
pub use platform_matcher::{get_compatible_modrinth_loaders, is_version_compatible_with_server};
|
||||||
|
|
||||||
|
use futures::future::{BoxFuture, FutureExt}; // Import necessary future types
|
||||||
|
|
||||||
|
/// Search for plugins in repositories
|
||||||
|
pub async fn lib_search_plugins_in_repositories(
|
||||||
|
query: &str,
|
||||||
|
repositories: Vec<RepositorySource>
|
||||||
|
) -> Result<Vec<RepositoryPlugin>, String> {
|
||||||
|
// Check for empty query
|
||||||
|
if query.is_empty() {
|
||||||
|
return Err("Search query cannot be empty".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
// Check for empty repository list
|
||||||
pub struct ServerInfo {
|
if repositories.is_empty() {
|
||||||
server_type: ServerType,
|
return Err("No repositories specified for search".to_string());
|
||||||
minecraft_version: Option<String>,
|
|
||||||
plugins_directory: String,
|
|
||||||
plugins_count: usize,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
// Create a list to store tasks (boxed futures)
|
||||||
pub struct Plugin {
|
let mut tasks: Vec<BoxFuture<Result<(String, Vec<RepositoryPlugin>), (String, String)>>> = Vec::new();
|
||||||
name: String,
|
|
||||||
version: String,
|
// Add tasks for each repository
|
||||||
latest_version: Option<String>,
|
for repo in repositories {
|
||||||
description: Option<String>,
|
match repo {
|
||||||
authors: Vec<String>,
|
RepositorySource::HangarMC => {
|
||||||
has_update: bool,
|
let crawler = crawlers::HangarCrawler::new();
|
||||||
api_version: Option<String>,
|
let query_owned = query.to_string();
|
||||||
main_class: Option<String>,
|
let task = async move {
|
||||||
depend: Option<Vec<String>>,
|
match crawler.search(&query_owned).await {
|
||||||
soft_depend: Option<Vec<String>>,
|
Ok(repo_results) => Ok((crawler.get_repository_name(), repo_results)),
|
||||||
load_before: Option<Vec<String>>,
|
Err(e) => Err((crawler.get_repository_name(), e.to_string()))
|
||||||
commands: Option<serde_json::Value>,
|
|
||||||
permissions: Option<serde_json::Value>,
|
|
||||||
file_path: String,
|
|
||||||
file_hash: String,
|
|
||||||
}
|
}
|
||||||
|
}.boxed(); // Box the future
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
tasks.push(task);
|
||||||
pub struct PluginMeta {
|
},
|
||||||
pub name: String,
|
RepositorySource::SpigotMC => {
|
||||||
pub version: String,
|
let crawler = crawlers::SpigotMCCrawler::new();
|
||||||
pub description: Option<String>,
|
let query_owned = query.to_string();
|
||||||
pub authors: Vec<String>,
|
let task = async move {
|
||||||
pub api_version: Option<String>,
|
match crawler.search(&query_owned).await {
|
||||||
pub main_class: Option<String>,
|
Ok(repo_results) => Ok((crawler.get_repository_name(), repo_results)),
|
||||||
pub depend: Option<Vec<String>>,
|
Err(e) => Err((crawler.get_repository_name(), e.to_string()))
|
||||||
pub soft_depend: Option<Vec<String>>,
|
}
|
||||||
pub load_before: Option<Vec<String>>,
|
}.boxed(); // Box the future
|
||||||
pub commands: Option<serde_json::Value>,
|
tasks.push(task);
|
||||||
pub permissions: Option<serde_json::Value>,
|
},
|
||||||
pub file_path: String,
|
RepositorySource::Modrinth => {
|
||||||
pub file_size: u64,
|
let crawler = crawlers::ModrinthCrawler::new();
|
||||||
pub file_hash: String,
|
let query_owned = query.to_string();
|
||||||
}
|
let task = async move {
|
||||||
|
match crawler.search(&query_owned).await {
|
||||||
/// Calculates SHA-256 hash for a given file path
|
Ok(repo_results) => Ok((crawler.get_repository_name(), repo_results)),
|
||||||
pub fn calculate_file_hash(file_path: &str) -> Result<String, String> {
|
Err(e) => Err((crawler.get_repository_name(), e.to_string()))
|
||||||
let mut file = File::open(file_path).map_err(|e| format!("Failed to open file for hashing: {}", e))?;
|
}
|
||||||
let mut hasher = Sha256::new();
|
}.boxed(); // Box the future
|
||||||
let mut buffer = [0; 1024];
|
tasks.push(task);
|
||||||
|
},
|
||||||
loop {
|
RepositorySource::GitHub => {
|
||||||
let bytes_read = file.read(&mut buffer).map_err(|e| format!("Failed to read file for hashing: {}", e))?;
|
let crawler = crawlers::GitHubCrawler::new();
|
||||||
if bytes_read == 0 {
|
let query_owned = query.to_string();
|
||||||
break;
|
let task = async move {
|
||||||
}
|
match crawler.search(&query_owned).await {
|
||||||
hasher.update(&buffer[..bytes_read]);
|
Ok(repo_results) => Ok((crawler.get_repository_name(), repo_results)),
|
||||||
}
|
Err(e) => Err((crawler.get_repository_name(), e.to_string()))
|
||||||
|
}
|
||||||
let hash = hasher.finalize();
|
}.boxed(); // Box the future
|
||||||
Ok(format!("{:x}", hash))
|
tasks.push(task);
|
||||||
}
|
|
||||||
|
|
||||||
/// Extract metadata from a plugin.yml file inside a JAR
|
|
||||||
fn extract_plugin_metadata(jar_path: &Path) -> Result<PluginMeta, String> {
|
|
||||||
let file = fs::File::open(jar_path)
|
|
||||||
.map_err(|e| format!("Failed to open JAR file: {}", e))?;
|
|
||||||
|
|
||||||
let file_size = file.metadata()
|
|
||||||
.map_err(|e| format!("Failed to read file metadata: {}", e))?
|
|
||||||
.len();
|
|
||||||
|
|
||||||
let mut archive = ZipArchive::new(file)
|
|
||||||
.map_err(|e| format!("Invalid JAR file: {}", e))?;
|
|
||||||
|
|
||||||
// Try to find and read plugin.yml or bungee.yml
|
|
||||||
let yaml_content = match read_yaml_from_archive(&mut archive, "plugin.yml") {
|
|
||||||
Ok(content) => content,
|
|
||||||
Err(_) => match read_yaml_from_archive(&mut archive, "bungee.yml") {
|
|
||||||
Ok(content) => content,
|
|
||||||
Err(_) => {
|
|
||||||
// If no plugin metadata file is found, try to infer from filename
|
|
||||||
let filename = jar_path.file_name()
|
|
||||||
.and_then(|n| n.to_str())
|
|
||||||
.unwrap_or("unknown.jar");
|
|
||||||
|
|
||||||
// Extract name and version from filename (e.g., "WorldEdit-7.2.8.jar" → name: "WorldEdit", version: "7.2.8")
|
|
||||||
let mut parts: Vec<&str> = filename.trim_end_matches(".jar").split('-').collect();
|
|
||||||
let version = if parts.len() > 1 {
|
|
||||||
parts.pop().unwrap_or("1.0.0").to_string()
|
|
||||||
} else {
|
|
||||||
"1.0.0".to_string()
|
|
||||||
};
|
|
||||||
|
|
||||||
let name = parts.join("-");
|
|
||||||
|
|
||||||
return Ok(PluginMeta {
|
|
||||||
name,
|
|
||||||
version,
|
|
||||||
description: None,
|
|
||||||
authors: Vec::new(),
|
|
||||||
api_version: None,
|
|
||||||
main_class: None,
|
|
||||||
depend: None,
|
|
||||||
soft_depend: None,
|
|
||||||
load_before: None,
|
|
||||||
commands: None,
|
|
||||||
permissions: None,
|
|
||||||
file_path: jar_path.to_string_lossy().to_string(),
|
|
||||||
file_size,
|
|
||||||
file_hash: calculate_file_hash(jar_path.to_str().unwrap_or("unknown.jar")).unwrap_or_else(|_| "unknown".to_string()),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Parse the YAML content
|
|
||||||
let docs = match YamlLoader::load_from_str(&yaml_content) {
|
|
||||||
Ok(docs) => docs,
|
|
||||||
Err(e) => {
|
|
||||||
println!("Failed to parse plugin YAML: {}", e);
|
|
||||||
return fallback_plugin_meta(jar_path, file_size);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if docs.is_empty() {
|
|
||||||
return fallback_plugin_meta(jar_path, file_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
let doc = &docs[0];
|
|
||||||
|
|
||||||
// Extract basic metadata with fallbacks for missing fields
|
|
||||||
let name = yaml_str_with_fallback(doc, "name", jar_path);
|
|
||||||
let version = yaml_str_with_fallback(doc, "version", jar_path);
|
|
||||||
|
|
||||||
// Extract optional fields
|
|
||||||
let description = yaml_str_opt(doc, "description");
|
|
||||||
|
|
||||||
// Handle authors (can be a single string or an array)
|
|
||||||
let authors = match &doc["authors"] {
|
|
||||||
Yaml::Array(arr) => {
|
|
||||||
arr.iter()
|
|
||||||
.filter_map(|a| a.as_str().map(|s| s.to_string()))
|
|
||||||
.collect()
|
|
||||||
},
|
},
|
||||||
Yaml::String(s) => vec![s.clone()],
|
|
||||||
_ => {
|
_ => {
|
||||||
// Fallback to 'author' field which is sometimes used
|
eprintln!("Repository {:?} not supported for search", repo);
|
||||||
match &doc["author"] {
|
|
||||||
Yaml::String(s) => vec![s.clone()],
|
|
||||||
_ => Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Extract other optional metadata
|
|
||||||
let api_version = yaml_str_opt(doc, "api-version");
|
|
||||||
let main_class = yaml_str_opt(doc, "main");
|
|
||||||
|
|
||||||
// Handle dependency lists
|
|
||||||
let depend = yaml_str_array(doc, "depend");
|
|
||||||
let soft_depend = yaml_str_array(doc, "softdepend");
|
|
||||||
let load_before = yaml_str_array(doc, "loadbefore");
|
|
||||||
|
|
||||||
// Handle complex structures as generic JSON values
|
|
||||||
let commands = match &doc["commands"] {
|
|
||||||
Yaml::Hash(_) => {
|
|
||||||
Some(serde_json::Value::String("Commands data present".to_string()))
|
|
||||||
},
|
|
||||||
_ => None
|
|
||||||
};
|
|
||||||
|
|
||||||
let permissions = match &doc["permissions"] {
|
|
||||||
Yaml::Hash(_) => {
|
|
||||||
Some(serde_json::Value::String("Permissions data present".to_string()))
|
|
||||||
},
|
|
||||||
_ => None
|
|
||||||
};
|
|
||||||
|
|
||||||
// Calculate the file hash
|
|
||||||
let file_hash = calculate_file_hash(jar_path.to_str().unwrap_or("unknown.jar")).unwrap_or_else(|_| "unknown".to_string());
|
|
||||||
|
|
||||||
Ok(PluginMeta {
|
|
||||||
name,
|
|
||||||
version,
|
|
||||||
description,
|
|
||||||
authors,
|
|
||||||
api_version,
|
|
||||||
main_class,
|
|
||||||
depend,
|
|
||||||
soft_depend,
|
|
||||||
load_before,
|
|
||||||
commands,
|
|
||||||
permissions,
|
|
||||||
file_path: jar_path.to_string_lossy().to_string(),
|
|
||||||
file_size,
|
|
||||||
file_hash,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper function to read a YAML file from the ZIP archive
|
|
||||||
fn read_yaml_from_archive(archive: &mut ZipArchive<fs::File>, file_name: &str) -> Result<String, String> {
|
|
||||||
match archive.by_name(file_name) {
|
|
||||||
Ok(mut file) => {
|
|
||||||
let mut contents = String::new();
|
|
||||||
file.read_to_string(&mut contents)
|
|
||||||
.map_err(|e| format!("Failed to read {}: {}", file_name, e))?;
|
|
||||||
Ok(contents)
|
|
||||||
},
|
|
||||||
Err(e) => Err(format!("Failed to find {}: {}", file_name, e))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper function to create plugin metadata with fallback values
|
|
||||||
fn fallback_plugin_meta(jar_path: &Path, file_size: u64) -> Result<PluginMeta, String> {
|
|
||||||
let filename = jar_path.file_name()
|
|
||||||
.and_then(|n| n.to_str())
|
|
||||||
.unwrap_or("unknown.jar");
|
|
||||||
|
|
||||||
// Extract name and version from filename (e.g., "WorldEdit-7.2.8.jar" → name: "WorldEdit", version: "7.2.8")
|
|
||||||
let mut parts: Vec<&str> = filename.trim_end_matches(".jar").split('-').collect();
|
|
||||||
let version = if parts.len() > 1 {
|
|
||||||
parts.pop().unwrap_or("1.0.0").to_string()
|
|
||||||
} else {
|
|
||||||
"1.0.0".to_string()
|
|
||||||
};
|
|
||||||
|
|
||||||
let name = parts.join("-");
|
|
||||||
|
|
||||||
Ok(PluginMeta {
|
|
||||||
name,
|
|
||||||
version,
|
|
||||||
description: None,
|
|
||||||
authors: Vec::new(),
|
|
||||||
api_version: None,
|
|
||||||
main_class: None,
|
|
||||||
depend: None,
|
|
||||||
soft_depend: None,
|
|
||||||
load_before: None,
|
|
||||||
commands: None,
|
|
||||||
permissions: None,
|
|
||||||
file_path: jar_path.to_string_lossy().to_string(),
|
|
||||||
file_size,
|
|
||||||
file_hash: calculate_file_hash(jar_path.to_str().unwrap_or("unknown.jar")).unwrap_or_else(|_| "unknown".to_string()),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract a string from YAML with fallback to filename
|
|
||||||
fn yaml_str_with_fallback(yaml: &Yaml, key: &str, jar_path: &Path) -> String {
|
|
||||||
match yaml[key].as_str() {
|
|
||||||
Some(s) => s.to_string(),
|
|
||||||
None => {
|
|
||||||
// Extract from filename as fallback
|
|
||||||
let filename = jar_path.file_name()
|
|
||||||
.and_then(|n| n.to_str())
|
|
||||||
.unwrap_or("unknown.jar");
|
|
||||||
|
|
||||||
if key == "name" {
|
|
||||||
// Extract name (e.g., "WorldEdit-7.2.8.jar" → "WorldEdit")
|
|
||||||
let parts: Vec<&str> = filename.trim_end_matches(".jar").split('-').collect();
|
|
||||||
parts[0].to_string()
|
|
||||||
} else if key == "version" {
|
|
||||||
// Extract version (e.g., "WorldEdit-7.2.8.jar" → "7.2.8")
|
|
||||||
let parts: Vec<&str> = filename.trim_end_matches(".jar").split('-').collect();
|
|
||||||
if parts.len() > 1 {
|
|
||||||
parts[1].to_string()
|
|
||||||
} else {
|
|
||||||
"1.0.0".to_string()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
String::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn yaml_str_opt(yaml: &Yaml, key: &str) -> Option<String> {
|
|
||||||
yaml[key].as_str().map(|s| s.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn yaml_str_array(yaml: &Yaml, key: &str) -> Option<Vec<String>> {
|
|
||||||
match &yaml[key] {
|
|
||||||
Yaml::Array(arr) => {
|
|
||||||
let strings: Vec<String> = arr.iter()
|
|
||||||
.filter_map(|a| a.as_str().map(|s| s.to_string()))
|
|
||||||
.collect();
|
|
||||||
if strings.is_empty() { None } else { Some(strings) }
|
|
||||||
},
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Detect the server type based on files in the server directory
|
|
||||||
fn detect_server_type(server_path: &Path) -> ServerType {
|
|
||||||
// Check for Paper
|
|
||||||
if server_path.join("cache").join("patched_1.19.2.jar").exists() ||
|
|
||||||
server_path.join("paper.yml").exists() {
|
|
||||||
return ServerType::Paper;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for Spigot
|
|
||||||
if server_path.join("spigot.yml").exists() {
|
|
||||||
return ServerType::Spigot;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for Bukkit
|
|
||||||
if server_path.join("bukkit.yml").exists() {
|
|
||||||
return ServerType::Bukkit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for Forge
|
|
||||||
if server_path.join("forge-server.jar").exists() ||
|
|
||||||
server_path.join("mods").exists() {
|
|
||||||
return ServerType::Forge;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for Fabric
|
|
||||||
if server_path.join("fabric-server-launch.jar").exists() ||
|
|
||||||
(server_path.join("mods").exists() && server_path.join("fabric-server-launcher.properties").exists()) {
|
|
||||||
return ServerType::Fabric;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for Velocity
|
|
||||||
if server_path.join("velocity.toml").exists() {
|
|
||||||
return ServerType::Velocity;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for BungeeCord
|
|
||||||
if server_path.join("BungeeCord.jar").exists() ||
|
|
||||||
server_path.join("config.yml").exists() {
|
|
||||||
return ServerType::BungeeCord;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for Waterfall
|
|
||||||
if server_path.join("waterfall.jar").exists() ||
|
|
||||||
server_path.join("waterfall.yml").exists() {
|
|
||||||
return ServerType::Waterfall;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if it's at least a vanilla server
|
|
||||||
if server_path.join("server.properties").exists() ||
|
|
||||||
server_path.join("vanilla_server.jar").exists() {
|
|
||||||
return ServerType::Vanilla;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no server type detected
|
|
||||||
ServerType::Unknown
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Guess the Minecraft version from various files in the server directory
|
|
||||||
fn detect_minecraft_version(server_path: &Path, server_type: &ServerType) -> Option<String> {
|
|
||||||
// Try from version.json if it exists
|
|
||||||
if let Ok(content) = fs::read_to_string(server_path.join("version.json")) {
|
|
||||||
if let Ok(json) = serde_json::from_str::<serde_json::Value>(&content) {
|
|
||||||
if let Some(version) = json["name"].as_str() {
|
|
||||||
return Some(version.to_string());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try from the server jar name pattern
|
// Execute all tasks concurrently
|
||||||
if let Ok(entries) = fs::read_dir(server_path) {
|
let results = futures::future::join_all(tasks).await;
|
||||||
for entry in entries {
|
|
||||||
if let Ok(entry) = entry {
|
|
||||||
let path = entry.path();
|
|
||||||
if path.is_file() && path.extension().map_or(false, |ext| ext == "jar") {
|
|
||||||
let filename = path.file_name().and_then(|n| n.to_str()).unwrap_or("");
|
|
||||||
|
|
||||||
// Extract version from various common patterns in jar names
|
// Collect successful results
|
||||||
if filename.starts_with("paper-") ||
|
|
||||||
filename.starts_with("spigot-") ||
|
|
||||||
filename.starts_with("craftbukkit-") {
|
|
||||||
// Pattern: paper-1.19.2.jar, spigot-1.19.2.jar
|
|
||||||
let parts: Vec<&str> = filename.split('-').collect();
|
|
||||||
if parts.len() > 1 {
|
|
||||||
let version_part = parts[1].trim_end_matches(".jar");
|
|
||||||
if version_part.contains('.') { // Basic version format check
|
|
||||||
return Some(version_part.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Look for version patterns like minecraft_server.1.19.2.jar
|
|
||||||
if filename.starts_with("minecraft_server.") {
|
|
||||||
let version_part = filename
|
|
||||||
.trim_start_matches("minecraft_server.")
|
|
||||||
.trim_end_matches(".jar");
|
|
||||||
if version_part.contains('.') {
|
|
||||||
return Some(version_part.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If server type is proxy, look in config files
|
|
||||||
if server_type == &ServerType::BungeeCord ||
|
|
||||||
server_type == &ServerType::Waterfall ||
|
|
||||||
server_type == &ServerType::Velocity {
|
|
||||||
// Velocity uses TOML, others use YAML
|
|
||||||
if server_type == &ServerType::Velocity {
|
|
||||||
if let Ok(content) = fs::read_to_string(server_path.join("velocity.toml")) {
|
|
||||||
// Very basic TOML parsing just for this field
|
|
||||||
for line in content.lines() {
|
|
||||||
if line.contains("minecraft-version") {
|
|
||||||
if let Some(version) = line.split('=').nth(1) {
|
|
||||||
return Some(version.trim().trim_matches('"').to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Try to parse config.yml for BungeeCord/Waterfall
|
|
||||||
if let Ok(content) = fs::read_to_string(server_path.join("config.yml")) {
|
|
||||||
if let Ok(docs) = YamlLoader::load_from_str(&content) {
|
|
||||||
if !docs.is_empty() {
|
|
||||||
let doc = &docs[0];
|
|
||||||
if let Some(version) = doc["minecraft_version"].as_str() {
|
|
||||||
return Some(version.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default fallback
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get plugins directory path based on server type
|
|
||||||
fn get_plugins_directory(server_path: &Path, server_type: &ServerType) -> String {
|
|
||||||
match server_type {
|
|
||||||
ServerType::Velocity => server_path.join("plugins").to_string_lossy().to_string(),
|
|
||||||
ServerType::BungeeCord => server_path.join("plugins").to_string_lossy().to_string(),
|
|
||||||
ServerType::Waterfall => server_path.join("plugins").to_string_lossy().to_string(),
|
|
||||||
_ => server_path.join("plugins").to_string_lossy().to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
pub struct ScanResult {
|
|
||||||
server_info: ServerInfo,
|
|
||||||
plugins: Vec<Plugin>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[command]
|
|
||||||
fn scan_server_directory(path: &str) -> Result<ScanResult, String> {
|
|
||||||
let server_path = Path::new(path);
|
|
||||||
|
|
||||||
if !server_path.exists() {
|
|
||||||
return Err(format!("Server path does not exist: {}", path));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detect server type and version
|
|
||||||
let server_type = detect_server_type(server_path);
|
|
||||||
let minecraft_version = detect_minecraft_version(server_path, &server_type);
|
|
||||||
|
|
||||||
println!("Detected server type: {:?}", server_type);
|
|
||||||
if let Some(version) = &minecraft_version {
|
|
||||||
println!("Detected Minecraft version: {}", version);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine plugins directory based on server type
|
|
||||||
let plugins_dir_str = get_plugins_directory(server_path, &server_type);
|
|
||||||
let plugins_dir = Path::new(&plugins_dir_str);
|
|
||||||
|
|
||||||
if !plugins_dir.exists() {
|
|
||||||
return Err(format!("Plugins directory not found at: {}", plugins_dir.display()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scan for JAR files in the plugins directory
|
|
||||||
let mut plugins = Vec::new();
|
let mut plugins = Vec::new();
|
||||||
|
let mut errors = Vec::new();
|
||||||
|
|
||||||
match fs::read_dir(&plugins_dir) {
|
for result in results {
|
||||||
Ok(entries) => {
|
match result {
|
||||||
for entry in entries {
|
Ok((_, repo_plugins)) => {
|
||||||
if let Ok(entry) = entry {
|
plugins.extend(repo_plugins);
|
||||||
let path = entry.path();
|
},
|
||||||
|
Err((repo, error)) => {
|
||||||
|
errors.push(format!("[{}] {}", repo, error));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check if this is a JAR file
|
// Check if we found any results
|
||||||
if path.is_file() && path.extension().map_or(false, |ext| ext.eq_ignore_ascii_case("jar")) {
|
if plugins.is_empty() {
|
||||||
match extract_plugin_metadata(&path) {
|
if !errors.is_empty() {
|
||||||
Ok(meta) => {
|
return Err(errors.join("; "));
|
||||||
// Create a Plugin from PluginMeta
|
} else {
|
||||||
let plugin = Plugin {
|
return Ok(Vec::new());
|
||||||
name: meta.name,
|
}
|
||||||
version: meta.version,
|
}
|
||||||
latest_version: None, // Will be filled by update checker
|
|
||||||
description: meta.description,
|
|
||||||
authors: meta.authors,
|
|
||||||
has_update: false, // Will be determined by update checker
|
|
||||||
api_version: meta.api_version,
|
|
||||||
main_class: meta.main_class,
|
|
||||||
depend: meta.depend,
|
|
||||||
soft_depend: meta.soft_depend,
|
|
||||||
load_before: meta.load_before,
|
|
||||||
commands: meta.commands,
|
|
||||||
permissions: meta.permissions,
|
|
||||||
file_path: meta.file_path,
|
|
||||||
file_hash: meta.file_hash,
|
|
||||||
};
|
|
||||||
|
|
||||||
plugins.push(plugin);
|
Ok(plugins)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Generate search variations for a plugin name
|
||||||
|
fn generate_search_variations(plugin_name: &str) -> Vec<String> {
|
||||||
|
let mut variations = Vec::new();
|
||||||
|
|
||||||
|
// Add original name
|
||||||
|
variations.push(plugin_name.to_string());
|
||||||
|
|
||||||
|
// Convert to lowercase
|
||||||
|
let name_lower = plugin_name.to_lowercase();
|
||||||
|
if name_lower != plugin_name {
|
||||||
|
variations.push(name_lower.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add variations with common prefixes/suffixes removed
|
||||||
|
let prefixes = ["plugin", "mc", "minecraft"];
|
||||||
|
let suffixes = ["plugin", "spigot", "bukkit", "paper", "mc"];
|
||||||
|
|
||||||
|
for prefix in prefixes.iter() {
|
||||||
|
let prefix_str = format!("{} ", prefix);
|
||||||
|
if name_lower.starts_with(&prefix_str) {
|
||||||
|
variations.push(name_lower[prefix_str.len()..].to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for suffix in suffixes.iter() {
|
||||||
|
let suffix_str = format!(" {}", suffix);
|
||||||
|
if name_lower.ends_with(&suffix_str) {
|
||||||
|
variations.push(name_lower[0..name_lower.len() - suffix_str.len()].to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove duplicates
|
||||||
|
variations.sort();
|
||||||
|
variations.dedup();
|
||||||
|
|
||||||
|
variations
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Search for plugin variations
|
||||||
|
pub async fn search_with_variations(plugin_name: &str, repositories: &[RepositorySource]) -> Result<Vec<RepositoryPlugin>, String> {
|
||||||
|
let variations = generate_search_variations(plugin_name);
|
||||||
|
let mut all_results = Vec::new();
|
||||||
|
|
||||||
|
for variation in variations {
|
||||||
|
match lib_search_plugins_in_repositories(&variation, repositories.to_vec()).await {
|
||||||
|
Ok(results) => {
|
||||||
|
all_results.extend(results);
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// Log error but continue with other plugins
|
println!("Error searching for variation '{}': {}", variation, e);
|
||||||
println!("Error reading plugin from {}: {}", path.display(), e);
|
// Continue with other variations even if this one fails
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove duplicates by plugin ID and repository
|
||||||
|
all_results.sort_by(|a, b| {
|
||||||
|
let a_key = format!("{:?}:{}", a.repository, a.id);
|
||||||
|
let b_key = format!("{:?}:{}", b.repository, b.id);
|
||||||
|
a_key.cmp(&b_key)
|
||||||
|
});
|
||||||
|
|
||||||
|
all_results.dedup_by(|a, b| {
|
||||||
|
a.id == b.id && a.repository == b.repository
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(all_results)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get plugin details from a repository
|
||||||
|
pub async fn lib_get_plugin_details_from_repository(
|
||||||
|
plugin_id: &str,
|
||||||
|
repository: RepositorySource,
|
||||||
|
server_type: Option<&ServerType>
|
||||||
|
) -> Result<RepositoryPlugin, String> {
|
||||||
|
match repository {
|
||||||
|
RepositorySource::HangarMC => {
|
||||||
|
let crawler = crawlers::HangarCrawler::new();
|
||||||
|
crawler.get_plugin_details(plugin_id).await
|
||||||
|
.map_err(|e| format!("Failed to get plugin details from HangarMC: {}", e))
|
||||||
|
},
|
||||||
|
RepositorySource::SpigotMC => {
|
||||||
|
let crawler = crawlers::SpigotMCCrawler::new();
|
||||||
|
crawler.get_plugin_details(plugin_id).await
|
||||||
|
.map_err(|e| format!("Failed to get plugin details from SpigotMC: {}", e))
|
||||||
|
},
|
||||||
|
RepositorySource::Modrinth => {
|
||||||
|
let crawler = crawlers::ModrinthCrawler::new();
|
||||||
|
|
||||||
|
// Use server type aware version if provided
|
||||||
|
if let Some(server_type) = server_type {
|
||||||
|
crawler.get_plugin_details_with_server_type(plugin_id, Some(server_type)).await
|
||||||
|
.map_err(|e| format!("Failed to get plugin details from Modrinth: {}", e))
|
||||||
|
} else {
|
||||||
|
crawler.get_plugin_details(plugin_id).await
|
||||||
|
.map_err(|e| format!("Failed to get plugin details from Modrinth: {}", e))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
RepositorySource::GitHub => {
|
||||||
return Err(format!("Failed to read plugins directory: {}", e));
|
let crawler = crawlers::GitHubCrawler::new();
|
||||||
}
|
crawler.get_plugin_details(plugin_id).await
|
||||||
}
|
.map_err(|e| format!("Failed to get plugin details from GitHub: {}", e))
|
||||||
|
|
||||||
// If no plugins were found, fall back to mock data for testing
|
|
||||||
if plugins.is_empty() && server_type == ServerType::Unknown {
|
|
||||||
// For testing only - in production, we'd just return an empty list
|
|
||||||
plugins = vec![
|
|
||||||
Plugin {
|
|
||||||
name: "EssentialsX".to_string(),
|
|
||||||
version: "2.19.0".to_string(),
|
|
||||||
latest_version: Some("2.20.0".to_string()),
|
|
||||||
description: Some("Essential server tools for Minecraft".to_string()),
|
|
||||||
authors: vec!["md_5".to_string(), "SupaHam".to_string()],
|
|
||||||
has_update: true,
|
|
||||||
api_version: Some("1.13".to_string()),
|
|
||||||
main_class: Some("com.earth2me.essentials.Essentials".to_string()),
|
|
||||||
depend: None,
|
|
||||||
soft_depend: None,
|
|
||||||
load_before: None,
|
|
||||||
commands: None,
|
|
||||||
permissions: None,
|
|
||||||
file_path: "EssentialsX.jar".to_string(),
|
|
||||||
file_hash: calculate_file_hash("EssentialsX.jar").unwrap_or_else(|_| "unknown".to_string()),
|
|
||||||
},
|
},
|
||||||
Plugin {
|
_ => Err(format!("Repository source {:?} not supported for plugin details", repository))
|
||||||
name: "WorldEdit".to_string(),
|
}
|
||||||
version: "7.2.8".to_string(),
|
}
|
||||||
latest_version: Some("7.2.8".to_string()),
|
|
||||||
description: Some("In-game map editor".to_string()),
|
/// Download a plugin from a repository
|
||||||
authors: vec!["sk89q".to_string(), "wizjany".to_string()],
|
pub async fn lib_download_plugin_from_repository(
|
||||||
has_update: false,
|
plugin_id: &str,
|
||||||
api_version: Some("1.13".to_string()),
|
version: &str,
|
||||||
main_class: Some("com.sk89q.worldedit.bukkit.WorldEditPlugin".to_string()),
|
repository: RepositorySource,
|
||||||
depend: None,
|
destination: &str,
|
||||||
soft_depend: None,
|
server_type: Option<&ServerType>
|
||||||
load_before: None,
|
) -> Result<String, String> {
|
||||||
commands: None,
|
match repository {
|
||||||
permissions: None,
|
RepositorySource::HangarMC => {
|
||||||
file_path: "WorldEdit.jar".to_string(),
|
let crawler = crawlers::HangarCrawler::new();
|
||||||
file_hash: calculate_file_hash("WorldEdit.jar").unwrap_or_else(|_| "unknown".to_string()),
|
crawler.download_plugin(plugin_id, version, Path::new(destination)).await
|
||||||
|
.map_err(|e| format!("Failed to download plugin from HangarMC: {}", e))
|
||||||
},
|
},
|
||||||
];
|
RepositorySource::SpigotMC => {
|
||||||
|
let crawler = crawlers::SpigotMCCrawler::new();
|
||||||
|
crawler.download_plugin(plugin_id, version, Path::new(destination)).await
|
||||||
|
.map_err(|e| format!("Failed to download plugin from SpigotMC: {}", e))
|
||||||
|
},
|
||||||
|
RepositorySource::Modrinth => {
|
||||||
|
let crawler = crawlers::ModrinthCrawler::new();
|
||||||
|
|
||||||
|
// Use server type aware version if provided
|
||||||
|
if let Some(server_type) = server_type {
|
||||||
|
crawler.download_plugin_with_server_type(plugin_id, version, Path::new(destination), Some(server_type)).await
|
||||||
|
.map_err(|e| format!("Failed to download plugin from Modrinth: {}", e))
|
||||||
|
} else {
|
||||||
|
crawler.download_plugin(plugin_id, version, Path::new(destination)).await
|
||||||
|
.map_err(|e| format!("Failed to download plugin from Modrinth: {}", e))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
RepositorySource::GitHub => {
|
||||||
|
let crawler = crawlers::GitHubCrawler::new();
|
||||||
|
crawler.download_plugin(plugin_id, version, Path::new(destination)).await
|
||||||
|
.map_err(|e| format!("Failed to download plugin from GitHub: {}", e))
|
||||||
|
},
|
||||||
|
_ => Err(format!("Repository source {:?} not supported for downloads", repository))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create server info
|
/// Configure and run the Tauri application
|
||||||
let server_info = ServerInfo {
|
|
||||||
server_type,
|
|
||||||
minecraft_version,
|
|
||||||
plugins_directory: plugins_dir_str,
|
|
||||||
plugins_count: plugins.len(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(ScanResult {
|
|
||||||
server_info,
|
|
||||||
plugins,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[command]
|
|
||||||
fn greet(name: &str) -> String {
|
|
||||||
format!("Hello, {}! You've been greeted from Rust!", name)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
|
// Build the Tauri application
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.plugin(tauri_plugin_opener::init())
|
|
||||||
.plugin(tauri_plugin_dialog::init())
|
.plugin(tauri_plugin_dialog::init())
|
||||||
.invoke_handler(tauri::generate_handler![greet, scan_server_directory])
|
.invoke_handler(tauri::generate_handler![
|
||||||
|
// Plugin discovery commands
|
||||||
|
scan_server_dir,
|
||||||
|
scan_server_dir_sync,
|
||||||
|
|
||||||
|
// Plugin repository commands
|
||||||
|
search_plugins,
|
||||||
|
get_plugin_details,
|
||||||
|
|
||||||
|
// Update commands
|
||||||
|
update_plugin,
|
||||||
|
check_plugin_updates,
|
||||||
|
check_single_plugin_update_command,
|
||||||
|
backup_plugin_command,
|
||||||
|
|
||||||
|
// Plugin management commands
|
||||||
|
download_plugin,
|
||||||
|
set_plugin_repository,
|
||||||
|
get_plugin_versions,
|
||||||
|
load_plugin_data,
|
||||||
|
save_plugin_data,
|
||||||
|
|
||||||
|
// Utility commands
|
||||||
|
get_potential_plugin_matches,
|
||||||
|
compare_versions,
|
||||||
|
is_plugin_compatible,
|
||||||
|
greet
|
||||||
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||||
|
|
||||||
|
// Standard library imports
|
||||||
|
use std::error::Error;
|
||||||
|
use std::fs::{self, File};
|
||||||
|
use std::io::{Read, Seek, Write};
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::env;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
// Serde for serialization/deserialization
|
||||||
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
|
// Tauri related imports
|
||||||
|
use tauri::{command, Emitter, AppHandle, Manager, State, Window};
|
||||||
|
|
||||||
|
// Internal modules
|
||||||
|
pub mod models;
|
||||||
|
pub mod services;
|
||||||
|
pub mod commands;
|
||||||
|
pub mod crawlers;
|
||||||
|
pub mod platform_matcher;
|
||||||
|
|
||||||
|
// Import our models
|
||||||
|
pub use models::server::{ServerType, ServerInfo, ScanResult, ScanProgress};
|
||||||
|
pub use models::plugin::{Plugin, PluginMeta};
|
||||||
|
pub use models::repository::{RepositorySource, RepositoryPlugin, PotentialPluginMatch};
|
||||||
|
|
||||||
|
// Import our services
|
||||||
|
pub use services::http::HttpClient;
|
||||||
|
pub use services::plugin_scanner::{scan_server_directory, perform_scan, extract_plugin_metadata, calculate_file_hash, is_file_locked};
|
||||||
|
pub use services::update_manager::{check_for_plugin_updates, check_single_plugin_update, backup_plugin, replace_plugin, normalize_version, compare_plugin_versions};
|
||||||
|
|
||||||
|
// Import our commands
|
||||||
|
pub use commands::plugin_commands::*;
|
||||||
|
pub use commands::scan_commands::*;
|
||||||
|
|
||||||
|
// Import our crawlers
|
||||||
|
pub use crawlers::HangarCrawler;
|
||||||
|
pub use crawlers::SpigotMCCrawler;
|
||||||
|
pub use crawlers::ModrinthCrawler;
|
||||||
|
pub use crawlers::GitHubCrawler;
|
||||||
|
|
||||||
|
// Import platform matchers
|
||||||
|
pub use platform_matcher::{get_compatible_modrinth_loaders, is_version_compatible_with_server};
|
||||||
|
|
||||||
|
/// Search for plugins in specified repositories
|
||||||
|
pub async fn lib_search_plugins_in_repositories(query: &str, repositories: Vec<RepositorySource>) -> Result<Vec<RepositoryPlugin>, String> {
|
||||||
|
// Implementation details to be moved from original lib.rs
|
||||||
|
Ok(Vec::new()) // Placeholder
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get plugin details from a repository
|
||||||
|
pub async fn lib_get_plugin_details_from_repository(
|
||||||
|
plugin_id: &str,
|
||||||
|
repository: RepositorySource,
|
||||||
|
server_type: Option<&ServerType>
|
||||||
|
) -> Result<RepositoryPlugin, String> {
|
||||||
|
// Implementation details to be moved from original lib.rs
|
||||||
|
Ok(RepositoryPlugin {
|
||||||
|
id: plugin_id.to_string(),
|
||||||
|
name: "Example Plugin".to_string(),
|
||||||
|
version: "1.0.0".to_string(),
|
||||||
|
description: Some("This is a placeholder".to_string()),
|
||||||
|
authors: vec!["Example Author".to_string()],
|
||||||
|
download_url: "https://example.com".to_string(),
|
||||||
|
repository: repository,
|
||||||
|
page_url: "https://example.com".to_string(),
|
||||||
|
download_count: Some(0),
|
||||||
|
last_updated: Some("2023-01-01".to_string()),
|
||||||
|
icon_url: None,
|
||||||
|
minecraft_versions: vec!["1.19.2".to_string()],
|
||||||
|
categories: vec![],
|
||||||
|
rating: None,
|
||||||
|
file_size: None,
|
||||||
|
file_hash: None,
|
||||||
|
changelog: None,
|
||||||
|
}) // Placeholder
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Download a plugin from a repository
|
||||||
|
pub async fn lib_download_plugin_from_repository(
|
||||||
|
plugin_id: &str,
|
||||||
|
version: &str,
|
||||||
|
repository: RepositorySource,
|
||||||
|
destination: &str,
|
||||||
|
server_type: Option<&ServerType>
|
||||||
|
) -> Result<String, String> {
|
||||||
|
// Implementation details to be moved from original lib.rs
|
||||||
|
Ok(destination.to_string()) // Placeholder
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Search for plugin variations
|
||||||
|
pub async fn search_with_variations(plugin_name: &str, repositories: &[RepositorySource]) -> Result<Vec<RepositoryPlugin>, String> {
|
||||||
|
// Implementation details to be moved from original lib.rs
|
||||||
|
Ok(Vec::new()) // Placeholder
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Configure and run the Tauri application
|
||||||
|
pub fn run() {
|
||||||
|
// Build the Tauri application
|
||||||
|
tauri::Builder::default()
|
||||||
|
.invoke_handler(tauri::generate_handler![
|
||||||
|
// Plugin discovery commands
|
||||||
|
scan_server_dir,
|
||||||
|
scan_server_dir_sync,
|
||||||
|
|
||||||
|
// Plugin repository commands
|
||||||
|
search_plugins,
|
||||||
|
get_plugin_details,
|
||||||
|
|
||||||
|
// Other commands to be added
|
||||||
|
])
|
||||||
|
.run(tauri::generate_context!())
|
||||||
|
.expect("error while running tauri application");
|
||||||
|
}
|
||||||
@@ -2,5 +2,5 @@
|
|||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
plugsnatcher_lib::run()
|
plugsnatcher_lib::run();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
pub mod plugin;
|
||||||
|
pub mod server;
|
||||||
|
pub mod repository;
|
||||||
|
|
||||||
|
pub use plugin::{Plugin, PluginMeta};
|
||||||
|
pub use server::{ServerInfo, ServerType, ScanResult, ScanProgress};
|
||||||
|
pub use repository::{RepositorySource, RepositoryPlugin, PotentialPluginMatch};
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
|
use super::repository::RepositorySource;
|
||||||
|
|
||||||
|
/// Represents a Minecraft plugin with detailed information
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct Plugin {
|
||||||
|
pub name: String,
|
||||||
|
pub version: String,
|
||||||
|
pub latest_version: Option<String>,
|
||||||
|
pub description: Option<String>,
|
||||||
|
pub authors: Vec<String>,
|
||||||
|
pub website: Option<String>,
|
||||||
|
pub has_update: bool,
|
||||||
|
pub api_version: Option<String>,
|
||||||
|
pub main_class: Option<String>,
|
||||||
|
pub depend: Option<Vec<String>>,
|
||||||
|
pub soft_depend: Option<Vec<String>>,
|
||||||
|
pub load_before: Option<Vec<String>>,
|
||||||
|
pub commands: Option<serde_json::Value>,
|
||||||
|
pub permissions: Option<serde_json::Value>,
|
||||||
|
pub file_path: String,
|
||||||
|
pub file_hash: String,
|
||||||
|
pub changelog: Option<String>, // Changelog for the latest version
|
||||||
|
// Fields for persistence
|
||||||
|
pub repository_source: Option<RepositorySource>,
|
||||||
|
pub repository_id: Option<String>,
|
||||||
|
pub repository_url: Option<String>, // URL to the plugin page on the repository
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Raw metadata extracted from a plugin.yml file
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct PluginMeta {
|
||||||
|
pub name: String,
|
||||||
|
pub version: String,
|
||||||
|
pub description: Option<String>,
|
||||||
|
pub authors: Vec<String>,
|
||||||
|
pub website: Option<String>,
|
||||||
|
pub api_version: Option<String>,
|
||||||
|
pub main_class: Option<String>,
|
||||||
|
pub depend: Option<Vec<String>>,
|
||||||
|
pub soft_depend: Option<Vec<String>>,
|
||||||
|
pub load_before: Option<Vec<String>>,
|
||||||
|
pub commands: Option<serde_json::Value>,
|
||||||
|
pub permissions: Option<serde_json::Value>,
|
||||||
|
pub file_path: String,
|
||||||
|
pub file_size: u64,
|
||||||
|
pub file_hash: String,
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
use serde::{Serialize, Deserialize};
|
||||||
|
use std::error::Error;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::any::Any;
|
||||||
|
|
||||||
|
/// Represents a source of plugins
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
||||||
|
pub enum RepositorySource {
|
||||||
|
HangarMC,
|
||||||
|
SpigotMC,
|
||||||
|
Modrinth,
|
||||||
|
GitHub,
|
||||||
|
BukkitDev,
|
||||||
|
Custom(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Represents a plugin from a repository
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct RepositoryPlugin {
|
||||||
|
pub id: String, // Unique identifier in the repository
|
||||||
|
pub name: String, // Plugin name
|
||||||
|
pub version: String, // Latest version
|
||||||
|
pub description: Option<String>,
|
||||||
|
pub authors: Vec<String>,
|
||||||
|
pub download_url: String, // URL to download the plugin
|
||||||
|
pub repository: RepositorySource,
|
||||||
|
pub page_url: String, // URL to the plugin page
|
||||||
|
pub download_count: Option<u64>,
|
||||||
|
pub last_updated: Option<String>,
|
||||||
|
pub icon_url: Option<String>,
|
||||||
|
pub minecraft_versions: Vec<String>,
|
||||||
|
pub categories: Vec<String>,
|
||||||
|
pub rating: Option<f32>,
|
||||||
|
pub file_size: Option<u64>,
|
||||||
|
pub file_hash: Option<String>,
|
||||||
|
pub changelog: Option<String>, // Changelog information for latest version
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Trait for crawler implementors with object safety
|
||||||
|
pub trait RepositoryCrawlerBase {
|
||||||
|
fn as_any(&self) -> &dyn Any;
|
||||||
|
fn get_repository_name(&self) -> RepositorySource;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Repository crawler search functionality
|
||||||
|
pub trait RepositoryCrawlerSearch: RepositoryCrawlerBase {
|
||||||
|
fn search<'a>(&'a self, query: &'a str) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<Vec<RepositoryPlugin>, Box<dyn Error + Send + Sync>>> + Send + 'a>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Repository crawler details functionality
|
||||||
|
pub trait RepositoryCrawlerDetails: RepositoryCrawlerBase {
|
||||||
|
fn get_plugin_details<'a>(&'a self, plugin_id: &'a str) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<RepositoryPlugin, Box<dyn Error + Send + Sync>>> + Send + 'a>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Repository crawler versions functionality
|
||||||
|
pub trait RepositoryCrawlerVersions: RepositoryCrawlerBase {
|
||||||
|
fn get_plugin_versions<'a>(&'a self, plugin_id: &'a str) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<Vec<String>, Box<dyn Error + Send + Sync>>> + Send + 'a>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Repository crawler download functionality
|
||||||
|
pub trait RepositoryCrawlerDownload: RepositoryCrawlerBase {
|
||||||
|
fn download_plugin<'a>(&'a self, plugin_id: &'a str, version: &'a str, destination: &'a Path) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<String, Box<dyn Error + Send + Sync>>> + Send + 'a>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Represents a potential match from repositories for an installed plugin
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct PotentialPluginMatch {
|
||||||
|
pub name: String,
|
||||||
|
pub version: String,
|
||||||
|
pub repository: RepositorySource,
|
||||||
|
pub repository_id: String,
|
||||||
|
pub page_url: String,
|
||||||
|
pub description: Option<String>,
|
||||||
|
pub minecraft_versions: Vec<String>,
|
||||||
|
pub download_count: Option<u64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Represents the result of a single plugin update operation
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct SingleUpdateResult {
|
||||||
|
pub original_file_path: String,
|
||||||
|
pub plugin: Option<Plugin>, // None if error occurred
|
||||||
|
pub error: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Represents the progress of bulk plugin updates
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct BulkUpdateProgress {
|
||||||
|
pub processed: usize,
|
||||||
|
pub total: usize,
|
||||||
|
pub current_plugin_name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Import required for SingleUpdateResult
|
||||||
|
use super::plugin::Plugin;
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
|
use super::plugin::Plugin;
|
||||||
|
|
||||||
|
/// Represents the type of Minecraft server
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
||||||
|
pub enum ServerType {
|
||||||
|
Paper,
|
||||||
|
Spigot,
|
||||||
|
Bukkit,
|
||||||
|
Vanilla,
|
||||||
|
Forge,
|
||||||
|
Fabric,
|
||||||
|
Velocity,
|
||||||
|
BungeeCord,
|
||||||
|
Waterfall,
|
||||||
|
Unknown,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Contains information about a Minecraft server
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct ServerInfo {
|
||||||
|
pub server_type: ServerType,
|
||||||
|
pub minecraft_version: Option<String>,
|
||||||
|
pub plugins_directory: String,
|
||||||
|
pub plugins_count: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Result of a server scan operation
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct ScanResult {
|
||||||
|
pub server_info: ServerInfo,
|
||||||
|
pub plugins: Vec<Plugin>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Progress information during a server scan
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct ScanProgress {
|
||||||
|
pub processed: usize,
|
||||||
|
pub total: usize,
|
||||||
|
pub current_file: String,
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
use crate::ServerType;
|
||||||
|
|
||||||
|
// Known platform/loader mappings
|
||||||
|
pub enum PlatformLoader {
|
||||||
|
Bukkit, // Bukkit API
|
||||||
|
Spigot, // Spigot API (Bukkit compatible)
|
||||||
|
Paper, // Paper API (Spigot compatible)
|
||||||
|
Forge, // Forge API
|
||||||
|
NeoForge, // NeoForge API (Forge fork)
|
||||||
|
Fabric, // Fabric API
|
||||||
|
Quilt, // Quilt API (Fabric compatible)
|
||||||
|
Velocity, // Velocity proxy
|
||||||
|
BungeeCord, // BungeeCord proxy
|
||||||
|
Waterfall, // Waterfall proxy (BungeeCord fork)
|
||||||
|
Sponge, // Sponge API
|
||||||
|
Unknown, // Unknown platform
|
||||||
|
}
|
||||||
|
|
||||||
|
// Maps the ServerType to a PlatformLoader
|
||||||
|
pub fn server_type_to_platform_loader(server_type: &ServerType) -> PlatformLoader {
|
||||||
|
match server_type {
|
||||||
|
ServerType::Paper => PlatformLoader::Paper,
|
||||||
|
ServerType::Spigot => PlatformLoader::Spigot,
|
||||||
|
ServerType::Bukkit => PlatformLoader::Bukkit,
|
||||||
|
ServerType::Forge => PlatformLoader::Forge,
|
||||||
|
ServerType::Fabric => PlatformLoader::Fabric,
|
||||||
|
ServerType::Velocity => PlatformLoader::Velocity,
|
||||||
|
ServerType::BungeeCord => PlatformLoader::BungeeCord,
|
||||||
|
ServerType::Waterfall => PlatformLoader::Waterfall,
|
||||||
|
ServerType::Vanilla => PlatformLoader::Unknown, // No specific loader for vanilla
|
||||||
|
ServerType::Unknown => PlatformLoader::Unknown,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Standard Modrinth loader strings
|
||||||
|
pub fn get_modrinth_loader_strings(platform: &PlatformLoader) -> Vec<String> {
|
||||||
|
match platform {
|
||||||
|
PlatformLoader::Bukkit => vec!["bukkit".to_string(), "spigot".to_string(), "paper".to_string()],
|
||||||
|
PlatformLoader::Spigot => vec!["spigot".to_string(), "paper".to_string()],
|
||||||
|
PlatformLoader::Paper => vec!["paper".to_string()],
|
||||||
|
PlatformLoader::Forge => vec!["forge".to_string()],
|
||||||
|
PlatformLoader::NeoForge => vec!["neoforge".to_string()],
|
||||||
|
PlatformLoader::Fabric => vec!["fabric".to_string()],
|
||||||
|
PlatformLoader::Quilt => vec!["quilt".to_string(), "fabric".to_string()],
|
||||||
|
PlatformLoader::Velocity => vec!["velocity".to_string()],
|
||||||
|
PlatformLoader::BungeeCord => vec!["bungeecord".to_string(), "waterfall".to_string()],
|
||||||
|
PlatformLoader::Waterfall => vec!["waterfall".to_string()],
|
||||||
|
PlatformLoader::Sponge => vec!["sponge".to_string()],
|
||||||
|
PlatformLoader::Unknown => vec![], // No specific loader strings
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compatible Modrinth loader strings (what the server can load)
|
||||||
|
pub fn get_compatible_modrinth_loaders(server_type: &ServerType) -> Vec<String> {
|
||||||
|
let platform = server_type_to_platform_loader(server_type);
|
||||||
|
|
||||||
|
match server_type {
|
||||||
|
ServerType::Paper => {
|
||||||
|
// Paper can load Paper, Spigot, and Bukkit plugins
|
||||||
|
vec!["paper".to_string(), "spigot".to_string(), "bukkit".to_string()]
|
||||||
|
},
|
||||||
|
ServerType::Spigot => {
|
||||||
|
// Spigot can load Spigot and Bukkit plugins
|
||||||
|
vec!["spigot".to_string(), "bukkit".to_string()]
|
||||||
|
},
|
||||||
|
ServerType::Bukkit => {
|
||||||
|
// Bukkit can only load Bukkit plugins
|
||||||
|
vec!["bukkit".to_string()]
|
||||||
|
},
|
||||||
|
ServerType::Forge => {
|
||||||
|
// Forge can load Forge plugins (and maybe Sponge)
|
||||||
|
vec!["forge".to_string()]
|
||||||
|
},
|
||||||
|
ServerType::Fabric => {
|
||||||
|
// Fabric can load Fabric plugins
|
||||||
|
vec!["fabric".to_string()]
|
||||||
|
},
|
||||||
|
ServerType::Velocity => {
|
||||||
|
// Velocity proxy
|
||||||
|
vec!["velocity".to_string()]
|
||||||
|
},
|
||||||
|
ServerType::BungeeCord => {
|
||||||
|
// BungeeCord can load BungeeCord plugins
|
||||||
|
vec!["bungeecord".to_string()]
|
||||||
|
},
|
||||||
|
ServerType::Waterfall => {
|
||||||
|
// Waterfall can load Waterfall and BungeeCord plugins
|
||||||
|
vec!["waterfall".to_string(), "bungeecord".to_string()]
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
// For unknown server types, return an empty list
|
||||||
|
vec![]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a version's loaders are compatible with the server type
|
||||||
|
pub fn is_version_compatible_with_server(version_loaders: &Vec<String>, server_type: &ServerType) -> bool {
|
||||||
|
// If no loaders specified, it's possibly a universal plugin, consider it compatible
|
||||||
|
if version_loaders.is_empty() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
let compatible_loaders = get_compatible_modrinth_loaders(server_type);
|
||||||
|
|
||||||
|
// If we don't know compatible loaders for this server type, be conservative and return false
|
||||||
|
if compatible_loaders.is_empty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if any loader in the version matches any compatible loader
|
||||||
|
version_loaders.iter().any(|loader| {
|
||||||
|
compatible_loaders.iter().any(|compatible|
|
||||||
|
loader.to_lowercase() == compatible.to_lowercase()
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,212 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::error::Error;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::time::Duration;
|
||||||
|
use tokio::time::sleep;
|
||||||
|
|
||||||
|
use cached::proc_macro::cached;
|
||||||
|
use reqwest;
|
||||||
|
use reqwest::header::{
|
||||||
|
HeaderMap, HeaderValue, USER_AGENT, AUTHORIZATION, ACCEPT, ACCEPT_LANGUAGE, CONNECTION, RETRY_AFTER,
|
||||||
|
};
|
||||||
|
use reqwest::StatusCode;
|
||||||
|
|
||||||
|
/// HTTP Client for making requests to external services
|
||||||
|
pub struct HttpClient {
|
||||||
|
client: reqwest::Client,
|
||||||
|
github_token: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Cache HTTP GET requests to avoid hitting rate limits
|
||||||
|
#[cached(
|
||||||
|
time = 3600, // Cache for 1 hour
|
||||||
|
size = 100, // Maximum number of cached responses
|
||||||
|
key = "String",
|
||||||
|
convert = r#"{ url.clone() }"#,
|
||||||
|
result = true
|
||||||
|
)]
|
||||||
|
async fn cached_http_get(url: String, client: reqwest::Client, token: Option<String>) -> Result<String, Box<dyn Error + Send + Sync>> {
|
||||||
|
const MAX_RETRIES: u32 = 3;
|
||||||
|
const BASE_RETRY_DELAY_MS: u64 = 1000;
|
||||||
|
|
||||||
|
let mut headers = HeaderMap::new();
|
||||||
|
|
||||||
|
// Set common headers for all requests
|
||||||
|
headers.insert(USER_AGENT, HeaderValue::from_static("PlugSnatcherApp/0.1.0"));
|
||||||
|
headers.insert(ACCEPT, HeaderValue::from_static("application/json"));
|
||||||
|
headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.5"));
|
||||||
|
headers.insert(CONNECTION, HeaderValue::from_static("keep-alive"));
|
||||||
|
|
||||||
|
// Add authorization header if token is provided
|
||||||
|
if let Some(token_value) = token {
|
||||||
|
if url.contains("github.com") {
|
||||||
|
headers.insert(
|
||||||
|
AUTHORIZATION,
|
||||||
|
HeaderValue::from_str(&format!("token {}", token_value)).unwrap_or_else(|_| HeaderValue::from_static("")),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut retry_count = 0;
|
||||||
|
let mut retry_delay = BASE_RETRY_DELAY_MS;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let response = client
|
||||||
|
.get(&url)
|
||||||
|
.headers(headers.clone())
|
||||||
|
.send()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
match response {
|
||||||
|
Ok(resp) => {
|
||||||
|
// Handle rate limiting
|
||||||
|
if resp.status() == StatusCode::TOO_MANY_REQUESTS {
|
||||||
|
if retry_count >= MAX_RETRIES {
|
||||||
|
return Err(format!("Rate limit exceeded for {}", url).into());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for Retry-After header or use exponential backoff
|
||||||
|
let retry_after = resp.headers()
|
||||||
|
.get(RETRY_AFTER)
|
||||||
|
.and_then(|val| val.to_str().ok())
|
||||||
|
.and_then(|val| val.parse::<u64>().ok())
|
||||||
|
.map(|secs| secs * 1000) // Convert header seconds to ms
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
// If no Retry-After header, just use the current exponential delay
|
||||||
|
retry_delay
|
||||||
|
});
|
||||||
|
|
||||||
|
// Exponential backoff calculation for the *next* potential retry
|
||||||
|
retry_delay *= 2;
|
||||||
|
println!("Rate limited for {}. Retrying after {} ms...", url, retry_after);
|
||||||
|
sleep(Duration::from_millis(retry_after)).await;
|
||||||
|
retry_count += 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle other responses
|
||||||
|
if resp.status().is_success() {
|
||||||
|
return Ok(resp.text().await?);
|
||||||
|
} else {
|
||||||
|
return Err(format!(
|
||||||
|
"Request to {} failed with status code: {}",
|
||||||
|
url,
|
||||||
|
resp.status()
|
||||||
|
).into());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
if retry_count >= MAX_RETRIES {
|
||||||
|
return Err(Box::new(err));
|
||||||
|
}
|
||||||
|
sleep(Duration::from_millis(retry_delay)).await;
|
||||||
|
retry_delay *= 2;
|
||||||
|
retry_count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Helper function to parse Modrinth's rate limit format
|
||||||
|
fn parse_modrinth_ratelimit(error_body: &str) -> Option<u64> {
|
||||||
|
if let Ok(json) = serde_json::from_str::<serde_json::Value>(error_body) {
|
||||||
|
if let Some(retry_after) = json.get("retry_after") {
|
||||||
|
if let Some(seconds) = retry_after.as_u64() {
|
||||||
|
return Some(seconds * 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HttpClient {
|
||||||
|
/// Create a new HTTP client
|
||||||
|
pub fn new() -> Self {
|
||||||
|
let client = reqwest::ClientBuilder::new()
|
||||||
|
.timeout(Duration::from_secs(30))
|
||||||
|
.connect_timeout(Duration::from_secs(5))
|
||||||
|
.pool_idle_timeout(Duration::from_secs(90))
|
||||||
|
.build()
|
||||||
|
.unwrap_or_else(|_| reqwest::Client::new());
|
||||||
|
|
||||||
|
// Try to get GitHub token from environment variable
|
||||||
|
let github_token = match env::var("GITHUB_API_TOKEN") {
|
||||||
|
Ok(token) if !token.is_empty() => Some(token),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
HttpClient {
|
||||||
|
client,
|
||||||
|
github_token,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Perform an HTTP GET request
|
||||||
|
pub async fn get(&self, url: &str) -> Result<String, Box<dyn Error + Send + Sync>> {
|
||||||
|
cached_http_get(url.to_string(), self.client.clone(), self.github_token.clone()).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Download a file from a URL to the specified destination
|
||||||
|
pub async fn download(&self, url: &str, destination: &Path) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||||
|
// Create a client with a larger timeout for downloads
|
||||||
|
let client = reqwest::ClientBuilder::new()
|
||||||
|
.timeout(Duration::from_secs(180)) // Longer timeout for downloads
|
||||||
|
.build()?;
|
||||||
|
|
||||||
|
let mut headers = HeaderMap::new();
|
||||||
|
headers.insert(USER_AGENT, HeaderValue::from_static("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36")); // More browser-like
|
||||||
|
|
||||||
|
// Add Accept header for everything
|
||||||
|
headers.insert(ACCEPT, HeaderValue::from_static("*/*"));
|
||||||
|
|
||||||
|
// Add headers for better browser simulation when dealing with SpigotMC
|
||||||
|
if url.contains("spigotmc.org") {
|
||||||
|
headers.insert(ACCEPT, HeaderValue::from_static("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"));
|
||||||
|
// Add custom headers as strings
|
||||||
|
let _ = headers.insert("Sec-Fetch-Dest", HeaderValue::from_static("document"));
|
||||||
|
let _ = headers.insert("Sec-Fetch-Mode", HeaderValue::from_static("navigate"));
|
||||||
|
let _ = headers.insert("Sec-Fetch-Site", HeaderValue::from_static("none"));
|
||||||
|
let _ = headers.insert("Sec-Fetch-User", HeaderValue::from_static("?1"));
|
||||||
|
headers.insert(reqwest::header::UPGRADE_INSECURE_REQUESTS, HeaderValue::from_static("1"));
|
||||||
|
println!("Added browser simulation headers for SpigotMC download");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add GitHub token if URL is GitHub and we have a token
|
||||||
|
if url.contains("github.com") && self.github_token.is_some() {
|
||||||
|
headers.insert(
|
||||||
|
AUTHORIZATION,
|
||||||
|
HeaderValue::from_str(&format!("token {}", self.github_token.as_ref().unwrap()))
|
||||||
|
.unwrap_or_else(|_| HeaderValue::from_static("")),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get response
|
||||||
|
println!("Sending download request to: {}", url);
|
||||||
|
let response = client.get(url).headers(headers).send().await?;
|
||||||
|
|
||||||
|
// Log response status
|
||||||
|
println!("Download response status: {}", response.status());
|
||||||
|
|
||||||
|
// Check if request was successful
|
||||||
|
if !response.status().is_success() {
|
||||||
|
return Err(format!("Failed to download: Status {}", response.status()).into());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get response bytes
|
||||||
|
let bytes = response.bytes().await?;
|
||||||
|
println!("Downloaded {} bytes", bytes.len());
|
||||||
|
|
||||||
|
// Create parent directories if needed
|
||||||
|
if let Some(parent) = destination.parent() {
|
||||||
|
if !parent.exists() {
|
||||||
|
std::fs::create_dir_all(parent)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write to file
|
||||||
|
std::fs::write(destination, bytes)?;
|
||||||
|
println!("Successfully wrote file to: {}", destination.display());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
mod client;
|
||||||
|
|
||||||
|
pub use client::HttpClient;
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
pub mod http;
|
||||||
|
pub mod plugin_scanner;
|
||||||
|
pub mod update_manager;
|
||||||
|
|
||||||
|
// Re-export important services
|
||||||
|
pub use http::HttpClient;
|
||||||
|
pub use plugin_scanner::{scan_server_directory, perform_scan, extract_plugin_metadata, calculate_file_hash, is_file_locked};
|
||||||
|
pub use update_manager::{check_for_plugin_updates, check_single_plugin_update, backup_plugin, replace_plugin, normalize_version, compare_plugin_versions};
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
use std::fs::{self, File};
|
||||||
|
use std::io::Read;
|
||||||
|
use std::path::Path;
|
||||||
|
use sha2::{Sha256, Digest};
|
||||||
|
|
||||||
|
/// Calculate SHA-256 hash of a file for identification and verification
|
||||||
|
pub fn calculate_file_hash(file_path: &str) -> Result<String, String> {
|
||||||
|
// Open the file
|
||||||
|
let mut file = match File::open(file_path) {
|
||||||
|
Ok(file) => file,
|
||||||
|
Err(e) => return Err(format!("Failed to open file for hashing: {}", e)),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Read the file content
|
||||||
|
let mut buffer = Vec::new();
|
||||||
|
if let Err(e) = file.read_to_end(&mut buffer) {
|
||||||
|
return Err(format!("Failed to read file for hashing: {}", e));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate the SHA-256 hash
|
||||||
|
let mut hasher = Sha256::new();
|
||||||
|
hasher.update(&buffer);
|
||||||
|
let result = hasher.finalize();
|
||||||
|
|
||||||
|
// Convert the hash to a hex string
|
||||||
|
let hash_string = format!("{:x}", result);
|
||||||
|
Ok(hash_string)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check if a file is currently locked by another process
|
||||||
|
pub fn is_file_locked(file_path: &str) -> bool {
|
||||||
|
// Try to open the file with write permissions to check if locked
|
||||||
|
match fs::OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.open(file_path)
|
||||||
|
{
|
||||||
|
Ok(_) => false, // File can be opened for writing, so it's not locked
|
||||||
|
Err(_) => {
|
||||||
|
// If we can't open for writing, try to check if it exists
|
||||||
|
// This helps determine if the error is due to file being locked
|
||||||
|
// or just not existing
|
||||||
|
Path::new(file_path).exists()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Read YAML content from a ZIP archive
|
||||||
|
pub fn read_yaml_from_archive(archive: &mut zip::ZipArchive<fs::File>, file_name: &str) -> Result<String, String> {
|
||||||
|
match archive.by_name(file_name) {
|
||||||
|
Ok(mut file) => {
|
||||||
|
let mut contents = String::new();
|
||||||
|
file.read_to_string(&mut contents)
|
||||||
|
.map_err(|e| format!("Failed to read {}: {}", file_name, e))?;
|
||||||
|
Ok(contents)
|
||||||
|
},
|
||||||
|
Err(e) => Err(format!("Failed to find {}: {}", file_name, e))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,219 @@
|
|||||||
|
use std::fs;
|
||||||
|
use std::path::Path;
|
||||||
|
use yaml_rust::{YamlLoader, Yaml};
|
||||||
|
use zip::ZipArchive;
|
||||||
|
|
||||||
|
use crate::models::plugin::PluginMeta;
|
||||||
|
use super::file_utils::{calculate_file_hash, read_yaml_from_archive};
|
||||||
|
|
||||||
|
/// Extract metadata from a plugin JAR file
|
||||||
|
pub fn extract_plugin_metadata(jar_path: &Path) -> Result<PluginMeta, String> {
|
||||||
|
// Get the file size
|
||||||
|
let metadata = match fs::metadata(jar_path) {
|
||||||
|
Ok(meta) => meta,
|
||||||
|
Err(e) => return Err(format!("Failed to get file metadata: {}", e)),
|
||||||
|
};
|
||||||
|
let file_size = metadata.len();
|
||||||
|
|
||||||
|
// Open the JAR file
|
||||||
|
let file = match fs::File::open(jar_path) {
|
||||||
|
Ok(file) => file,
|
||||||
|
Err(e) => return Err(format!("Failed to open JAR file: {}", e)),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create a ZIP archive reader
|
||||||
|
let mut archive = match ZipArchive::new(file) {
|
||||||
|
Ok(archive) => archive,
|
||||||
|
Err(e) => return Err(format!("Failed to read JAR as ZIP archive: {}", e)),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Try to read plugin.yml
|
||||||
|
let yaml_content = match read_yaml_from_archive(&mut archive, "plugin.yml") {
|
||||||
|
Ok(content) => content,
|
||||||
|
Err(_) => {
|
||||||
|
// If plugin.yml is not found, try bungee.yml for BungeeCord plugins
|
||||||
|
match read_yaml_from_archive(&mut archive, "bungee.yml") {
|
||||||
|
Ok(content) => content,
|
||||||
|
Err(_) => {
|
||||||
|
// If neither is found, use fallback metadata
|
||||||
|
return fallback_plugin_meta(jar_path, file_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Parse the YAML content
|
||||||
|
let docs = match YamlLoader::load_from_str(&yaml_content) {
|
||||||
|
Ok(docs) => docs,
|
||||||
|
Err(e) => return Err(format!("Failed to parse plugin.yml: {}", e)),
|
||||||
|
};
|
||||||
|
|
||||||
|
// If there's no document in the YAML, use fallback
|
||||||
|
if docs.is_empty() {
|
||||||
|
return fallback_plugin_meta(jar_path, file_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
let doc = &docs[0];
|
||||||
|
|
||||||
|
// Extract plugin information
|
||||||
|
let name = yaml_str_with_fallback(doc, "name", jar_path);
|
||||||
|
let version = yaml_str_with_fallback(doc, "version", jar_path);
|
||||||
|
let description = yaml_str_opt(doc, "description");
|
||||||
|
let website = yaml_str_opt(doc, "website");
|
||||||
|
let api_version = yaml_str_opt(doc, "api-version");
|
||||||
|
let main_class = yaml_str_opt(doc, "main");
|
||||||
|
|
||||||
|
// Extract author/authors
|
||||||
|
let authors = match &doc["author"] {
|
||||||
|
Yaml::String(author) => vec![author.clone()],
|
||||||
|
_ => match &doc["authors"] {
|
||||||
|
Yaml::Array(authors) => authors
|
||||||
|
.iter()
|
||||||
|
.filter_map(|a| match a {
|
||||||
|
Yaml::String(s) => Some(s.clone()),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
Yaml::String(author) => vec![author.clone()],
|
||||||
|
_ => Vec::new(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Extract dependencies
|
||||||
|
let depend = yaml_str_array(doc, "depend");
|
||||||
|
let soft_depend = yaml_str_array(doc, "softdepend");
|
||||||
|
let load_before = yaml_str_array(doc, "loadbefore");
|
||||||
|
|
||||||
|
// Extract commands and permissions
|
||||||
|
let commands = match &doc["commands"] {
|
||||||
|
Yaml::Hash(_) => {
|
||||||
|
Some(serde_json::Value::String("Commands data present".to_string()))
|
||||||
|
},
|
||||||
|
_ => None
|
||||||
|
};
|
||||||
|
|
||||||
|
let permissions = match &doc["permissions"] {
|
||||||
|
Yaml::Hash(_) => {
|
||||||
|
Some(serde_json::Value::String("Permissions data present".to_string()))
|
||||||
|
},
|
||||||
|
_ => None
|
||||||
|
};
|
||||||
|
|
||||||
|
// Calculate the file hash
|
||||||
|
let file_hash = calculate_file_hash(jar_path.to_str().unwrap_or("unknown.jar")).unwrap_or_else(|_| "unknown".to_string());
|
||||||
|
|
||||||
|
Ok(PluginMeta {
|
||||||
|
name,
|
||||||
|
version,
|
||||||
|
description,
|
||||||
|
authors,
|
||||||
|
api_version,
|
||||||
|
main_class,
|
||||||
|
depend,
|
||||||
|
soft_depend,
|
||||||
|
load_before,
|
||||||
|
commands,
|
||||||
|
permissions,
|
||||||
|
file_path: jar_path.to_string_lossy().to_string(),
|
||||||
|
file_size,
|
||||||
|
file_hash,
|
||||||
|
website,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create plugin metadata with fallback values
|
||||||
|
fn fallback_plugin_meta(jar_path: &Path, file_size: u64) -> Result<PluginMeta, String> {
|
||||||
|
let filename = jar_path.file_name()
|
||||||
|
.and_then(|n| n.to_str())
|
||||||
|
.unwrap_or("unknown.jar");
|
||||||
|
|
||||||
|
// Extract name and version from filename (e.g., "WorldEdit-7.2.8.jar" → name: "WorldEdit", version: "7.2.8")
|
||||||
|
let mut parts: Vec<&str> = filename.trim_end_matches(".jar").split('-').collect();
|
||||||
|
let version = if parts.len() > 1 {
|
||||||
|
parts.pop().unwrap_or("1.0.0").to_string()
|
||||||
|
} else {
|
||||||
|
"1.0.0".to_string()
|
||||||
|
};
|
||||||
|
|
||||||
|
let name = parts.join("-");
|
||||||
|
|
||||||
|
// Calculate hash
|
||||||
|
let file_hash = calculate_file_hash(jar_path.to_str().unwrap_or("unknown.jar")).unwrap_or_else(|_| "unknown".to_string());
|
||||||
|
|
||||||
|
Ok(PluginMeta {
|
||||||
|
name,
|
||||||
|
version,
|
||||||
|
description: None,
|
||||||
|
authors: Vec::new(),
|
||||||
|
website: None,
|
||||||
|
api_version: None,
|
||||||
|
main_class: None,
|
||||||
|
depend: None,
|
||||||
|
soft_depend: None,
|
||||||
|
load_before: None,
|
||||||
|
commands: None,
|
||||||
|
permissions: None,
|
||||||
|
file_path: jar_path.to_string_lossy().to_string(),
|
||||||
|
file_size,
|
||||||
|
file_hash,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Helper function to extract a string with fallback
|
||||||
|
fn yaml_str_with_fallback(yaml: &Yaml, key: &str, jar_path: &Path) -> String {
|
||||||
|
match yaml[key] {
|
||||||
|
Yaml::String(ref s) => s.clone(),
|
||||||
|
_ => {
|
||||||
|
// Fallback to the JAR filename without extension
|
||||||
|
let filename = jar_path
|
||||||
|
.file_name()
|
||||||
|
.and_then(|n| n.to_str())
|
||||||
|
.unwrap_or("unknown")
|
||||||
|
.trim_end_matches(".jar");
|
||||||
|
|
||||||
|
if key == "name" {
|
||||||
|
let name_parts: Vec<&str> = filename.split('-').collect();
|
||||||
|
name_parts[0].to_string()
|
||||||
|
} else if key == "version" {
|
||||||
|
let version_parts: Vec<&str> = filename.split('-').collect();
|
||||||
|
if version_parts.len() > 1 {
|
||||||
|
version_parts[1].to_string()
|
||||||
|
} else {
|
||||||
|
"1.0.0".to_string()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
"".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Helper function to extract an optional string
|
||||||
|
fn yaml_str_opt(yaml: &Yaml, key: &str) -> Option<String> {
|
||||||
|
match &yaml[key] {
|
||||||
|
Yaml::String(s) => Some(s.clone()),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Helper function to extract an array of strings
|
||||||
|
fn yaml_str_array(yaml: &Yaml, key: &str) -> Option<Vec<String>> {
|
||||||
|
match &yaml[key] {
|
||||||
|
Yaml::Array(arr) => {
|
||||||
|
let string_arr: Vec<String> = arr
|
||||||
|
.iter()
|
||||||
|
.filter_map(|item| match item {
|
||||||
|
Yaml::String(s) => Some(s.clone()),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if string_arr.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(string_arr)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
mod scanner;
|
||||||
|
mod metadata_extractor;
|
||||||
|
mod file_utils;
|
||||||
|
|
||||||
|
pub use scanner::{scan_server_directory, perform_scan, get_plugin_data_path};
|
||||||
|
pub use metadata_extractor::extract_plugin_metadata;
|
||||||
|
pub use file_utils::{calculate_file_hash, is_file_locked};
|
||||||
@@ -0,0 +1,409 @@
|
|||||||
|
use std::fs;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use tauri::{AppHandle, Manager, Emitter};
|
||||||
|
use walkdir::WalkDir;
|
||||||
|
use regex::Regex;
|
||||||
|
use std::ffi::OsStr;
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
|
use crate::models::server::{ServerType, ServerInfo, ScanResult, ScanProgress};
|
||||||
|
use crate::models::plugin::Plugin;
|
||||||
|
use super::metadata_extractor::extract_plugin_metadata;
|
||||||
|
|
||||||
|
/// Scan a server directory and emit progress events
|
||||||
|
pub async fn scan_server_directory(app_handle: AppHandle, path: String) -> Result<(), String> {
|
||||||
|
// Get the main window
|
||||||
|
let window = app_handle.get_webview_window("main").ok_or("Main window not found")?;
|
||||||
|
|
||||||
|
println!("Starting scan for server directory: {}", path);
|
||||||
|
|
||||||
|
// Start the scan
|
||||||
|
match window.emit("scan_started", {}) {
|
||||||
|
Ok(_) => println!("Emitted scan_started event successfully"),
|
||||||
|
Err(e) => {
|
||||||
|
let err_msg = format!("Failed to emit scan_started event: {}", e);
|
||||||
|
println!("{}", err_msg);
|
||||||
|
return Err(err_msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform the actual scan in a separate function
|
||||||
|
match perform_scan(&app_handle, &path).await {
|
||||||
|
Ok(result) => {
|
||||||
|
println!("Scan completed successfully. Found {} plugins", result.plugins.len());
|
||||||
|
|
||||||
|
// Save the scan result to disk
|
||||||
|
match save_plugin_data(app_handle.clone(), result.plugins.clone(), path.clone()).await {
|
||||||
|
Ok(_) => println!("Saved plugin data to disk successfully"),
|
||||||
|
Err(e) => println!("Failed to save plugin data: {}", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Emit scan completion event with the result
|
||||||
|
println!("Emitting scan_completed event with {} plugins", result.plugins.len());
|
||||||
|
match window.emit("scan_completed", result.clone()) {
|
||||||
|
Ok(_) => {
|
||||||
|
println!("Emitted scan_completed event successfully");
|
||||||
|
Ok(())
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
let err_msg = format!("Failed to emit scan_completed event: {}", e);
|
||||||
|
println!("{}", err_msg);
|
||||||
|
Err(err_msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
println!("Scan failed with error: {}", e);
|
||||||
|
|
||||||
|
// Emit scan error event
|
||||||
|
match window.emit("scan_error", e.clone()) {
|
||||||
|
Ok(_) => println!("Emitted scan_error event successfully"),
|
||||||
|
Err(err) => println!("Failed to emit scan_error event: {}", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Perform a scan of the server directory
|
||||||
|
pub async fn perform_scan(app_handle: &AppHandle, path: &str) -> Result<ScanResult, String> {
|
||||||
|
// Normalize the path and check if it exists
|
||||||
|
let server_path = Path::new(path);
|
||||||
|
if !server_path.exists() {
|
||||||
|
return Err(format!("Server directory not found: {}", path));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detect server type
|
||||||
|
let server_type = detect_server_type(server_path);
|
||||||
|
|
||||||
|
// Find Minecraft version
|
||||||
|
let minecraft_version = detect_minecraft_version(server_path, &server_type);
|
||||||
|
|
||||||
|
// Find plugins directory
|
||||||
|
let plugins_dir = get_plugins_directory(server_path, &server_type);
|
||||||
|
let plugins_path = Path::new(&plugins_dir);
|
||||||
|
|
||||||
|
// Check if plugins directory exists
|
||||||
|
if !plugins_path.exists() {
|
||||||
|
return Err(format!("Plugins directory not found: {}", plugins_dir));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all JAR files in plugins directory
|
||||||
|
let mut plugin_files = Vec::new();
|
||||||
|
for entry in WalkDir::new(plugins_path)
|
||||||
|
.max_depth(1) // Only scan the top level
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|e| e.ok())
|
||||||
|
{
|
||||||
|
let path = entry.path();
|
||||||
|
if path.is_file() && path.extension() == Some(OsStr::new("jar")) {
|
||||||
|
plugin_files.push(path.to_path_buf());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create server info object
|
||||||
|
let server_info = ServerInfo {
|
||||||
|
server_type,
|
||||||
|
minecraft_version,
|
||||||
|
plugins_directory: plugins_dir,
|
||||||
|
plugins_count: plugin_files.len(),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Emit total plugin count
|
||||||
|
app_handle.emit("scan_progress", ScanProgress {
|
||||||
|
processed: 0,
|
||||||
|
total: plugin_files.len(),
|
||||||
|
current_file: "Starting scan...".to_string(),
|
||||||
|
}).map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
// Process each plugin
|
||||||
|
let mut plugins = Vec::new();
|
||||||
|
for (index, jar_path) in plugin_files.iter().enumerate() {
|
||||||
|
// Emit progress update
|
||||||
|
let file_name = jar_path.file_name()
|
||||||
|
.and_then(|n| n.to_str())
|
||||||
|
.unwrap_or("unknown.jar");
|
||||||
|
|
||||||
|
app_handle.emit("scan_progress", ScanProgress {
|
||||||
|
processed: index,
|
||||||
|
total: plugin_files.len(),
|
||||||
|
current_file: file_name.to_string(),
|
||||||
|
}).map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
// Extract plugin metadata
|
||||||
|
match extract_plugin_metadata(jar_path) {
|
||||||
|
Ok(meta) => {
|
||||||
|
// Convert PluginMeta to Plugin
|
||||||
|
let plugin = Plugin {
|
||||||
|
name: meta.name,
|
||||||
|
version: meta.version,
|
||||||
|
latest_version: None, // Will be populated during update check
|
||||||
|
description: meta.description,
|
||||||
|
authors: meta.authors,
|
||||||
|
website: meta.website,
|
||||||
|
has_update: false, // Will be populated during update check
|
||||||
|
api_version: meta.api_version,
|
||||||
|
main_class: meta.main_class,
|
||||||
|
depend: meta.depend,
|
||||||
|
soft_depend: meta.soft_depend,
|
||||||
|
load_before: meta.load_before,
|
||||||
|
commands: meta.commands,
|
||||||
|
permissions: meta.permissions,
|
||||||
|
file_path: meta.file_path,
|
||||||
|
file_hash: meta.file_hash,
|
||||||
|
changelog: None, // Will be populated during update check
|
||||||
|
repository_source: None, // Will be populated during update check
|
||||||
|
repository_id: None, // Will be populated during update check
|
||||||
|
repository_url: None, // Will be populated during update check
|
||||||
|
};
|
||||||
|
plugins.push(plugin);
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
// Log the error but continue processing other plugins
|
||||||
|
eprintln!("Error extracting metadata from {}: {}", file_name, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Emit final progress
|
||||||
|
app_handle.emit("scan_progress", ScanProgress {
|
||||||
|
processed: plugin_files.len(),
|
||||||
|
total: plugin_files.len(),
|
||||||
|
current_file: "Scan complete".to_string(),
|
||||||
|
}).map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
// Return the result
|
||||||
|
Ok(ScanResult {
|
||||||
|
server_info,
|
||||||
|
plugins,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Detect the type of Minecraft server
|
||||||
|
fn detect_server_type(server_path: &Path) -> ServerType {
|
||||||
|
// Check for server JAR file
|
||||||
|
if let Some(jar_path) = find_server_jar(server_path) {
|
||||||
|
let jar_filename = jar_path.file_name()
|
||||||
|
.and_then(|n| n.to_str())
|
||||||
|
.unwrap_or("");
|
||||||
|
|
||||||
|
// Convert filename to lowercase for easier matching
|
||||||
|
let filename_lower = jar_filename.to_lowercase();
|
||||||
|
|
||||||
|
// Check for known server types
|
||||||
|
if filename_lower.contains("paper") {
|
||||||
|
return ServerType::Paper;
|
||||||
|
} else if filename_lower.contains("spigot") {
|
||||||
|
return ServerType::Spigot;
|
||||||
|
} else if filename_lower.contains("bukkit") || filename_lower.contains("craftbukkit") {
|
||||||
|
return ServerType::Bukkit;
|
||||||
|
} else if filename_lower.contains("forge") {
|
||||||
|
return ServerType::Forge;
|
||||||
|
} else if filename_lower.contains("fabric") {
|
||||||
|
return ServerType::Fabric;
|
||||||
|
} else if filename_lower.contains("velocity") {
|
||||||
|
return ServerType::Velocity;
|
||||||
|
} else if filename_lower.contains("bungeecord") {
|
||||||
|
return ServerType::BungeeCord;
|
||||||
|
} else if filename_lower.contains("waterfall") {
|
||||||
|
return ServerType::Waterfall;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If server.properties exists, it's likely a vanilla or modified vanilla server
|
||||||
|
if server_path.join("server.properties").exists() {
|
||||||
|
// Check if there's a plugins directory
|
||||||
|
if server_path.join("plugins").exists() {
|
||||||
|
// Assume Spigot if we can't tell more specifically but plugins exist
|
||||||
|
return ServerType::Spigot;
|
||||||
|
}
|
||||||
|
return ServerType::Vanilla;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we can't determine, check for directory structure hints
|
||||||
|
if server_path.join("plugins").exists() {
|
||||||
|
if server_path.join("cache").exists() && server_path.join("modules").exists() {
|
||||||
|
return ServerType::Velocity;
|
||||||
|
} else if server_path.join("libraries").exists() && server_path.join("mods").exists() {
|
||||||
|
return ServerType::Forge;
|
||||||
|
} else {
|
||||||
|
return ServerType::Spigot; // Default assumption for server with plugins
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerType::Unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Find the server JAR file in the server directory
|
||||||
|
fn find_server_jar(server_path: &Path) -> Option<PathBuf> {
|
||||||
|
// Define pattern for server JAR files
|
||||||
|
let server_jar_pattern = Regex::new(r"^(paper|spigot|craftbukkit|minecraft|fabric|forge|velocity|bungeecord|waterfall).*\.jar$").unwrap();
|
||||||
|
|
||||||
|
// Look for JAR files in the directory
|
||||||
|
let entries = match fs::read_dir(server_path) {
|
||||||
|
Ok(entries) => entries,
|
||||||
|
Err(_) => return None,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check each entry
|
||||||
|
for entry in entries {
|
||||||
|
if let Ok(entry) = entry {
|
||||||
|
if let Some(filename) = entry.file_name().to_str() {
|
||||||
|
// Check if it matches server JAR pattern
|
||||||
|
if filename.to_lowercase().ends_with(".jar") {
|
||||||
|
if server_jar_pattern.is_match(&filename.to_lowercase()) {
|
||||||
|
return Some(entry.path());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also check for common naming patterns
|
||||||
|
if filename.contains("server") || filename == "server.jar" {
|
||||||
|
return Some(entry.path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Detect the Minecraft version from server files
|
||||||
|
fn detect_minecraft_version(server_path: &Path, server_type: &ServerType) -> Option<String> {
|
||||||
|
// Try to find server JAR
|
||||||
|
if let Some(jar_path) = find_server_jar(server_path) {
|
||||||
|
// Try to extract version from JAR filename
|
||||||
|
if let Some(filename) = jar_path.file_name().and_then(|n| n.to_str()) {
|
||||||
|
// Look for version pattern like 1.19.2 in filename
|
||||||
|
let version_pattern = Regex::new(r"(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)").unwrap();
|
||||||
|
if let Some(captures) = version_pattern.captures(filename) {
|
||||||
|
if let Some(version_match) = captures.get(0) {
|
||||||
|
return Some(version_match.as_str().to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If version not found in filename, try to read it from the JAR
|
||||||
|
return read_version_from_jar(&jar_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try server.properties for vanilla/bukkit/spigot servers
|
||||||
|
if matches!(server_type, ServerType::Vanilla | ServerType::Bukkit | ServerType::Spigot | ServerType::Paper) {
|
||||||
|
let properties_path = server_path.join("server.properties");
|
||||||
|
if properties_path.exists() {
|
||||||
|
// Read properties file
|
||||||
|
if let Ok(content) = fs::read_to_string(properties_path) {
|
||||||
|
// Look for the level-type property
|
||||||
|
for line in content.lines() {
|
||||||
|
if line.starts_with("level-name=") {
|
||||||
|
// Try to find version.json in the level directory
|
||||||
|
let level_name = line.trim_start_matches("level-name=").trim();
|
||||||
|
let version_json_path = server_path.join(level_name).join("version.json");
|
||||||
|
if version_json_path.exists() {
|
||||||
|
if let Ok(version_content) = fs::read_to_string(version_json_path) {
|
||||||
|
if let Ok(json) = serde_json::from_str::<serde_json::Value>(&version_content) {
|
||||||
|
if let Some(name) = json.get("name").and_then(|n| n.as_str()) {
|
||||||
|
return Some(name.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Read version information from a JAR file
|
||||||
|
fn read_version_from_jar(jar_path: &Path) -> Option<String> {
|
||||||
|
// Open the JAR file
|
||||||
|
let file = match fs::File::open(jar_path) {
|
||||||
|
Ok(file) => file,
|
||||||
|
Err(_) => return None,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create a ZIP archive reader
|
||||||
|
let mut archive = match zip::ZipArchive::new(file) {
|
||||||
|
Ok(archive) => archive,
|
||||||
|
Err(_) => return None,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Try to find version.json or similar file
|
||||||
|
for i in 0..archive.len() {
|
||||||
|
let mut file = match archive.by_index(i) {
|
||||||
|
Ok(file) => file,
|
||||||
|
Err(_) => continue,
|
||||||
|
};
|
||||||
|
|
||||||
|
let name = file.name();
|
||||||
|
|
||||||
|
// Check various version files
|
||||||
|
if name.ends_with("version.json") || name.contains("version") && name.ends_with(".json") {
|
||||||
|
let mut contents = String::new();
|
||||||
|
if let Err(_) = file.read_to_string(&mut contents) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(json) = serde_json::from_str::<serde_json::Value>(&contents) {
|
||||||
|
// Try different possible keys for version
|
||||||
|
for key in ["name", "version", "minecraft_version", "id"] {
|
||||||
|
if let Some(version) = json.get(key).and_then(|v| v.as_str()) {
|
||||||
|
return Some(version.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the plugins directory for the server
|
||||||
|
fn get_plugins_directory(server_path: &Path, server_type: &ServerType) -> String {
|
||||||
|
match server_type {
|
||||||
|
ServerType::Velocity | ServerType::BungeeCord | ServerType::Waterfall => {
|
||||||
|
server_path.join("plugins").to_string_lossy().to_string()
|
||||||
|
},
|
||||||
|
_ => server_path.join("plugins").to_string_lossy().to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Save plugin data to disk for persistence
|
||||||
|
async fn save_plugin_data(app_handle: AppHandle, plugins: Vec<Plugin>, server_path: String) -> Result<(), String> {
|
||||||
|
// Get plugin data path
|
||||||
|
let data_dir = get_plugin_data_path(&app_handle, &server_path)?;
|
||||||
|
|
||||||
|
// Create directory if it doesn't exist
|
||||||
|
if !data_dir.exists() {
|
||||||
|
fs::create_dir_all(&data_dir)
|
||||||
|
.map_err(|e| format!("Failed to create data directory: {}", e))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save plugins data
|
||||||
|
let data_path = data_dir.join("plugins.json");
|
||||||
|
let json_data = serde_json::to_string_pretty(&plugins)
|
||||||
|
.map_err(|e| format!("Failed to serialize plugin data: {}", e))?;
|
||||||
|
|
||||||
|
fs::write(&data_path, json_data)
|
||||||
|
.map_err(|e| format!("Failed to write plugin data: {}", e))?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get plugin data directory path
|
||||||
|
pub fn get_plugin_data_path(app_handle: &AppHandle, server_path: &str) -> Result<PathBuf, String> {
|
||||||
|
let app_data_dir = app_handle.path().app_data_dir()
|
||||||
|
.map_err(|e| format!("Failed to get app data directory: {}", e))?;
|
||||||
|
|
||||||
|
// Hash the server path to create a unique identifier
|
||||||
|
use sha2::Digest;
|
||||||
|
let mut hasher = sha2::Sha256::new();
|
||||||
|
hasher.update(server_path.as_bytes());
|
||||||
|
let server_hash = format!("{:x}", hasher.finalize());
|
||||||
|
|
||||||
|
// Create a directory for this server
|
||||||
|
Ok(app_data_dir.join("servers").join(server_hash))
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
mod update_checker;
|
||||||
|
mod version_utils;
|
||||||
|
mod plugin_updater;
|
||||||
|
|
||||||
|
pub use update_checker::{check_for_plugin_updates, check_single_plugin_update};
|
||||||
|
pub use version_utils::{normalize_version, compare_plugin_versions};
|
||||||
|
pub use plugin_updater::{backup_plugin, replace_plugin};
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::fs;
|
||||||
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
use regex;
|
||||||
|
|
||||||
|
use crate::models::repository::RepositorySource;
|
||||||
|
use crate::models::server::ServerInfo;
|
||||||
|
use crate::services::plugin_scanner::is_file_locked;
|
||||||
|
|
||||||
|
/// Backup a plugin before replacing it
|
||||||
|
pub async fn backup_plugin(plugin_file_path: String) -> Result<String, String> {
|
||||||
|
// Get the current timestamp for the backup filename
|
||||||
|
let now = SystemTime::now().duration_since(UNIX_EPOCH)
|
||||||
|
.map_err(|e| format!("Failed to get timestamp: {}", e))?
|
||||||
|
.as_secs();
|
||||||
|
|
||||||
|
// Create backup file path
|
||||||
|
let path = Path::new(&plugin_file_path);
|
||||||
|
let file_name = path.file_name()
|
||||||
|
.ok_or_else(|| "Invalid plugin file path".to_string())?
|
||||||
|
.to_str()
|
||||||
|
.ok_or_else(|| "Invalid file name encoding".to_string())?;
|
||||||
|
|
||||||
|
// Create backup directory if it doesn't exist
|
||||||
|
let backup_dir = path.parent()
|
||||||
|
.unwrap_or_else(|| Path::new("."))
|
||||||
|
.join("backups");
|
||||||
|
|
||||||
|
if !backup_dir.exists() {
|
||||||
|
fs::create_dir_all(&backup_dir)
|
||||||
|
.map_err(|e| format!("Failed to create backup directory: {}", e))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create backup file path with timestamp
|
||||||
|
let backup_path = backup_dir.join(format!("{}.{}.bak", file_name, now));
|
||||||
|
let backup_path_str = backup_path.to_string_lossy().to_string();
|
||||||
|
|
||||||
|
// Check if file is locked
|
||||||
|
if is_file_locked(&plugin_file_path) {
|
||||||
|
return Err(format!("File is locked: {}", plugin_file_path));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy the file
|
||||||
|
fs::copy(&plugin_file_path, &backup_path)
|
||||||
|
.map_err(|e| format!("Failed to create backup: {}", e))?;
|
||||||
|
|
||||||
|
Ok(backup_path_str)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Replace a plugin with a new version
|
||||||
|
pub async fn replace_plugin(
|
||||||
|
plugin_id: String,
|
||||||
|
version: String,
|
||||||
|
repository: RepositorySource,
|
||||||
|
current_file_path: String,
|
||||||
|
server_info: Option<ServerInfo>
|
||||||
|
) -> Result<String, String> {
|
||||||
|
// Check if file is locked
|
||||||
|
if is_file_locked(¤t_file_path) {
|
||||||
|
return Err(format!("Plugin file is currently locked: {}", current_file_path));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a temporary file path
|
||||||
|
let download_path = create_temp_download_path(¤t_file_path)?;
|
||||||
|
|
||||||
|
// Download the new plugin version
|
||||||
|
let server_type = server_info.as_ref().map(|info| &info.server_type);
|
||||||
|
let download_result = crate::lib_download_plugin_from_repository(
|
||||||
|
&plugin_id,
|
||||||
|
&version,
|
||||||
|
repository,
|
||||||
|
&download_path.to_string_lossy(),
|
||||||
|
server_type
|
||||||
|
).await;
|
||||||
|
|
||||||
|
// Check for premium resource indicator
|
||||||
|
if let Err(error) = &download_result {
|
||||||
|
if error.starts_with("PREMIUM_RESOURCE:") {
|
||||||
|
// Extract the resource URL from the error
|
||||||
|
let resource_url = error.strip_prefix("PREMIUM_RESOURCE:").unwrap_or_default();
|
||||||
|
return Err(format!("PREMIUM_RESOURCE:{}:{}:{}", plugin_id, version, resource_url));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If other error, propagate it
|
||||||
|
let _ = download_result?;
|
||||||
|
|
||||||
|
// Backup the original file
|
||||||
|
backup_plugin(current_file_path.clone()).await?;
|
||||||
|
|
||||||
|
// Determine new file name with version
|
||||||
|
let new_file_path = create_versioned_file_path(¤t_file_path, &version)?;
|
||||||
|
|
||||||
|
// Replace the original file with the downloaded one
|
||||||
|
// Use the new file path with version instead of the original path
|
||||||
|
fs::rename(download_path, &new_file_path)
|
||||||
|
.map_err(|e| format!("Failed to replace plugin: {}", e))?;
|
||||||
|
|
||||||
|
// Remove the old file if the path changed
|
||||||
|
if new_file_path != current_file_path {
|
||||||
|
match fs::remove_file(¤t_file_path) {
|
||||||
|
Ok(_) => println!("Removed old plugin file: {}", current_file_path),
|
||||||
|
Err(e) => println!("Warning: Could not remove old plugin file {}: {}", current_file_path, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(new_file_path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a temporary file path for plugin download
|
||||||
|
fn create_temp_download_path(current_file_path: &str) -> Result<PathBuf, String> {
|
||||||
|
let path = Path::new(current_file_path);
|
||||||
|
let file_stem = path.file_stem()
|
||||||
|
.ok_or_else(|| "Invalid plugin file path".to_string())?
|
||||||
|
.to_str()
|
||||||
|
.ok_or_else(|| "Invalid file name encoding".to_string())?;
|
||||||
|
|
||||||
|
let file_ext = path.extension()
|
||||||
|
.unwrap_or_else(|| std::ffi::OsStr::new("jar"))
|
||||||
|
.to_str()
|
||||||
|
.unwrap_or("jar");
|
||||||
|
|
||||||
|
let parent = path.parent()
|
||||||
|
.unwrap_or_else(|| Path::new("."));
|
||||||
|
|
||||||
|
// Generate temp file name with timestamp
|
||||||
|
let now = SystemTime::now().duration_since(UNIX_EPOCH)
|
||||||
|
.map_err(|e| format!("Failed to get timestamp: {}", e))?
|
||||||
|
.as_secs();
|
||||||
|
|
||||||
|
let temp_name = format!("{}.new.{}.{}", file_stem, now, file_ext);
|
||||||
|
Ok(parent.join(temp_name))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a versioned file path for the updated plugin
|
||||||
|
fn create_versioned_file_path(current_file_path: &str, version: &str) -> Result<String, String> {
|
||||||
|
let path = Path::new(current_file_path);
|
||||||
|
let file_name = path.file_name()
|
||||||
|
.ok_or_else(|| "Invalid plugin file path".to_string())?
|
||||||
|
.to_str()
|
||||||
|
.ok_or_else(|| "Invalid file name encoding".to_string())?;
|
||||||
|
|
||||||
|
let parent = path.parent()
|
||||||
|
.unwrap_or_else(|| Path::new("."));
|
||||||
|
|
||||||
|
// Check if the file name already has a version pattern
|
||||||
|
// Common formats: PluginName-1.2.3.jar, PluginName-v1.2.3.jar, PluginName_1.2.3.jar
|
||||||
|
if let Some(captures) = regex::Regex::new(r"^([A-Za-z0-9_]+)[-_]v?[\d\.]+(\.[a-zA-Z0-9]+)$")
|
||||||
|
.unwrap()
|
||||||
|
.captures(file_name) {
|
||||||
|
// Get the plugin name without version
|
||||||
|
let base_name = captures.get(1).unwrap().as_str();
|
||||||
|
let extension = captures.get(2).unwrap().as_str();
|
||||||
|
|
||||||
|
// Create new filename with updated version
|
||||||
|
let new_file_name = format!("{}-{}{}", base_name, version, extension);
|
||||||
|
return Ok(parent.join(new_file_name).to_string_lossy().to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no version pattern, just return the original path
|
||||||
|
Ok(current_file_path.to_string())
|
||||||
|
}
|
||||||
@@ -0,0 +1,276 @@
|
|||||||
|
use tauri::{AppHandle, Emitter};
|
||||||
|
use futures::stream::StreamExt;
|
||||||
|
|
||||||
|
use crate::models::plugin::Plugin;
|
||||||
|
use crate::models::repository::{RepositorySource, RepositoryPlugin, BulkUpdateProgress, SingleUpdateResult};
|
||||||
|
use super::version_utils::compare_plugin_versions;
|
||||||
|
|
||||||
|
/// Check for updates for multiple plugins
|
||||||
|
pub async fn check_for_plugin_updates(
|
||||||
|
app_handle: AppHandle,
|
||||||
|
installed_plugins: Vec<Plugin>,
|
||||||
|
repositories_to_check: Vec<RepositorySource>
|
||||||
|
) -> Result<Vec<Plugin>, String> {
|
||||||
|
if installed_plugins.is_empty() {
|
||||||
|
return Ok(Vec::new());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone plugins for returning
|
||||||
|
let mut updated_plugins = installed_plugins.clone();
|
||||||
|
|
||||||
|
// Initialize progress
|
||||||
|
let total = installed_plugins.len();
|
||||||
|
println!("Starting bulk update check for {} plugins", total);
|
||||||
|
|
||||||
|
if let Err(e) = app_handle.emit("bulk_update_start", total) {
|
||||||
|
return Err(format!("Failed to emit bulk_update_start event: {}", e));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process plugins in batches to avoid overwhelming the system
|
||||||
|
let batch_size = 5;
|
||||||
|
for (batch_index, chunk) in installed_plugins.chunks(batch_size).enumerate() {
|
||||||
|
let mut batch_futures = Vec::new();
|
||||||
|
|
||||||
|
// Create futures for this batch
|
||||||
|
for (i, plugin) in chunk.iter().enumerate() {
|
||||||
|
let index = batch_index * batch_size + i;
|
||||||
|
let app_handle_clone = app_handle.clone();
|
||||||
|
let repos_clone = repositories_to_check.clone();
|
||||||
|
let plugin_clone = plugin.clone();
|
||||||
|
|
||||||
|
// Report progress
|
||||||
|
let progress = BulkUpdateProgress {
|
||||||
|
processed: index,
|
||||||
|
total,
|
||||||
|
current_plugin_name: plugin.name.clone(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(e) = app_handle_clone.emit("update_check_progress", progress) {
|
||||||
|
println!("Failed to emit update progress: {}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add to batch
|
||||||
|
batch_futures.push(async move {
|
||||||
|
// Process plugin
|
||||||
|
println!("Processing update for plugin {}/{}: {}", index + 1, total, plugin_clone.name);
|
||||||
|
let result = process_plugin_update(plugin_clone.clone(), &repos_clone).await;
|
||||||
|
(index, result)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process batch concurrently
|
||||||
|
let batch_results = futures::future::join_all(batch_futures).await;
|
||||||
|
|
||||||
|
// Update plugins with results from this batch
|
||||||
|
for (index, updated_plugin) in batch_results {
|
||||||
|
if let Some(position) = updated_plugins.iter().position(|p| p.file_path == updated_plugin.file_path) {
|
||||||
|
updated_plugins[position] = updated_plugin;
|
||||||
|
println!("Updated plugin {}: {}", index, updated_plugins[position].name);
|
||||||
|
if let Some(latest) = &updated_plugins[position].latest_version {
|
||||||
|
println!(" Current version: {}, Latest version: {}, Has update: {}",
|
||||||
|
updated_plugins[position].version, latest, updated_plugins[position].has_update);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Small delay between batches to avoid overwhelming
|
||||||
|
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Final progress report
|
||||||
|
let final_progress = BulkUpdateProgress {
|
||||||
|
processed: total,
|
||||||
|
total,
|
||||||
|
current_plugin_name: "Completed".to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(e) = app_handle.emit("update_check_progress", final_progress) {
|
||||||
|
println!("Failed to emit final update progress: {}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Bulk update check completed for {} plugins", total);
|
||||||
|
Ok(updated_plugins)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check for updates for a single plugin
|
||||||
|
pub async fn check_single_plugin_update(
|
||||||
|
app_handle: AppHandle,
|
||||||
|
plugin_to_check: Plugin,
|
||||||
|
repositories_to_check: Vec<RepositorySource>,
|
||||||
|
) -> Result<(), String> { // Returns Result<(), String> because result is sent via event
|
||||||
|
// Begin check
|
||||||
|
if let Err(e) = app_handle.emit("single_update_check_started", plugin_to_check.name.clone()) {
|
||||||
|
return Err(format!("Failed to emit single_update_check_started event: {}", e));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process update
|
||||||
|
let updated_plugin = process_plugin_update(plugin_to_check.clone(), &repositories_to_check).await;
|
||||||
|
|
||||||
|
// Create result
|
||||||
|
let result = SingleUpdateResult {
|
||||||
|
original_file_path: plugin_to_check.file_path.clone(),
|
||||||
|
plugin: Some(updated_plugin),
|
||||||
|
error: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Emit result
|
||||||
|
if let Err(e) = app_handle.emit("single_update_check_completed", result) {
|
||||||
|
return Err(format!("Failed to emit single_update_check_completed event: {}", e));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Process update check for a single plugin
|
||||||
|
async fn process_plugin_update(plugin: Plugin, repositories: &[RepositorySource]) -> Plugin {
|
||||||
|
let mut updated_plugin = plugin.clone();
|
||||||
|
println!("Checking for updates for plugin: {}", plugin.name);
|
||||||
|
|
||||||
|
// If plugin already has repository info, check that specific repo
|
||||||
|
if let (Some(repo_source), Some(repo_id)) = (&plugin.repository_source, &plugin.repository_id) {
|
||||||
|
println!("Plugin has existing repository info: {:?}, ID: {}", repo_source, repo_id);
|
||||||
|
match crate::lib_get_plugin_details_from_repository(repo_id, repo_source.clone(), None).await {
|
||||||
|
Ok(repo_plugin) => {
|
||||||
|
println!("Successfully got details from repository for {}", plugin.name);
|
||||||
|
update_plugin_from_repo(&mut updated_plugin, &repo_plugin);
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to get update details for {}: {}", plugin.name, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return updated_plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, try smart matching with repositories
|
||||||
|
println!("No repository info for {}. Trying smart matching...", plugin.name);
|
||||||
|
let matches = match crate::search_with_variations(&plugin.name, repositories).await {
|
||||||
|
Ok(matches) => {
|
||||||
|
println!("Found {} potential matches for {}", matches.len(), plugin.name);
|
||||||
|
matches
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
println!("Error searching for plugin {}: {}", plugin.name, e);
|
||||||
|
return updated_plugin;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Find best match
|
||||||
|
for repo_plugin in matches {
|
||||||
|
if is_likely_match(&plugin, &repo_plugin) {
|
||||||
|
println!("Found likely match for {} in {:?}: {} ({})",
|
||||||
|
plugin.name, repo_plugin.repository, repo_plugin.name, repo_plugin.version);
|
||||||
|
update_plugin_from_repo(&mut updated_plugin, &repo_plugin);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Update check complete for plugin: {}", plugin.name);
|
||||||
|
updated_plugin
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update plugin with repository information
|
||||||
|
fn update_plugin_from_repo(plugin: &mut Plugin, repo_plugin: &RepositoryPlugin) {
|
||||||
|
// Set repository information
|
||||||
|
plugin.repository_source = Some(repo_plugin.repository.clone());
|
||||||
|
plugin.repository_id = Some(repo_plugin.id.clone());
|
||||||
|
plugin.repository_url = Some(repo_plugin.page_url.clone());
|
||||||
|
|
||||||
|
// For Modrinth, check if the version looks like an ID instead of a version number
|
||||||
|
let latest_version = if repo_plugin.repository == RepositorySource::Modrinth &&
|
||||||
|
repo_plugin.version.len() >= 8 &&
|
||||||
|
!repo_plugin.version.contains('.') {
|
||||||
|
// This looks like an ID rather than a version, use "Latest" as a fallback
|
||||||
|
"Latest".to_string()
|
||||||
|
} else {
|
||||||
|
repo_plugin.version.clone()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set latest version if newer
|
||||||
|
if latest_version != plugin.version {
|
||||||
|
let has_update = compare_plugin_versions(&plugin.version, &latest_version);
|
||||||
|
plugin.latest_version = Some(latest_version);
|
||||||
|
plugin.has_update = has_update;
|
||||||
|
plugin.changelog = repo_plugin.changelog.clone();
|
||||||
|
} else {
|
||||||
|
plugin.has_update = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Determine if a repository plugin is likely a match for the installed plugin
|
||||||
|
fn is_likely_match(installed: &Plugin, repo: &RepositoryPlugin) -> bool {
|
||||||
|
// Require multiple criteria to match to avoid false positives
|
||||||
|
let mut match_points = 0;
|
||||||
|
|
||||||
|
// Name similarity check
|
||||||
|
let name_similarity = calculate_name_similarity(&installed.name, &repo.name);
|
||||||
|
|
||||||
|
// Strong name match (over 0.9 similarity)
|
||||||
|
if name_similarity > 0.9 {
|
||||||
|
match_points += 2;
|
||||||
|
}
|
||||||
|
// Moderate name match
|
||||||
|
else if name_similarity > 0.7 {
|
||||||
|
match_points += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Author check - if any author matches
|
||||||
|
if !installed.authors.is_empty() && !repo.authors.is_empty() {
|
||||||
|
for installed_author in &installed.authors {
|
||||||
|
for repo_author in &repo.authors {
|
||||||
|
if installed_author.to_lowercase() == repo_author.to_lowercase() {
|
||||||
|
match_points += 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Website match
|
||||||
|
if let Some(website) = &installed.website {
|
||||||
|
if website.contains(&repo.page_url) || repo.page_url.contains(website) {
|
||||||
|
match_points += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Require at least 2 match points to consider it a likely match
|
||||||
|
// This helps avoid incorrect matches
|
||||||
|
match_points >= 2
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Calculate similarity between plugin names (simple implementation)
|
||||||
|
fn calculate_name_similarity(name1: &str, name2: &str) -> f32 {
|
||||||
|
let name1_lower = name1.to_lowercase();
|
||||||
|
let name2_lower = name2.to_lowercase();
|
||||||
|
|
||||||
|
// Direct match
|
||||||
|
if name1_lower == name2_lower {
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Contains check
|
||||||
|
if name1_lower.contains(&name2_lower) || name2_lower.contains(&name1_lower) {
|
||||||
|
return 0.9;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simple word matching
|
||||||
|
let words1: Vec<&str> = name1_lower.split_whitespace().collect();
|
||||||
|
let words2: Vec<&str> = name2_lower.split_whitespace().collect();
|
||||||
|
|
||||||
|
let mut matched_words = 0;
|
||||||
|
let total_words = words1.len().max(words2.len());
|
||||||
|
|
||||||
|
for word1 in &words1 {
|
||||||
|
for word2 in &words2 {
|
||||||
|
if word1 == word2 && word1.len() > 2 { // Ignore short words
|
||||||
|
matched_words += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if total_words > 0 {
|
||||||
|
matched_words as f32 / total_words as f32
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
use semver::{Version, VersionReq};
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
|
/// Normalize a version string to be semver compatible
|
||||||
|
pub fn normalize_version(version_str: &str) -> String {
|
||||||
|
// If already starts with a digit, assume semantic version format
|
||||||
|
if version_str.chars().next().map_or(false, |c| c.is_ascii_digit()) {
|
||||||
|
// Clean up any common prefixes like 'v'
|
||||||
|
let cleaned = version_str.trim_start_matches(|c| c == 'v' || c == 'V');
|
||||||
|
return cleaned.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return as-is for now
|
||||||
|
version_str.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Compare two plugin versions to determine if an update is available
|
||||||
|
pub fn compare_plugin_versions(installed_str: &str, repo_str: &str) -> bool {
|
||||||
|
// Normalize version strings
|
||||||
|
let installed_version = normalize_version(installed_str);
|
||||||
|
let repo_version = normalize_version(repo_str);
|
||||||
|
|
||||||
|
// Try to parse as semver
|
||||||
|
match (Version::parse(&installed_version), Version::parse(&repo_version)) {
|
||||||
|
(Ok(installed), Ok(repo)) => {
|
||||||
|
// Simple semver comparison
|
||||||
|
repo > installed
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
// Fallback to simple string comparison for non-semver versions
|
||||||
|
repo_version != installed_version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Extract version pattern from a string
|
||||||
|
pub fn extract_version_pattern(input: &str) -> Option<String> {
|
||||||
|
// Look for version pattern like 1.19.2 in string
|
||||||
|
let version_pattern = Regex::new(r"(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)").unwrap();
|
||||||
|
if let Some(captures) = version_pattern.captures(input) {
|
||||||
|
if let Some(version_match) = captures.get(0) {
|
||||||
|
return Some(version_match.as_str().to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check if a plugin version is compatible with a specific Minecraft version
|
||||||
|
pub fn is_version_compatible(plugin_version: &str, minecraft_version: &str) -> bool {
|
||||||
|
// Try to parse the Minecraft version
|
||||||
|
if let Ok(mc_version) = Version::parse(minecraft_version) {
|
||||||
|
// Try to parse as a version requirement
|
||||||
|
if let Ok(req) = VersionReq::parse(plugin_version) {
|
||||||
|
return req.matches(&mc_version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If version formats are incompatible, make best guess
|
||||||
|
plugin_version.contains(minecraft_version)
|
||||||
|
}
|
||||||
+202
-22
@@ -134,35 +134,13 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.plugins-list {
|
.plugins-list {
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
|
||||||
gap: 1rem;
|
|
||||||
margin-top: 1.5rem;
|
margin-top: 1.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.plugins-list h2 {
|
.plugins-list h2 {
|
||||||
grid-column: 1 / -1;
|
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.plugin-card {
|
|
||||||
background-color: var(--surface-color);
|
|
||||||
border: 1px solid var(--border-color);
|
|
||||||
border-radius: 8px;
|
|
||||||
padding: 1rem;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: transform 0.2s, box-shadow 0.2s;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
height: 100%;
|
|
||||||
min-height: 120px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.plugin-card:hover {
|
|
||||||
transform: translateY(-2px);
|
|
||||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.plugin-name {
|
.plugin-name {
|
||||||
font-size: 1.1rem;
|
font-size: 1.1rem;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
@@ -536,3 +514,205 @@ button {
|
|||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
border: 1px solid var(--border-color);
|
border: 1px solid var(--border-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.plugin-changelog {
|
||||||
|
margin-top: 1rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
background-color: rgba(255, 255, 255, 0.05);
|
||||||
|
padding: 1rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
max-height: 200px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.changelog-content {
|
||||||
|
white-space: pre-line;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-actions {
|
||||||
|
margin-top: 1.5rem;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-update-button {
|
||||||
|
padding: 0.75rem 1.5rem;
|
||||||
|
background-color: var(--secondary-color);
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 1rem;
|
||||||
|
transition: background-color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-update-button:hover {
|
||||||
|
background-color: #43a047;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-update-button:disabled {
|
||||||
|
background-color: #666;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-available-badge {
|
||||||
|
background-color: var(--secondary-color);
|
||||||
|
color: white;
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
margin-left: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.up-to-date-badge {
|
||||||
|
color: var(--success-color, #4caf50);
|
||||||
|
font-weight: bold;
|
||||||
|
margin-left: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.up-to-date-text {
|
||||||
|
color: var(--success-color, #4caf50);
|
||||||
|
font-size: 0.85em;
|
||||||
|
margin-left: 0.4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bulk-update-progress {
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: var(--text-secondary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.bulk-update-progress progress {
|
||||||
|
width: 100%;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
margin-top: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Warning Modal Styles */
|
||||||
|
.warning-modal {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background-color: rgba(0, 0, 0, 0.7);
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
z-index: 2000; /* Higher than other modals */
|
||||||
|
}
|
||||||
|
|
||||||
|
.warning-content {
|
||||||
|
background-color: var(--background-color);
|
||||||
|
border: 2px solid var(--warning-color);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 2rem;
|
||||||
|
width: 90%;
|
||||||
|
max-width: 500px;
|
||||||
|
text-align: center;
|
||||||
|
position: relative;
|
||||||
|
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.warning-content h3 {
|
||||||
|
color: var(--warning-color);
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.warning-content p {
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.warning-content .close-button {
|
||||||
|
padding: 0.75rem 1.5rem;
|
||||||
|
background-color: var(--warning-color);
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 1rem;
|
||||||
|
transition: background-color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.warning-content .close-button:hover {
|
||||||
|
background-color: #e69500;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Premium Plugin Modal Styles */
|
||||||
|
.premium-plugin-modal {
|
||||||
|
background-color: var(--surface-color);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 1.5rem;
|
||||||
|
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
||||||
|
width: 90%;
|
||||||
|
max-width: 600px;
|
||||||
|
position: relative;
|
||||||
|
color: var(--text-color);
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.premium-plugin-modal h3 {
|
||||||
|
color: var(--warning-color, #ff9800);
|
||||||
|
margin-top: 0;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
font-size: 1.4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.premium-plugin-instructions {
|
||||||
|
margin: 1.2rem 0;
|
||||||
|
background-color: rgba(255, 255, 255, 0.05);
|
||||||
|
padding: 1rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
border-left: 3px solid var(--accent-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.premium-plugin-instructions ol {
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
padding-left: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.premium-plugin-instructions li {
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.premium-plugin-actions {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 1rem;
|
||||||
|
margin-top: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.plugin-page-button {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 0.75rem 1.5rem;
|
||||||
|
background-color: var(--accent-color);
|
||||||
|
color: white;
|
||||||
|
text-decoration: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-weight: bold;
|
||||||
|
transition: background-color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.plugin-page-button:hover {
|
||||||
|
background-color: var(--accent-hover-color, #1967d2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-modal-button {
|
||||||
|
padding: 0.75rem 1.5rem;
|
||||||
|
background-color: var(--surface-alt-color, #424242);
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 1rem;
|
||||||
|
transition: background-color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-modal-button:hover {
|
||||||
|
background-color: var(--surface-hover-color, #616161);
|
||||||
|
}
|
||||||
+701
-30
@@ -1,6 +1,8 @@
|
|||||||
import { useState } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import { open } from "@tauri-apps/plugin-dialog";
|
import { open } from "@tauri-apps/plugin-dialog";
|
||||||
|
import { listen, UnlistenFn } from "@tauri-apps/api/event";
|
||||||
|
import { appDataDir } from '@tauri-apps/api/path'; // Import for data directory (if needed frontend side)
|
||||||
import "./App.css";
|
import "./App.css";
|
||||||
|
|
||||||
type ServerType =
|
type ServerType =
|
||||||
@@ -38,6 +40,11 @@ interface Plugin {
|
|||||||
permissions?: any;
|
permissions?: any;
|
||||||
file_path: string;
|
file_path: string;
|
||||||
file_hash: string;
|
file_hash: string;
|
||||||
|
website?: string;
|
||||||
|
changelog?: string;
|
||||||
|
repository_source?: string; // Add repository source (string for simplicity)
|
||||||
|
repository_id?: string; // Add repository ID
|
||||||
|
repository_url?: string; // URL to the plugin's repository page
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ScanResult {
|
interface ScanResult {
|
||||||
@@ -45,6 +52,39 @@ interface ScanResult {
|
|||||||
plugins: Plugin[];
|
plugins: Plugin[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ScanProgress {
|
||||||
|
processed: number;
|
||||||
|
total: number;
|
||||||
|
current_file: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- New Interfaces for Update Events ---
|
||||||
|
interface BulkUpdateProgressPayload {
|
||||||
|
processed: number;
|
||||||
|
total: number;
|
||||||
|
current_plugin_name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SingleUpdateResultPayload {
|
||||||
|
original_file_path: string;
|
||||||
|
plugin: Plugin | null; // Updated plugin state or null if check failed but wasn't a panic
|
||||||
|
error: string | null; // Error message if any
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interface for potential plugin matches for ambiguous plugins
|
||||||
|
interface PotentialPluginMatch {
|
||||||
|
name: string;
|
||||||
|
version: string;
|
||||||
|
repository: string;
|
||||||
|
repository_id: string;
|
||||||
|
page_url: string;
|
||||||
|
description?: string;
|
||||||
|
minecraft_versions: string[];
|
||||||
|
download_count?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- End New Interfaces ---
|
||||||
|
|
||||||
interface PluginDetailsProps {
|
interface PluginDetailsProps {
|
||||||
plugin: Plugin;
|
plugin: Plugin;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
@@ -87,12 +127,26 @@ function PluginDetails({ plugin, onClose }: PluginDetailsProps) {
|
|||||||
<div className="plugin-details-content">
|
<div className="plugin-details-content">
|
||||||
<button className="close-button" onClick={onClose}>×</button>
|
<button className="close-button" onClick={onClose}>×</button>
|
||||||
<h2>{plugin.name}</h2>
|
<h2>{plugin.name}</h2>
|
||||||
<div className="plugin-version-display">Version: {plugin.version}</div>
|
<div className="plugin-version-display">Version: {plugin.version} {plugin.latest_version && (
|
||||||
|
plugin.has_update
|
||||||
|
? <span className="update-available-badge">(Update available: {plugin.latest_version})</span>
|
||||||
|
: <span className="up-to-date-badge">(Up to Date: {plugin.latest_version})</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
{plugin.description && (
|
{plugin.description && (
|
||||||
<div className="plugin-description">{plugin.description}</div>
|
<div className="plugin-description">{plugin.description}</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{plugin.website && (
|
||||||
|
<div className="plugin-website">
|
||||||
|
<div className="section-label">Website:</div>
|
||||||
|
<a href={plugin.website} target="_blank" rel="noopener noreferrer">
|
||||||
|
{plugin.website}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{plugin.authors && plugin.authors.length > 0 && (
|
{plugin.authors && plugin.authors.length > 0 && (
|
||||||
<div className="plugin-authors">
|
<div className="plugin-authors">
|
||||||
<div className="section-label">Authors:</div>
|
<div className="section-label">Authors:</div>
|
||||||
@@ -114,6 +168,13 @@ function PluginDetails({ plugin, onClose }: PluginDetailsProps) {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{plugin.changelog && plugin.has_update && (
|
||||||
|
<div className="plugin-changelog">
|
||||||
|
<div className="section-label">Changelog:</div>
|
||||||
|
<div className="changelog-content">{plugin.changelog}</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="plugin-file-info">
|
<div className="plugin-file-info">
|
||||||
<div className="section-label">File Path:</div>
|
<div className="section-label">File Path:</div>
|
||||||
<div className="file-path">{plugin.file_path}</div>
|
<div className="file-path">{plugin.file_path}</div>
|
||||||
@@ -121,6 +182,17 @@ function PluginDetails({ plugin, onClose }: PluginDetailsProps) {
|
|||||||
<div className="section-label">File Hash (SHA-256):</div>
|
<div className="section-label">File Hash (SHA-256):</div>
|
||||||
<div className="file-hash">{plugin.file_hash}</div>
|
<div className="file-hash">{plugin.file_hash}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{plugin.has_update && plugin.latest_version && (
|
||||||
|
<div className="update-actions">
|
||||||
|
<button
|
||||||
|
className="update-button detail-update-button"
|
||||||
|
onClick={() => window.dispatchEvent(new CustomEvent('update-plugin', { detail: plugin }))}
|
||||||
|
>
|
||||||
|
Update to version {plugin.latest_version}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -152,6 +224,122 @@ function ServerInfoDisplay({ serverInfo }: { serverInfo: ServerInfo | null }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add this new component after PluginDetails
|
||||||
|
function WarningModal({ message, onClose }: { message: string, onClose: () => void }) {
|
||||||
|
return (
|
||||||
|
<div className="modal-backdrop">
|
||||||
|
<div className="warning-modal">
|
||||||
|
<h3>⚠️ Warning</h3>
|
||||||
|
<p>{message}</p>
|
||||||
|
<button onClick={onClose}>Close</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Component for selecting the correct plugin from potential matches
|
||||||
|
function PluginMatchSelector({
|
||||||
|
plugin,
|
||||||
|
potentialMatches,
|
||||||
|
onSelect,
|
||||||
|
onCancel
|
||||||
|
}: {
|
||||||
|
plugin: Plugin,
|
||||||
|
potentialMatches: PotentialPluginMatch[],
|
||||||
|
onSelect: (match: PotentialPluginMatch) => void,
|
||||||
|
onCancel: () => void
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="modal-backdrop">
|
||||||
|
<div className="plugin-match-modal">
|
||||||
|
<h3>Multiple Matches Found</h3>
|
||||||
|
<p>We found several potential matches for <strong>{plugin.name}</strong>. Please select the correct one:</p>
|
||||||
|
|
||||||
|
<div className="matches-list">
|
||||||
|
{potentialMatches.map((match, index) => (
|
||||||
|
<div key={`${match.repository}-${match.repository_id}`} className="match-item">
|
||||||
|
<div className="match-details">
|
||||||
|
<h4>{match.name}</h4>
|
||||||
|
<p className="match-version">Version: {match.version}</p>
|
||||||
|
{match.description && <p className="match-description">{match.description}</p>}
|
||||||
|
<div className="match-meta">
|
||||||
|
<span className="match-repo">Source: {match.repository}</span>
|
||||||
|
{match.download_count && <span className="match-downloads">Downloads: {match.download_count.toLocaleString()}</span>}
|
||||||
|
<span className="match-mc-version">MC: {match.minecraft_versions.join(', ')}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="match-actions">
|
||||||
|
<button className="select-match-button" onClick={() => onSelect(match)}>
|
||||||
|
Select This Match
|
||||||
|
</button>
|
||||||
|
<a
|
||||||
|
href={match.page_url}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="view-page-link"
|
||||||
|
>
|
||||||
|
View Page
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="match-selector-footer">
|
||||||
|
<button className="cancel-button" onClick={onCancel}>Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// After the WarningModal component, add this new component
|
||||||
|
function PremiumPluginModal({
|
||||||
|
pluginName,
|
||||||
|
pluginVersion,
|
||||||
|
resourceUrl,
|
||||||
|
onClose
|
||||||
|
}: {
|
||||||
|
pluginName: string;
|
||||||
|
pluginVersion: string;
|
||||||
|
resourceUrl: string;
|
||||||
|
onClose: () => void;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="modal-backdrop">
|
||||||
|
<div className="premium-plugin-modal">
|
||||||
|
<h3>Premium Plugin Detected</h3>
|
||||||
|
<p>
|
||||||
|
<strong>{pluginName} {pluginVersion}</strong> appears to be a premium or protected plugin
|
||||||
|
that requires manual download.
|
||||||
|
</p>
|
||||||
|
<div className="premium-plugin-instructions">
|
||||||
|
<p>To update this plugin:</p>
|
||||||
|
<ol>
|
||||||
|
<li>Visit the plugin page on SpigotMC</li>
|
||||||
|
<li>Log in to your SpigotMC account</li>
|
||||||
|
<li>Download the latest version manually</li>
|
||||||
|
<li>Replace the current plugin file in your server's plugins folder</li>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
<div className="premium-plugin-actions">
|
||||||
|
<a
|
||||||
|
href={resourceUrl}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="plugin-page-button"
|
||||||
|
>
|
||||||
|
Open Plugin Page
|
||||||
|
</a>
|
||||||
|
<button className="close-modal-button" onClick={onClose}>
|
||||||
|
Close
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [serverPath, setServerPath] = useState("");
|
const [serverPath, setServerPath] = useState("");
|
||||||
const [serverInfo, setServerInfo] = useState<ServerInfo | null>(null);
|
const [serverInfo, setServerInfo] = useState<ServerInfo | null>(null);
|
||||||
@@ -160,52 +348,414 @@ function App() {
|
|||||||
const [scanComplete, setScanComplete] = useState(false);
|
const [scanComplete, setScanComplete] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [selectedPlugin, setSelectedPlugin] = useState<Plugin | null>(null);
|
const [selectedPlugin, setSelectedPlugin] = useState<Plugin | null>(null);
|
||||||
|
const [scanProgress, setScanProgress] = useState<ScanProgress | null>(null);
|
||||||
|
const [isCheckingUpdates, setIsCheckingUpdates] = useState(false);
|
||||||
|
const [updateError, setUpdateError] = useState<string | null>(null);
|
||||||
|
// --- New State Variables ---
|
||||||
|
const [pluginLoadingStates, setPluginLoadingStates] = useState<Record<string, boolean>>({});
|
||||||
|
const [bulkUpdateProgress, setBulkUpdateProgress] = useState<BulkUpdateProgressPayload | null>(null);
|
||||||
|
const [warningMessage, setWarningMessage] = useState<string | null>(null);
|
||||||
|
const [potentialMatches, setPotentialMatches] = useState<PotentialPluginMatch[]>([]);
|
||||||
|
// --- New state for match selector ---
|
||||||
|
const [showMatchSelector, setShowMatchSelector] = useState(false);
|
||||||
|
const [pluginToDisambiguate, setPluginToDisambiguate] = useState<Plugin | null>(null);
|
||||||
|
// --- End New state for match selector ---
|
||||||
|
// --- End New State Variables ---
|
||||||
|
const [serverType, setServerType] = useState<ServerType>('Unknown');
|
||||||
|
const [premiumPluginInfo, setPremiumPluginInfo] = useState<{name: string; version: string; url: string} | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let unlistenScanStarted: UnlistenFn | undefined;
|
||||||
|
let unlistenScanProgress: UnlistenFn | undefined;
|
||||||
|
let unlistenScanCompleted: UnlistenFn | undefined;
|
||||||
|
let unlistenScanError: UnlistenFn | undefined;
|
||||||
|
let unlistenBulkUpdateStart: UnlistenFn | undefined;
|
||||||
|
let unlistenUpdateCheckProgress: UnlistenFn | undefined;
|
||||||
|
let unlistenSingleUpdateCheckStarted: UnlistenFn | undefined;
|
||||||
|
let unlistenSingleUpdateCheckCompleted: UnlistenFn | undefined;
|
||||||
|
|
||||||
|
const setupListeners = async () => {
|
||||||
|
unlistenScanStarted = await listen("scan_started", () => {
|
||||||
|
console.log("Scan started event received");
|
||||||
|
setIsScanning(true);
|
||||||
|
setScanProgress(null);
|
||||||
|
setError(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
unlistenScanProgress = await listen<ScanProgress>("scan_progress", (event) => {
|
||||||
|
console.log("Scan progress event received:", event.payload);
|
||||||
|
setScanProgress(event.payload);
|
||||||
|
});
|
||||||
|
|
||||||
|
unlistenScanCompleted = await listen<ScanResult>("scan_completed", (event) => {
|
||||||
|
console.log("Scan completed event received with payload:", event.payload);
|
||||||
|
try {
|
||||||
|
console.log("Server info:", event.payload.server_info);
|
||||||
|
console.log("Plugins count:", event.payload.plugins.length);
|
||||||
|
|
||||||
|
// Update state in a specific order to ensure UI updates properly
|
||||||
|
setIsScanning(false);
|
||||||
|
setScanComplete(true);
|
||||||
|
setServerInfo(event.payload.server_info);
|
||||||
|
setPlugins(event.payload.plugins);
|
||||||
|
setServerType(event.payload.server_info.server_type);
|
||||||
|
|
||||||
|
// Add a slight delay and verify the state was updated
|
||||||
|
setTimeout(() => {
|
||||||
|
console.log("Verifying state updates after scan:");
|
||||||
|
console.log("- scanComplete:", scanComplete);
|
||||||
|
console.log("- serverInfo:", serverInfo);
|
||||||
|
console.log("- plugins count:", plugins.length);
|
||||||
|
|
||||||
|
// Force a state update if plugins length is still 0 but we got plugins
|
||||||
|
if (plugins.length === 0 && event.payload.plugins.length > 0) {
|
||||||
|
console.log("Forcing state update because plugins array is empty");
|
||||||
|
setPlugins([...event.payload.plugins]);
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
console.log("State updated after scan completion");
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error handling scan completion:", err);
|
||||||
|
setError(`Error handling scan completion: ${err}`);
|
||||||
|
setIsScanning(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
unlistenScanError = await listen<string>("scan_error", (event) => {
|
||||||
|
console.log("Scan error event received:", event.payload);
|
||||||
|
setIsScanning(false);
|
||||||
|
setError(event.payload);
|
||||||
|
});
|
||||||
|
|
||||||
|
unlistenBulkUpdateStart = await listen<number>("bulk_update_start", (event) => {
|
||||||
|
console.log("Bulk update start event received, total plugins:", event.payload);
|
||||||
|
setIsCheckingUpdates(true);
|
||||||
|
setUpdateError(null);
|
||||||
|
setBulkUpdateProgress({
|
||||||
|
processed: 0,
|
||||||
|
total: event.payload,
|
||||||
|
current_plugin_name: "Starting update check..."
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
unlistenUpdateCheckProgress = await listen<BulkUpdateProgressPayload>("update_check_progress", (event) => {
|
||||||
|
console.log("Update check progress event received:", event.payload);
|
||||||
|
setBulkUpdateProgress(event.payload);
|
||||||
|
});
|
||||||
|
|
||||||
|
unlistenSingleUpdateCheckStarted = await listen<string>("single_update_check_started", (event) => {
|
||||||
|
console.log("Single update check started for:", event.payload);
|
||||||
|
});
|
||||||
|
|
||||||
|
unlistenSingleUpdateCheckCompleted = await listen<SingleUpdateResultPayload>("single_update_check_completed", (event) => {
|
||||||
|
console.log("Single update check completed, result:", event.payload);
|
||||||
|
const { original_file_path, plugin, error } = event.payload;
|
||||||
|
|
||||||
|
setPluginLoadingStates(prev => ({ ...prev, [original_file_path]: false }));
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
setUpdateError(`Error checking for updates: ${error}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plugin) {
|
||||||
|
setPlugins(prevPlugins => prevPlugins.map(p => {
|
||||||
|
if (p.file_path === original_file_path) {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (serverPath) {
|
||||||
|
invoke("save_plugin_data", {
|
||||||
|
plugins: plugins.map(p => p.file_path === original_file_path ? plugin : p),
|
||||||
|
serverPath
|
||||||
|
}).catch(err => {
|
||||||
|
console.error("Error saving plugin data after single update:", err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener('update-plugin', ((e: CustomEvent<Plugin>) => {
|
||||||
|
if (e.detail) {
|
||||||
|
updatePlugin(e.detail);
|
||||||
|
}
|
||||||
|
}) as EventListener);
|
||||||
|
};
|
||||||
|
|
||||||
|
setupListeners();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
unlistenScanStarted?.();
|
||||||
|
unlistenScanProgress?.();
|
||||||
|
unlistenScanCompleted?.();
|
||||||
|
unlistenScanError?.();
|
||||||
|
unlistenBulkUpdateStart?.();
|
||||||
|
unlistenUpdateCheckProgress?.();
|
||||||
|
unlistenSingleUpdateCheckStarted?.();
|
||||||
|
unlistenSingleUpdateCheckCompleted?.();
|
||||||
|
window.removeEventListener('update-plugin', (() => {}) as EventListener);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
async function selectDirectory() {
|
async function selectDirectory() {
|
||||||
try {
|
try {
|
||||||
const selected = await open({
|
const selected = await open({
|
||||||
directory: true,
|
directory: true,
|
||||||
multiple: false,
|
multiple: false,
|
||||||
title: 'Select Minecraft Server Directory'
|
title: "Select Minecraft Server Folder",
|
||||||
});
|
});
|
||||||
|
|
||||||
if (selected !== null) {
|
if (selected && typeof selected === "string") {
|
||||||
if (typeof selected === 'string') {
|
console.log(`Directory selected: ${selected}`);
|
||||||
setServerPath(selected);
|
setServerPath(selected);
|
||||||
|
setServerInfo(null);
|
||||||
|
setPlugins([]);
|
||||||
|
setIsScanning(false);
|
||||||
|
setScanComplete(false);
|
||||||
setError(null);
|
setError(null);
|
||||||
} else if (Array.isArray(selected)) {
|
setScanProgress(null);
|
||||||
const selectedArr = selected as string[];
|
setIsCheckingUpdates(false);
|
||||||
if (selectedArr.length > 0) {
|
setUpdateError(null);
|
||||||
setServerPath(selectedArr[0]);
|
setPluginLoadingStates({});
|
||||||
|
setBulkUpdateProgress(null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log(`Attempting to load persisted data for: ${selected}`);
|
||||||
|
const loadedPlugins: Plugin[] = await invoke("load_plugin_data", { serverPath: selected });
|
||||||
|
if (loadedPlugins && loadedPlugins.length > 0) {
|
||||||
|
console.log(`Loaded ${loadedPlugins.length} plugins from persistence.`);
|
||||||
|
setPlugins(loadedPlugins);
|
||||||
|
setScanComplete(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
|
} else {
|
||||||
|
console.log("No persisted plugin data found for this server.");
|
||||||
}
|
}
|
||||||
|
} catch (loadError) {
|
||||||
|
console.error("Error loading persisted plugin data:", loadError);
|
||||||
|
setError(`Failed to load previous plugin data: ${loadError}`);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.log("Directory selection cancelled.");
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to open directory:', err);
|
console.error("Error selecting directory:", err);
|
||||||
setError("Failed to open directory selector. Please enter path manually.");
|
setError(`Error selecting directory: ${err}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function scanForPlugins() {
|
async function scanForPlugins() {
|
||||||
|
if (!serverPath || isScanning) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
console.log("Starting scan for plugins in:", serverPath);
|
||||||
setIsScanning(true);
|
setIsScanning(true);
|
||||||
|
setScanComplete(false);
|
||||||
|
setPlugins([]);
|
||||||
|
setServerInfo(null);
|
||||||
|
setScanProgress(null);
|
||||||
setError(null);
|
setError(null);
|
||||||
|
|
||||||
// Call the Rust backend
|
await invoke("scan_server_dir", { path: serverPath });
|
||||||
const result = await invoke<ScanResult>("scan_server_directory", { path: serverPath });
|
console.log("Scan server dir command invoked successfully");
|
||||||
|
|
||||||
setServerInfo(result.server_info);
|
|
||||||
setPlugins(result.plugins);
|
|
||||||
setIsScanning(false);
|
|
||||||
setScanComplete(true);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error scanning for plugins:", err);
|
console.error("Error invoking scan command:", err);
|
||||||
setError(err as string);
|
setError(`Failed to start scan: ${err as string}`);
|
||||||
setIsScanning(false);
|
setIsScanning(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function checkForUpdates() {
|
||||||
|
if (!plugins.length || isCheckingUpdates) return;
|
||||||
|
|
||||||
|
setIsCheckingUpdates(true);
|
||||||
|
setUpdateError(null);
|
||||||
|
setBulkUpdateProgress(null);
|
||||||
|
console.log("Invoking bulk check_plugin_updates...");
|
||||||
|
|
||||||
|
try {
|
||||||
|
const repositoriesToCheck = ['SpigotMC', 'Modrinth', 'GitHub'];
|
||||||
|
|
||||||
|
const pluginsToSend = plugins.map(p => ({
|
||||||
|
name: p.name,
|
||||||
|
version: p.version,
|
||||||
|
authors: p.authors || [],
|
||||||
|
file_path: p.file_path,
|
||||||
|
file_hash: p.file_hash,
|
||||||
|
website: p.website,
|
||||||
|
description: p.description,
|
||||||
|
api_version: p.api_version,
|
||||||
|
main_class: p.main_class,
|
||||||
|
depend: p.depend,
|
||||||
|
soft_depend: p.soft_depend,
|
||||||
|
load_before: p.load_before,
|
||||||
|
commands: p.commands,
|
||||||
|
permissions: p.permissions,
|
||||||
|
has_update: p.has_update || false,
|
||||||
|
repository_source: p.repository_source,
|
||||||
|
repository_id: p.repository_id,
|
||||||
|
repository_url: p.repository_url,
|
||||||
|
}));
|
||||||
|
|
||||||
|
console.log("Sending plugin data to backend, count:", pluginsToSend.length);
|
||||||
|
|
||||||
|
const updatedPlugins = await invoke<Plugin[]>("check_plugin_updates", {
|
||||||
|
plugins: pluginsToSend,
|
||||||
|
repositories: repositoriesToCheck,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("Bulk update check completed successfully, updating state.");
|
||||||
|
setPlugins(updatedPlugins);
|
||||||
|
|
||||||
|
if (serverPath) {
|
||||||
|
try {
|
||||||
|
console.log("[checkForUpdates] Saving plugin data...");
|
||||||
|
await invoke("save_plugin_data", { plugins: updatedPlugins, serverPath });
|
||||||
|
console.log("[checkForUpdates] Plugin data saved successfully.");
|
||||||
|
} catch (saveError) {
|
||||||
|
console.error("Error saving plugin data after bulk update:", saveError);
|
||||||
|
setUpdateError(`Update check complete, but failed to save plugin data: ${saveError}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
const errorMessage = `Error during bulk update check: ${err instanceof Error ? err.message : String(err)}`;
|
||||||
|
console.error(errorMessage);
|
||||||
|
setUpdateError(errorMessage);
|
||||||
|
} finally {
|
||||||
|
setIsCheckingUpdates(false);
|
||||||
|
setBulkUpdateProgress(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkSinglePlugin(plugin: Plugin) {
|
||||||
|
if (isScanning || isCheckingUpdates || pluginLoadingStates[plugin.file_path]) return;
|
||||||
|
|
||||||
|
console.log(`Invoking single check for: ${plugin.name} (${plugin.file_path})`);
|
||||||
|
setPluginLoadingStates(prev => ({ ...prev, [plugin.file_path]: true }));
|
||||||
|
setUpdateError(null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const repositoriesToCheck = ['SpigotMC', 'Modrinth', 'GitHub'];
|
||||||
|
|
||||||
|
const pluginToSend = {
|
||||||
|
name: plugin.name,
|
||||||
|
version: plugin.version,
|
||||||
|
authors: plugin.authors || [],
|
||||||
|
file_path: plugin.file_path,
|
||||||
|
file_hash: plugin.file_hash,
|
||||||
|
website: plugin.website,
|
||||||
|
description: plugin.description,
|
||||||
|
api_version: plugin.api_version,
|
||||||
|
main_class: plugin.main_class,
|
||||||
|
depend: plugin.depend,
|
||||||
|
soft_depend: plugin.soft_depend,
|
||||||
|
load_before: plugin.load_before,
|
||||||
|
commands: plugin.commands,
|
||||||
|
permissions: plugin.permissions,
|
||||||
|
has_update: plugin.has_update,
|
||||||
|
};
|
||||||
|
|
||||||
|
await invoke("check_single_plugin_update_command", {
|
||||||
|
plugin: pluginToSend,
|
||||||
|
repositories: repositoriesToCheck,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
const errorMessage = `Error invoking single update command for ${plugin.name}: ${err instanceof Error ? err.message : String(err)}`;
|
||||||
|
console.error(errorMessage);
|
||||||
|
setUpdateError(errorMessage);
|
||||||
|
setPluginLoadingStates(prev => ({ ...prev, [plugin.file_path]: false }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updatePlugin(plugin: Plugin) {
|
||||||
|
if (!plugin.has_update || !plugin.latest_version || !plugin.repository_source || !plugin.repository_id) {
|
||||||
|
setUpdateError(`Cannot update ${plugin.name}: Missing required update information`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setPluginLoadingStates(prev => ({ ...prev, [plugin.file_path]: true }));
|
||||||
|
setUpdateError(null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log(`Updating plugin: ${plugin.name} to version ${plugin.latest_version}`);
|
||||||
|
|
||||||
|
// Try to update the plugin
|
||||||
|
try {
|
||||||
|
const newFilePath = await invoke<string>("update_plugin", {
|
||||||
|
pluginId: plugin.repository_id,
|
||||||
|
version: plugin.latest_version,
|
||||||
|
repository: plugin.repository_source,
|
||||||
|
currentFilePath: plugin.file_path,
|
||||||
|
serverTypeStr: serverInfo?.server_type
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`Update successful for ${plugin.name}, new file path: ${newFilePath}`);
|
||||||
|
|
||||||
|
setPlugins(currentPlugins => currentPlugins.map(p => {
|
||||||
|
if (p.file_path === plugin.file_path) {
|
||||||
|
return {
|
||||||
|
...p,
|
||||||
|
version: p.latest_version || p.version,
|
||||||
|
has_update: false,
|
||||||
|
latest_version: p.latest_version,
|
||||||
|
file_path: newFilePath
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (serverPath) {
|
||||||
|
await invoke("save_plugin_data", {
|
||||||
|
plugins: plugins.map(p => {
|
||||||
|
if (p.file_path === plugin.file_path) {
|
||||||
|
return {
|
||||||
|
...p,
|
||||||
|
version: p.latest_version || p.version,
|
||||||
|
has_update: false,
|
||||||
|
file_path: newFilePath
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}),
|
||||||
|
serverPath
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error(`Error updating plugin: ${error}`);
|
||||||
|
|
||||||
|
// Check if this is a premium resource
|
||||||
|
const errorMsg = String(error);
|
||||||
|
if (errorMsg.startsWith("PREMIUM_RESOURCE:")) {
|
||||||
|
// Parse the premium resource error
|
||||||
|
const parts = errorMsg.split(":");
|
||||||
|
if (parts.length >= 4) {
|
||||||
|
const resourceUrl = parts.slice(3).join(":"); // Rejoin in case URL contains colons
|
||||||
|
|
||||||
|
// Show premium resource modal
|
||||||
|
setPremiumPluginInfo({
|
||||||
|
name: plugin.name,
|
||||||
|
version: plugin.latest_version,
|
||||||
|
url: resourceUrl
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setUpdateError(`Premium plugin detected, but couldn't get resource URL: ${plugin.name}`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Standard error handling
|
||||||
|
setUpdateError(`Failed to update ${plugin.name}: ${error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error in updatePlugin: ${error}`);
|
||||||
|
setUpdateError(`Update process error: ${error}`);
|
||||||
|
} finally {
|
||||||
|
setPluginLoadingStates(prev => ({ ...prev, [plugin.file_path]: false }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const showPluginDetails = (plugin: Plugin) => {
|
const showPluginDetails = (plugin: Plugin) => {
|
||||||
setSelectedPlugin(plugin);
|
setSelectedPlugin(plugin);
|
||||||
};
|
};
|
||||||
@@ -214,6 +764,48 @@ function App() {
|
|||||||
setSelectedPlugin(null);
|
setSelectedPlugin(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleSelectMatch = async (selectedMatch: PotentialPluginMatch) => {
|
||||||
|
if (!pluginToDisambiguate || !serverPath) return;
|
||||||
|
|
||||||
|
console.log(`User selected match: ${selectedMatch.name} from ${selectedMatch.repository}`);
|
||||||
|
setShowMatchSelector(false);
|
||||||
|
setPluginLoadingStates(prev => ({ ...prev, [pluginToDisambiguate.file_path]: true }));
|
||||||
|
|
||||||
|
try {
|
||||||
|
const updatedPlugin: Plugin = await invoke("set_plugin_repository", {
|
||||||
|
pluginFilePath: pluginToDisambiguate.file_path,
|
||||||
|
repository: selectedMatch.repository,
|
||||||
|
repositoryId: selectedMatch.repository_id,
|
||||||
|
pageUrl: selectedMatch.page_url,
|
||||||
|
serverPath: serverPath,
|
||||||
|
});
|
||||||
|
|
||||||
|
setPlugins(currentPlugins =>
|
||||||
|
currentPlugins.map(p =>
|
||||||
|
p.file_path === updatedPlugin.file_path ? updatedPlugin : p
|
||||||
|
)
|
||||||
|
);
|
||||||
|
console.log(`Successfully set repository source for ${updatedPlugin.name}`);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error setting plugin repository source:", err);
|
||||||
|
setUpdateError(`Failed to set repository source for ${pluginToDisambiguate.name}: ${err}`);
|
||||||
|
} finally {
|
||||||
|
setPluginLoadingStates(prev => ({ ...prev, [pluginToDisambiguate.file_path]: false }));
|
||||||
|
setPluginToDisambiguate(null);
|
||||||
|
setPotentialMatches([]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCancelMatchSelection = () => {
|
||||||
|
setShowMatchSelector(false);
|
||||||
|
setPluginToDisambiguate(null);
|
||||||
|
setPotentialMatches([]);
|
||||||
|
if (pluginToDisambiguate) {
|
||||||
|
setPluginLoadingStates(prev => ({ ...prev, [pluginToDisambiguate.file_path]: false }));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="app-container">
|
<div className="app-container">
|
||||||
<header className="app-header">
|
<header className="app-header">
|
||||||
@@ -241,6 +833,14 @@ function App() {
|
|||||||
{isScanning ? "Scanning..." : "Scan for Plugins"}
|
{isScanning ? "Scanning..." : "Scan for Plugins"}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
{isScanning && scanProgress && (
|
||||||
|
<div className="scan-progress">
|
||||||
|
<p>Scanning: {scanProgress.current_file}</p>
|
||||||
|
<progress value={scanProgress.processed} max={scanProgress.total}></progress>
|
||||||
|
<span>{scanProgress.processed} / {scanProgress.total}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
<div className="error-message">
|
<div className="error-message">
|
||||||
{error}
|
{error}
|
||||||
@@ -248,44 +848,115 @@ function App() {
|
|||||||
)}
|
)}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
{scanComplete && serverInfo && (
|
{serverInfo && (
|
||||||
<ServerInfoDisplay serverInfo={serverInfo} />
|
<ServerInfoDisplay serverInfo={serverInfo} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{scanComplete && (
|
{serverInfo && plugins.length > 0 && (
|
||||||
|
<div className="update-controls">
|
||||||
|
<button
|
||||||
|
onClick={checkForUpdates}
|
||||||
|
disabled={isScanning || isCheckingUpdates || Object.values(pluginLoadingStates).some(isLoading => isLoading) || plugins.length === 0}
|
||||||
|
className="action-button update-check-button"
|
||||||
|
>
|
||||||
|
{isCheckingUpdates ? 'Checking All...' : 'Check All for Updates'}
|
||||||
|
</button>
|
||||||
|
{isCheckingUpdates && bulkUpdateProgress && (
|
||||||
|
<div className="bulk-update-progress">
|
||||||
|
Checking {bulkUpdateProgress.processed}/{bulkUpdateProgress.total}: {bulkUpdateProgress.current_plugin_name}
|
||||||
|
<progress value={bulkUpdateProgress.processed} max={bulkUpdateProgress.total}></progress>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{updateError && (
|
||||||
|
<div className="error-message update-error">{updateError}</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{plugins.length > 0 && (
|
||||||
<section className="plugins-list">
|
<section className="plugins-list">
|
||||||
<h2>Installed Plugins ({plugins.length})</h2>
|
<h2>Installed Plugins ({plugins.length})</h2>
|
||||||
{plugins.length > 0 ? (
|
|
||||||
<>
|
|
||||||
<div className="plugins-header">
|
<div className="plugins-header">
|
||||||
<span>Name</span>
|
<span>Name</span>
|
||||||
<span>Current Version</span>
|
<span>Current Version</span>
|
||||||
<span>Latest Version</span>
|
<span>Latest Version</span>
|
||||||
<span>Actions</span>
|
<span>Actions</span>
|
||||||
</div>
|
</div>
|
||||||
{plugins.map((plugin, index) => (
|
{plugins.map((plugin) => (
|
||||||
<div key={index} className={`plugin-item ${plugin.has_update ? 'has-update' : ''}`}>
|
<div key={plugin.file_path} className={`plugin-item ${plugin.has_update ? 'has-update' : ''}`}>
|
||||||
<div className="plugin-name">{plugin.name}</div>
|
<div className="plugin-name">{plugin.name}</div>
|
||||||
<div className="plugin-version">{plugin.version}</div>
|
<div className="plugin-version">{plugin.version}</div>
|
||||||
<div className="plugin-latest-version">{plugin.latest_version || 'Unknown'}</div>
|
<div className="plugin-latest-version">
|
||||||
|
{plugin.repository_url && plugin.latest_version ? (
|
||||||
|
<a href={plugin.repository_url} target="_blank" rel="noopener noreferrer" className="version-link">
|
||||||
|
{plugin.latest_version} {!plugin.has_update && <span className="up-to-date-text">(Up to Date)</span>}
|
||||||
|
</a>
|
||||||
|
) : (
|
||||||
|
plugin.latest_version
|
||||||
|
? <>{plugin.latest_version} {!plugin.has_update && <span className="up-to-date-text">(Up to Date)</span>}</>
|
||||||
|
: 'N/A'
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<div className="plugin-actions">
|
<div className="plugin-actions">
|
||||||
|
<button
|
||||||
|
className="action-button check-single-button"
|
||||||
|
onClick={() => checkSinglePlugin(plugin)}
|
||||||
|
disabled={isScanning || isCheckingUpdates || pluginLoadingStates[plugin.file_path]}
|
||||||
|
>
|
||||||
|
{pluginLoadingStates[plugin.file_path] ? 'Checking...' : 'Check'}
|
||||||
|
</button>
|
||||||
{plugin.has_update && (
|
{plugin.has_update && (
|
||||||
<button className="update-button">Update</button>
|
<button
|
||||||
|
className="update-button"
|
||||||
|
onClick={() => updatePlugin(plugin)}
|
||||||
|
disabled={isScanning || isCheckingUpdates || pluginLoadingStates[plugin.file_path]}
|
||||||
|
>
|
||||||
|
{pluginLoadingStates[plugin.file_path] ? 'Updating...' : 'Update'}
|
||||||
|
</button>
|
||||||
)}
|
)}
|
||||||
<button className="info-button" onClick={() => showPluginDetails(plugin)}>Info</button>
|
<button className="info-button" onClick={() => showPluginDetails(plugin)}>Info</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</>
|
</section>
|
||||||
) : (
|
|
||||||
<p>No plugins found in this directory.</p>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{scanComplete && plugins.length === 0 && (
|
||||||
|
<section className="plugins-list">
|
||||||
|
<h2>Installed Plugins (0)</h2>
|
||||||
|
<p>No plugins found in this directory.</p>
|
||||||
</section>
|
</section>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{selectedPlugin && (
|
{selectedPlugin && (
|
||||||
<PluginDetails plugin={selectedPlugin} onClose={closePluginDetails} />
|
<PluginDetails plugin={selectedPlugin} onClose={closePluginDetails} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{warningMessage && (
|
||||||
|
<WarningModal
|
||||||
|
message={warningMessage}
|
||||||
|
onClose={() => setWarningMessage(null)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{showMatchSelector && pluginToDisambiguate && (
|
||||||
|
<PluginMatchSelector
|
||||||
|
plugin={pluginToDisambiguate}
|
||||||
|
potentialMatches={potentialMatches}
|
||||||
|
onSelect={handleSelectMatch}
|
||||||
|
onCancel={handleCancelMatchSelection}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{premiumPluginInfo && (
|
||||||
|
<PremiumPluginModal
|
||||||
|
pluginName={premiumPluginInfo.name}
|
||||||
|
pluginVersion={premiumPluginInfo.version}
|
||||||
|
resourceUrl={premiumPluginInfo.url}
|
||||||
|
onClose={() => setPremiumPluginInfo(null)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<footer className="app-footer">
|
<footer className="app-footer">
|
||||||
|
|||||||
Reference in new issue
Block a user