mirror of
https://github.com/Xevion/byte-me.git
synced 2025-12-10 14:06:48 -06:00
Compare commits
1 Commits
master
...
3944b7a5f4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3944b7a5f4 |
43
.github/dependabot.yml
vendored
Normal file
43
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
# Enable version updates for npm
|
||||||
|
- package-ecosystem: "npm"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
open-pull-requests-limit: 10
|
||||||
|
reviewers:
|
||||||
|
- "dependabot[bot]"
|
||||||
|
assignees:
|
||||||
|
- "dependabot[bot]"
|
||||||
|
commit-message:
|
||||||
|
prefix: "chore"
|
||||||
|
include: "scope"
|
||||||
|
|
||||||
|
# Enable version updates for Cargo
|
||||||
|
- package-ecosystem: "cargo"
|
||||||
|
directory: "/src-tauri"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
open-pull-requests-limit: 10
|
||||||
|
reviewers:
|
||||||
|
- "dependabot[bot]"
|
||||||
|
assignees:
|
||||||
|
- "dependabot[bot]"
|
||||||
|
commit-message:
|
||||||
|
prefix: "chore"
|
||||||
|
include: "scope"
|
||||||
|
|
||||||
|
# Enable version updates for GitHub Actions
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
open-pull-requests-limit: 5
|
||||||
|
reviewers:
|
||||||
|
- "dependabot[bot]"
|
||||||
|
assignees:
|
||||||
|
- "dependabot[bot]"
|
||||||
|
commit-message:
|
||||||
|
prefix: "chore"
|
||||||
|
include: "scope"
|
||||||
176
.github/workflows/ci.yml
vendored
176
.github/workflows/ci.yml
vendored
@@ -9,111 +9,117 @@ env:
|
|||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
# Frontend checks
|
||||||
name: Build (${{ matrix.os }}${{ matrix.target && format(' / {0}', matrix.target) || '' }})
|
frontend-check:
|
||||||
runs-on: ${{ matrix.os }}
|
name: Frontend Check
|
||||||
strategy:
|
runs-on: ubuntu-latest
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- os: ubuntu-22.04
|
|
||||||
target: x86_64-unknown-linux-gnu
|
|
||||||
artifact_name: byte-me-linux-x86_64
|
|
||||||
- os: windows-latest
|
|
||||||
target: x86_64-pc-windows-msvc
|
|
||||||
artifact_name: byte-me-windows-x86_64
|
|
||||||
artifact_extension: .exe
|
|
||||||
- os: macos-latest
|
|
||||||
target: aarch64-apple-darwin
|
|
||||||
artifact_name: byte-me-macos-aarch64
|
|
||||||
- os: macos-latest
|
|
||||||
target: x86_64-apple-darwin
|
|
||||||
artifact_name: byte-me-macos-x86_64
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@v5
|
|
||||||
|
|
||||||
- name: Setup Rust
|
- name: Install pnpm
|
||||||
|
uses: pnpm/action-setup@v4
|
||||||
|
with:
|
||||||
|
version: 10
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: "20"
|
||||||
|
cache: "pnpm"
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: pnpm install
|
||||||
|
|
||||||
|
- name: Check TypeScript
|
||||||
|
run: pnpm run build
|
||||||
|
|
||||||
|
- name: Format check
|
||||||
|
run: pnpm exec prettier --check .
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
# Rust backend checks
|
||||||
|
rust-check:
|
||||||
|
name: Rust Check
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Rust toolchain
|
||||||
uses: dtolnay/rust-toolchain@stable
|
uses: dtolnay/rust-toolchain@stable
|
||||||
with:
|
with:
|
||||||
components: rustfmt, clippy
|
components: rustfmt, clippy
|
||||||
targets: ${{ matrix.target }}
|
|
||||||
|
|
||||||
- name: Use sccache
|
- name: Rust Cache
|
||||||
if: runner.os != 'Linux' && github.event_name != 'release' && github.event_name != 'workflow_dispatch'
|
|
||||||
uses: mozilla-actions/sccache-action@v0.0.9
|
|
||||||
|
|
||||||
- name: Configure sccache
|
|
||||||
if: runner.os != 'Linux' && github.event_name != 'release' && github.event_name != 'workflow_dispatch'
|
|
||||||
run: |
|
|
||||||
# Enable GitHub Actions for cache storage
|
|
||||||
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
|
|
||||||
# Use sccache for rustc
|
|
||||||
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Rust cache
|
|
||||||
uses: Swatinem/rust-cache@v2
|
uses: Swatinem/rust-cache@v2
|
||||||
with:
|
with:
|
||||||
workspaces: src-tauri
|
workspaces: src-tauri
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Install Linux dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
|
||||||
|
|
||||||
|
- name: Format check
|
||||||
|
run: cargo fmt --manifest-path src-tauri/Cargo.toml --all -- --check
|
||||||
|
|
||||||
|
- name: Clippy
|
||||||
|
run: cargo clippy --manifest-path src-tauri/Cargo.toml --all-targets --all-features -- -D warnings
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: cargo test --manifest-path src-tauri/Cargo.toml --all-features
|
||||||
|
|
||||||
|
# Security audit
|
||||||
|
security-audit:
|
||||||
|
name: Security Audit
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Rust toolchain
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
|
||||||
|
- name: Install cargo-audit
|
||||||
|
uses: taiki-e/cache-cargo-install-action@v2
|
||||||
|
with:
|
||||||
|
tool: cargo-audit
|
||||||
|
|
||||||
|
- name: Run security audit
|
||||||
|
run: cargo audit --file src-tauri/Cargo.lock
|
||||||
|
|
||||||
|
# Check if Tauri app builds successfully
|
||||||
|
build-check:
|
||||||
|
name: Build Check
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [frontend-check, rust-check]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install pnpm
|
||||||
uses: pnpm/action-setup@v4
|
uses: pnpm/action-setup@v4
|
||||||
with:
|
with:
|
||||||
version: 10.19.0
|
version: 10
|
||||||
|
|
||||||
- name: Setup Node
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v6
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 22.21.1
|
node-version: "20"
|
||||||
cache: "pnpm"
|
cache: "pnpm"
|
||||||
|
|
||||||
- name: Install frontend dependencies
|
- name: Install Rust toolchain
|
||||||
run: pnpm install --frozen-lockfile --prefer-offline
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
|
||||||
- name: Install backend dependencies
|
- name: Rust Cache
|
||||||
run: cargo fetch --manifest-path src-tauri/Cargo.toml
|
uses: Swatinem/rust-cache@v2
|
||||||
|
|
||||||
- name: Install Tauri CLI
|
|
||||||
uses: Xevion/cache-cargo-install-action@main
|
|
||||||
with:
|
with:
|
||||||
tool: tauri-cli@2
|
workspaces: src-tauri
|
||||||
locked: true
|
|
||||||
|
|
||||||
- name: Cache apt packages
|
|
||||||
if: runner.os == 'Linux'
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: /var/cache/apt/archives
|
|
||||||
key: ${{ runner.os }}-apt-${{ hashFiles('**/Cargo.lock') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-apt-
|
|
||||||
|
|
||||||
- name: Install Linux dependencies
|
- name: Install Linux dependencies
|
||||||
if: runner.os == 'Linux'
|
|
||||||
run: |
|
run: |
|
||||||
# Update package list and install dependencies in one command to reduce time
|
sudo apt-get update
|
||||||
sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends \
|
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
|
||||||
build-essential \
|
|
||||||
libxdo-dev \
|
|
||||||
libglib2.0-dev \
|
|
||||||
libwebkit2gtk-4.1-dev \
|
|
||||||
libayatana-appindicator3-dev \
|
|
||||||
librsvg2-dev \
|
|
||||||
patchelf \
|
|
||||||
musl-tools
|
|
||||||
|
|
||||||
- name: Generate frontend bindings
|
- name: Install frontend dependencies
|
||||||
run: pnpm run generate-types
|
run: pnpm install
|
||||||
|
|
||||||
- name: Build app (tauri)
|
- name: Build Tauri app
|
||||||
run: cargo tauri build --target ${{ matrix.target }}
|
run: pnpm tauri build --no-bundle
|
||||||
|
|
||||||
- name: Upload binary artifact
|
|
||||||
uses: actions/upload-artifact@v5
|
|
||||||
with:
|
|
||||||
name: ${{ matrix.artifact_name }}
|
|
||||||
path: |
|
|
||||||
src-tauri/target/${{ matrix.target }}/release/byte-me${{ matrix.artifact_extension }}
|
|
||||||
src-tauri/target/${{ matrix.target }}/release/bundle/**/*
|
|
||||||
if-no-files-found: error
|
|
||||||
|
|||||||
74
.github/workflows/code-quality.yml
vendored
74
.github/workflows/code-quality.yml
vendored
@@ -6,15 +6,25 @@ on:
|
|||||||
workflow_dispatch: # Allow manual triggering
|
workflow_dispatch: # Allow manual triggering
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [master]
|
branches: [master]
|
||||||
|
paths:
|
||||||
|
- "**/Cargo.toml"
|
||||||
|
- "**/Cargo.lock"
|
||||||
|
- "**/package.json"
|
||||||
|
- "**/pnpm-lock.yaml"
|
||||||
push:
|
push:
|
||||||
branches: [master]
|
branches: [master]
|
||||||
|
paths:
|
||||||
|
- "**/Cargo.toml"
|
||||||
|
- "**/Cargo.lock"
|
||||||
|
- "**/package.json"
|
||||||
|
- "**/pnpm-lock.yaml"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
rust-quality:
|
rust-quality:
|
||||||
name: Rust Code Quality
|
name: Rust Code Quality
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install Rust toolchain
|
- name: Install Rust toolchain
|
||||||
uses: dtolnay/rust-toolchain@nightly
|
uses: dtolnay/rust-toolchain@nightly
|
||||||
@@ -29,25 +39,20 @@ jobs:
|
|||||||
- name: Install Linux dependencies
|
- name: Install Linux dependencies
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y \
|
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
|
||||||
pkg-config \
|
|
||||||
build-essential \
|
|
||||||
libxdo-dev \
|
|
||||||
libssl-dev \
|
|
||||||
libglib2.0-dev \
|
|
||||||
libwebkit2gtk-4.1-dev \
|
|
||||||
libayatana-appindicator3-dev \
|
|
||||||
librsvg2-dev \
|
|
||||||
patchelf
|
|
||||||
|
|
||||||
- name: Install cargo-udeps
|
- name: Install cargo-udeps
|
||||||
uses: taiki-e/install-action@cargo-udeps
|
uses: taiki-e/cache-cargo-install-action@v2
|
||||||
|
with:
|
||||||
|
tool: cargo-udeps
|
||||||
|
|
||||||
- name: Check for unused dependencies
|
- name: Check for unused dependencies
|
||||||
run: cargo +nightly udeps --manifest-path src-tauri/Cargo.toml --all-targets
|
run: cargo +nightly udeps --manifest-path src-tauri/Cargo.toml --all-targets
|
||||||
|
|
||||||
- name: Install cargo-machete
|
- name: Install cargo-machete
|
||||||
uses: taiki-e/install-action@cargo-machete
|
uses: taiki-e/cache-cargo-install-action@v2
|
||||||
|
with:
|
||||||
|
tool: cargo-machete
|
||||||
|
|
||||||
- name: Check for unused Cargo.toml dependencies
|
- name: Check for unused Cargo.toml dependencies
|
||||||
run: cargo machete src-tauri/
|
run: cargo machete src-tauri/
|
||||||
@@ -65,17 +70,17 @@ jobs:
|
|||||||
name: Frontend Code Quality
|
name: Frontend Code Quality
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install pnpm
|
- name: Install pnpm
|
||||||
uses: pnpm/action-setup@v4
|
uses: pnpm/action-setup@v4
|
||||||
with:
|
with:
|
||||||
version: 10.19.0
|
version: 10
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v6
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 22.21.1
|
node-version: 20
|
||||||
cache: pnpm
|
cache: pnpm
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
@@ -92,3 +97,38 @@ jobs:
|
|||||||
- name: Bundle size analysis
|
- name: Bundle size analysis
|
||||||
run: pnpm run build && du -sh dist/
|
run: pnpm run build && du -sh dist/
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
|
license-check:
|
||||||
|
name: License Check
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Rust toolchain
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
|
||||||
|
- name: Install cargo-license
|
||||||
|
uses: taiki-e/cache-cargo-install-action@v2
|
||||||
|
with:
|
||||||
|
tool: cargo-license
|
||||||
|
|
||||||
|
- name: Check Rust crate licenses
|
||||||
|
run: cargo license --manifest-path src-tauri/Cargo.toml --json > rust-licenses.json
|
||||||
|
|
||||||
|
- name: Install pnpm
|
||||||
|
uses: pnpm/action-setup@v4
|
||||||
|
with:
|
||||||
|
version: 10
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 20
|
||||||
|
cache: pnpm
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: pnpm install
|
||||||
|
|
||||||
|
- name: Check npm package licenses
|
||||||
|
run: pnpm exec license-checker --json > npm-licenses.json
|
||||||
|
continue-on-error: true
|
||||||
|
|||||||
8
.github/workflows/release.yml
vendored
8
.github/workflows/release.yml
vendored
@@ -23,17 +23,17 @@ jobs:
|
|||||||
|
|
||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install pnpm
|
- name: Install pnpm
|
||||||
uses: pnpm/action-setup@v4
|
uses: pnpm/action-setup@v4
|
||||||
with:
|
with:
|
||||||
version: 10.19.0
|
version: 10
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v6
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 22.21.1
|
node-version: 20
|
||||||
cache: pnpm
|
cache: pnpm
|
||||||
|
|
||||||
- name: Install Rust toolchain
|
- name: Install Rust toolchain
|
||||||
|
|||||||
32
.github/workflows/security-audit.yml
vendored
32
.github/workflows/security-audit.yml
vendored
@@ -3,35 +3,53 @@ name: Security Audit
|
|||||||
on:
|
on:
|
||||||
workflow_dispatch: # Allow manual triggering
|
workflow_dispatch: # Allow manual triggering
|
||||||
push:
|
push:
|
||||||
|
paths:
|
||||||
|
- "**/Cargo.toml"
|
||||||
|
- "**/Cargo.lock"
|
||||||
|
- "**/package.json"
|
||||||
|
- "**/pnpm-lock.yaml"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
rust-audit:
|
rust-audit:
|
||||||
name: Rust Security Audit
|
name: Rust Security Audit
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Rust toolchain
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
|
||||||
|
- name: Install cargo-audit
|
||||||
|
uses: taiki-e/cache-cargo-install-action@v2
|
||||||
|
with:
|
||||||
|
tool: cargo-audit
|
||||||
|
|
||||||
|
- name: Run cargo audit
|
||||||
|
run: cargo audit --file src-tauri/Cargo.lock
|
||||||
|
|
||||||
- name: Install cargo-deny
|
- name: Install cargo-deny
|
||||||
uses: taiki-e/install-action@cargo-deny
|
uses: taiki-e/cache-cargo-install-action@v2
|
||||||
|
with:
|
||||||
|
tool: cargo-deny
|
||||||
|
|
||||||
- name: Run cargo deny
|
- name: Run cargo deny
|
||||||
run: cargo deny --manifest-path src-tauri/Cargo.toml check sources advisories bans --show-stats
|
run: cargo deny --manifest-path src-tauri/Cargo.toml check
|
||||||
|
|
||||||
npm-audit:
|
npm-audit:
|
||||||
name: NPM Security Audit
|
name: NPM Security Audit
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install pnpm
|
- name: Install pnpm
|
||||||
uses: pnpm/action-setup@v4
|
uses: pnpm/action-setup@v4
|
||||||
with:
|
with:
|
||||||
version: 10.19.0
|
version: 10
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v6
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: "22.21.1"
|
node-version: "20"
|
||||||
cache: "pnpm"
|
cache: "pnpm"
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
|
|||||||
37
Justfile
37
Justfile
@@ -1,37 +0,0 @@
|
|||||||
# Default recipe - show available commands
|
|
||||||
default:
|
|
||||||
@just --list
|
|
||||||
|
|
||||||
dev:
|
|
||||||
cargo tauri dev
|
|
||||||
|
|
||||||
dev-build:
|
|
||||||
cargo tauri build --debug
|
|
||||||
|
|
||||||
generate-types:
|
|
||||||
cargo test --manifest-path src-tauri/Cargo.toml -- --test export_bindings
|
|
||||||
|
|
||||||
check-frontend:
|
|
||||||
pnpm exec tsc --noEmit
|
|
||||||
|
|
||||||
check-backend:
|
|
||||||
cargo clippy --manifest-path src-tauri/Cargo.toml
|
|
||||||
|
|
||||||
check: check-frontend check-backend
|
|
||||||
|
|
||||||
build-frontend: generate-types
|
|
||||||
pnpm exec tsc
|
|
||||||
pnpm exec vite build
|
|
||||||
|
|
||||||
build-backend:
|
|
||||||
cargo build --manifest-path src-tauri/Cargo.toml
|
|
||||||
|
|
||||||
build: build-frontend build-backend
|
|
||||||
|
|
||||||
test-frontend:
|
|
||||||
pnpm exec vitest run
|
|
||||||
|
|
||||||
test-backend:
|
|
||||||
cargo nextest run --manifest-path src-tauri/Cargo.toml
|
|
||||||
|
|
||||||
test: test-frontend test-backend
|
|
||||||
36
package.json
36
package.json
@@ -7,32 +7,30 @@
|
|||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "pnpm generate-types && tsc && vite build",
|
"build": "pnpm generate-types && tsc && vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"test": "vitest run",
|
|
||||||
"tauri": "tauri",
|
"tauri": "tauri",
|
||||||
"generate-types": "cargo test --manifest-path src-tauri/Cargo.toml -- --test export_bindings"
|
"generate-types": "tsx scripts/generate-types.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nivo/core": "^0.99.0",
|
"@nivo/core": "^0.99.0",
|
||||||
"@nivo/line": "^0.99.0",
|
"@nivo/line": "^0.99.0",
|
||||||
"@tailwindcss/vite": "^4.1.17",
|
"@tailwindcss/vite": "^4.1.11",
|
||||||
"@tauri-apps/api": "^2.9.0",
|
"@tauri-apps/api": "^2",
|
||||||
"@tauri-apps/plugin-opener": "^2.5.2",
|
"@tauri-apps/plugin-opener": "^2",
|
||||||
"lucide-react": "^0.548.0",
|
"lucide-react": "^0.525.0",
|
||||||
"react": "^19.2.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^19.2.1",
|
"react-dom": "^18.3.1",
|
||||||
"tailwindcss": "^4.1.17",
|
"tailwindcss": "^4.1.11",
|
||||||
"ts-pattern": "^5.9.0"
|
"ts-pattern": "^5.7.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tauri-apps/cli": "^2.9.3",
|
"@tauri-apps/cli": "^2",
|
||||||
"@tsconfig/vite-react": "^7.0.2",
|
"@types/react": "^18.3.1",
|
||||||
"@types/react": "^19.2.7",
|
"@types/react-dom": "^18.3.1",
|
||||||
"@types/react-dom": "^19.2.3",
|
"@vitejs/plugin-react": "^4.3.4",
|
||||||
"@vitejs/plugin-react": "^5.1.2",
|
"prettier": "^3.6.2",
|
||||||
"prettier": "^3.7.4",
|
"tsx": "^4.19.2",
|
||||||
"tsx": "^4.21.0",
|
"typescript": "~5.6.2",
|
||||||
"typescript": "~5.9.3",
|
"vite": "^6.0.3",
|
||||||
"vite": "^7.2.7",
|
|
||||||
"vitest": "^3.2.4"
|
"vitest": "^3.2.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1957
pnpm-lock.yaml
generated
1957
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
153
renovate.json
153
renovate.json
@@ -1,153 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
|
||||||
"extends": [
|
|
||||||
"config:recommended",
|
|
||||||
":enableVulnerabilityAlertsWithLabel(security)"
|
|
||||||
],
|
|
||||||
"schedule": ["before 6am on Monday"],
|
|
||||||
"timezone": "UTC",
|
|
||||||
"prConcurrentLimit": 10,
|
|
||||||
"prHourlyLimit": 0,
|
|
||||||
"semanticCommits": "enabled",
|
|
||||||
"dependencyDashboard": true,
|
|
||||||
"labels": ["dependencies"],
|
|
||||||
"rangeStrategy": "bump",
|
|
||||||
"postUpdateOptions": ["pnpmDedupe"],
|
|
||||||
"packageRules": [
|
|
||||||
{
|
|
||||||
"description": "Automerge non-major dev dependencies",
|
|
||||||
"matchDepTypes": ["devDependencies"],
|
|
||||||
"matchUpdateTypes": ["minor", "patch"],
|
|
||||||
"automerge": true,
|
|
||||||
"automergeType": "pr",
|
|
||||||
"ignoreTests": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Automerge patch updates for production dependencies",
|
|
||||||
"matchDepTypes": ["dependencies"],
|
|
||||||
"matchUpdateTypes": ["patch"],
|
|
||||||
"automerge": true,
|
|
||||||
"automergeType": "pr",
|
|
||||||
"ignoreTests": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Group all Tauri packages together",
|
|
||||||
"groupName": "Tauri",
|
|
||||||
"matchManagers": ["npm"],
|
|
||||||
"automerge": false,
|
|
||||||
"labels": ["dependencies", "tauri"],
|
|
||||||
"matchPackageNames": ["/^@tauri-apps//", "/^tauri-/"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Group Tauri Rust dependencies",
|
|
||||||
"groupName": "Tauri (Rust)",
|
|
||||||
"matchPackageNames": ["tauri", "tauri-build"],
|
|
||||||
"matchManagers": ["cargo"],
|
|
||||||
"automerge": false,
|
|
||||||
"labels": ["dependencies", "tauri", "rust"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Group React ecosystem updates",
|
|
||||||
"groupName": "React",
|
|
||||||
"matchPackageNames": ["react", "react-dom", "/^@types/react/"],
|
|
||||||
"labels": ["dependencies", "react"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Group TypeScript and build tooling",
|
|
||||||
"groupName": "Build tooling",
|
|
||||||
"matchPackageNames": [
|
|
||||||
"typescript",
|
|
||||||
"vite",
|
|
||||||
"@vitejs/plugin-react",
|
|
||||||
"vite-tsconfig-paths"
|
|
||||||
],
|
|
||||||
"labels": ["dependencies", "tooling"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Group ESLint and related plugins",
|
|
||||||
"groupName": "ESLint",
|
|
||||||
"labels": ["dependencies", "linting"],
|
|
||||||
"matchPackageNames": [
|
|
||||||
"/^eslint/",
|
|
||||||
"/^@eslint//",
|
|
||||||
"/^@typescript-eslint//"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Group testing frameworks",
|
|
||||||
"groupName": "Testing",
|
|
||||||
"labels": ["dependencies", "testing"],
|
|
||||||
"matchPackageNames": ["/^vitest/", "/^@vitest//"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Group TailwindCSS and plugins",
|
|
||||||
"groupName": "TailwindCSS",
|
|
||||||
"labels": ["dependencies", "styling"],
|
|
||||||
"matchPackageNames": ["/^tailwindcss/", "/^@tailwindcss//"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Group Nivo chart libraries",
|
|
||||||
"groupName": "Nivo",
|
|
||||||
"labels": ["dependencies", "charts"],
|
|
||||||
"matchPackageNames": ["/^@nivo//"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Separate major updates for manual review",
|
|
||||||
"matchUpdateTypes": ["major"],
|
|
||||||
"automerge": false,
|
|
||||||
"labels": ["dependencies", "major-update"],
|
|
||||||
"reviewers": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "High priority security updates",
|
|
||||||
"matchUpdateTypes": ["security"],
|
|
||||||
"labels": ["dependencies", "security"],
|
|
||||||
"automerge": false,
|
|
||||||
"schedule": ["at any time"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Rust patch updates - automerge",
|
|
||||||
"matchManagers": ["cargo"],
|
|
||||||
"matchUpdateTypes": ["patch"],
|
|
||||||
"automerge": true,
|
|
||||||
"automergeType": "pr"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Rust minor updates - review required",
|
|
||||||
"matchManagers": ["cargo"],
|
|
||||||
"matchUpdateTypes": ["minor"],
|
|
||||||
"automerge": false,
|
|
||||||
"labels": ["dependencies", "rust", "minor-update"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Rust major updates - careful review",
|
|
||||||
"matchManagers": ["cargo"],
|
|
||||||
"matchUpdateTypes": ["major"],
|
|
||||||
"automerge": false,
|
|
||||||
"labels": ["dependencies", "rust", "major-update"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Pin ts-rs (type generation critical)",
|
|
||||||
"matchPackageNames": ["ts-rs"],
|
|
||||||
"matchManagers": ["cargo"],
|
|
||||||
"automerge": false,
|
|
||||||
"labels": ["dependencies", "rust", "type-generation"]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"cargo": {
|
|
||||||
"enabled": true,
|
|
||||||
"rangeStrategy": "bump"
|
|
||||||
},
|
|
||||||
"npm": {
|
|
||||||
"enabled": true,
|
|
||||||
"rangeStrategy": "bump"
|
|
||||||
},
|
|
||||||
"lockFileMaintenance": {
|
|
||||||
"enabled": true,
|
|
||||||
"automerge": true,
|
|
||||||
"schedule": ["before 6am on Monday"]
|
|
||||||
},
|
|
||||||
"platformAutomerge": true,
|
|
||||||
"ignoreTests": false,
|
|
||||||
"commitMessagePrefix": "chore(deps):"
|
|
||||||
}
|
|
||||||
51
scripts/generate-types.ts
Normal file
51
scripts/generate-types.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
import { execSync } from "child_process";
|
||||||
|
import { copyFileSync, mkdirSync, existsSync, readdirSync } from "fs";
|
||||||
|
import { join, dirname } from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = dirname(__filename);
|
||||||
|
|
||||||
|
console.log("🔄 Generating TypeScript bindings...");
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Run the test to generate bindings
|
||||||
|
execSync("cargo test export_bindings", {
|
||||||
|
cwd: "./src-tauri",
|
||||||
|
stdio: "inherit",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!existsSync(join(__dirname, "../src-tauri/bindings"))) {
|
||||||
|
throw new Error(
|
||||||
|
"Bindings directory not found. Bindings generation failed or improperly configured.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("✅ TypeScript bindings generated successfully!");
|
||||||
|
|
||||||
|
// Copy bindings to src directory
|
||||||
|
const srcBindingsDir = join(__dirname, "../src/bindings");
|
||||||
|
const files = readdirSync(join(__dirname, "../src-tauri/bindings")).filter(
|
||||||
|
(file) => file.endsWith(".ts"),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (files.length === 0) {
|
||||||
|
throw new Error(
|
||||||
|
"No bindings files found. Bindings generation failed or improperly configured.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
const source = join(__dirname, "../src-tauri/bindings", file);
|
||||||
|
const dest = join(srcBindingsDir, file);
|
||||||
|
copyFileSync(source, dest);
|
||||||
|
console.log(`📁 Copied ${file} to src/bindings/`);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("🎉 All done! TypeScript bindings are up to date.");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("❌ Failed to generate TypeScript bindings:", error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
1820
src-tauri/Cargo.lock
generated
1820
src-tauri/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -15,14 +15,13 @@ name = "byte_me_lib"
|
|||||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
tauri-build = { version = "2.5.3", features = [] }
|
tauri-build = { version = "2", features = [] }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tauri = { version = "2.9.4", features = [] }
|
tauri = { version = "2.0", features = [] }
|
||||||
tauri-plugin-opener = "2.5.2"
|
tauri-plugin-opener = "2"
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
serde_json = "1"
|
||||||
ffprobe = "0.4.0"
|
ffprobe = "0.4.0"
|
||||||
ts-rs = { version = "11.1.0", features = ["format"] }
|
ts-rs = { version = "11.0", features = ["format"] }
|
||||||
infer = "0.19.0"
|
infer = "0.19.0"
|
||||||
tracing = "0.1.43"
|
|
||||||
tracing-subscriber = { version = "0.3.22", features = ["env-filter"] }
|
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
[graph]
|
|
||||||
targets = [
|
|
||||||
"x86_64-unknown-linux-gnu",
|
|
||||||
"x86_64-pc-windows-msvc",
|
|
||||||
"aarch64-apple-darwin",
|
|
||||||
"x86_64-apple-darwin",
|
|
||||||
]
|
|
||||||
all-features = true
|
|
||||||
no-default-features = false
|
|
||||||
|
|
||||||
[output]
|
|
||||||
feature-depth = 1
|
|
||||||
|
|
||||||
[advisories]
|
|
||||||
ignore = [
|
|
||||||
"RUSTSEC-2024-0429",
|
|
||||||
]
|
|
||||||
unmaintained = "workspace"
|
|
||||||
|
|
||||||
[licenses]
|
|
||||||
allow = []
|
|
||||||
confidence-threshold = 0.8
|
|
||||||
exceptions = []
|
|
||||||
|
|
||||||
[licenses.private]
|
|
||||||
ignore = false
|
|
||||||
registries = []
|
|
||||||
|
|
||||||
[bans]
|
|
||||||
multiple-versions = "allow"
|
|
||||||
wildcards = "allow"
|
|
||||||
highlight = "all"
|
|
||||||
workspace-default-features = "allow"
|
|
||||||
external-default-features = "allow"
|
|
||||||
allow = []
|
|
||||||
|
|
||||||
[sources]
|
|
||||||
unknown-registry = "warn"
|
|
||||||
unknown-git = "warn"
|
|
||||||
@@ -1,109 +1,47 @@
|
|||||||
use crate::models::StreamDetail;
|
use crate::models::StreamDetail;
|
||||||
use tracing::{debug, info, instrument};
|
|
||||||
|
|
||||||
#[instrument(skip(info), fields(stream_count = info.streams.len()))]
|
|
||||||
pub fn extract_streams(info: &ffprobe::FfProbe) -> Vec<StreamDetail> {
|
pub fn extract_streams(info: &ffprobe::FfProbe) -> Vec<StreamDetail> {
|
||||||
let mut streams = Vec::new();
|
let mut streams = Vec::new();
|
||||||
let mut video_count = 0;
|
|
||||||
let mut audio_count = 0;
|
|
||||||
let mut subtitle_count = 0;
|
|
||||||
|
|
||||||
info!(total_streams = info.streams.len(), "Extracting streams from media file");
|
for stream in &info.streams {
|
||||||
|
|
||||||
for (index, stream) in info.streams.iter().enumerate() {
|
|
||||||
match stream.codec_type.as_deref() {
|
match stream.codec_type.as_deref() {
|
||||||
Some("video") => {
|
Some("video") => {
|
||||||
video_count += 1;
|
streams.push(StreamDetail::Video {
|
||||||
let codec = stream
|
codec: stream
|
||||||
.codec_name
|
.codec_name
|
||||||
.clone()
|
.clone()
|
||||||
.unwrap_or_else(|| "unknown".to_string());
|
.unwrap_or_else(|| "unknown".to_string()),
|
||||||
let width = stream.width.map(|w| w as u32);
|
width: stream.width.map(|w| w as u32),
|
||||||
let height = stream.height.map(|h| h as u32);
|
height: stream.height.map(|h| h as u32),
|
||||||
let bit_rate = stream.bit_rate.as_ref().map(|b| b.to_string());
|
bit_rate: stream.bit_rate.as_ref().map(|b| b.to_string()),
|
||||||
let frame_rate = Some(stream.r_frame_rate.clone());
|
frame_rate: Some(stream.r_frame_rate.clone()),
|
||||||
|
|
||||||
debug!(
|
|
||||||
stream_index = index,
|
|
||||||
codec = %codec,
|
|
||||||
width = ?width,
|
|
||||||
height = ?height,
|
|
||||||
bit_rate = ?bit_rate,
|
|
||||||
frame_rate = ?frame_rate,
|
|
||||||
"Extracted video stream"
|
|
||||||
);
|
|
||||||
|
|
||||||
streams.push(StreamDetail::Video {
|
|
||||||
codec,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
bit_rate,
|
|
||||||
frame_rate,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Some("audio") => {
|
Some("audio") => {
|
||||||
audio_count += 1;
|
streams.push(StreamDetail::Audio {
|
||||||
let codec = stream
|
codec: stream
|
||||||
.codec_name
|
.codec_name
|
||||||
.clone()
|
.clone()
|
||||||
.unwrap_or_else(|| "unknown".to_string());
|
.unwrap_or_else(|| "unknown".to_string()),
|
||||||
let sample_rate = stream.sample_rate.clone();
|
sample_rate: stream.sample_rate.clone(),
|
||||||
let channels = stream.channels.map(|c| c as u32);
|
channels: stream.channels.map(|c| c as u32),
|
||||||
let bit_rate = stream.bit_rate.as_ref().map(|b| b.to_string());
|
bit_rate: stream.bit_rate.as_ref().map(|b| b.to_string()),
|
||||||
|
|
||||||
debug!(
|
|
||||||
stream_index = index,
|
|
||||||
codec = %codec,
|
|
||||||
sample_rate = ?sample_rate,
|
|
||||||
channels = ?channels,
|
|
||||||
bit_rate = ?bit_rate,
|
|
||||||
"Extracted audio stream"
|
|
||||||
);
|
|
||||||
|
|
||||||
streams.push(StreamDetail::Audio {
|
|
||||||
codec,
|
|
||||||
sample_rate,
|
|
||||||
channels,
|
|
||||||
bit_rate,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Some("subtitle") => {
|
Some("subtitle") => {
|
||||||
subtitle_count += 1;
|
streams.push(StreamDetail::Subtitle {
|
||||||
let codec = stream
|
codec: stream
|
||||||
.codec_name
|
.codec_name
|
||||||
.clone()
|
.clone()
|
||||||
.unwrap_or_else(|| "unknown".to_string());
|
.unwrap_or_else(|| "unknown".to_string()),
|
||||||
let language = stream.tags.as_ref().and_then(|tags| tags.language.clone());
|
language: stream.tags.as_ref().and_then(|tags| tags.language.clone()),
|
||||||
|
|
||||||
debug!(
|
|
||||||
stream_index = index,
|
|
||||||
codec = %codec,
|
|
||||||
language = ?language,
|
|
||||||
"Extracted subtitle stream"
|
|
||||||
);
|
|
||||||
|
|
||||||
streams.push(StreamDetail::Subtitle {
|
|
||||||
codec,
|
|
||||||
language,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
other => {
|
_ => {}
|
||||||
debug!(
|
|
||||||
stream_index = index,
|
|
||||||
codec_type = ?other,
|
|
||||||
"Skipping unknown stream type"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
info!(
|
|
||||||
video_streams = video_count,
|
|
||||||
audio_streams = audio_count,
|
|
||||||
subtitle_streams = subtitle_count,
|
|
||||||
total_extracted = streams.len(),
|
|
||||||
"Stream extraction completed"
|
|
||||||
);
|
|
||||||
|
|
||||||
streams
|
streams
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,27 +1,19 @@
|
|||||||
pub mod ff;
|
mod ff;
|
||||||
pub mod media;
|
mod media;
|
||||||
pub mod models;
|
mod models;
|
||||||
pub mod strings;
|
|
||||||
|
|
||||||
use ff::extract_streams;
|
use ff::extract_streams;
|
||||||
use media::{detect_media_type, is_media_file};
|
use media::{detect_media_type, is_media_file};
|
||||||
use models::{StreamResult, StreamResultError, File, FileCandidacy, BitrateData, BitrateFrame};
|
use models::{StreamResult, StreamResultError};
|
||||||
use strings::transform_filename;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
|
||||||
use tracing::{debug, error, info, instrument, warn};
|
|
||||||
|
|
||||||
// detection, helpers moved to modules above
|
// detection, helpers moved to modules above
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
#[instrument(skip(paths), fields(file_count = paths.len()))]
|
|
||||||
fn has_streams(paths: Vec<String>) -> Result<Vec<StreamResult>, StreamResultError> {
|
fn has_streams(paths: Vec<String>) -> Result<Vec<StreamResult>, StreamResultError> {
|
||||||
info!(file_count = paths.len(), "Processing files for stream analysis");
|
paths
|
||||||
|
|
||||||
let results = paths
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.enumerate()
|
.map(|path_str| {
|
||||||
.map(|(index, path_str)| {
|
|
||||||
let path = Path::new(&path_str);
|
let path = Path::new(&path_str);
|
||||||
let filename = path
|
let filename = path
|
||||||
.file_name()
|
.file_name()
|
||||||
@@ -29,18 +21,8 @@ fn has_streams(paths: Vec<String>) -> Result<Vec<StreamResult>, StreamResultErro
|
|||||||
.unwrap_or("unknown")
|
.unwrap_or("unknown")
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
// Log full path only on first occurrence, then use truncated filename
|
|
||||||
if index == 0 {
|
|
||||||
debug!(full_path = %path_str, filename = %filename, "Processing first file");
|
|
||||||
} else {
|
|
||||||
let truncated_name = transform_filename(&filename, 15);
|
|
||||||
debug!(filename = %truncated_name, "Processing file");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if file exists
|
// Check if file exists
|
||||||
if !path.exists() {
|
if !path.exists() {
|
||||||
let truncated_name = transform_filename(&filename, 15);
|
|
||||||
warn!(filename = %truncated_name, "File does not exist");
|
|
||||||
return Err(StreamResultError {
|
return Err(StreamResultError {
|
||||||
filename: Some(filename),
|
filename: Some(filename),
|
||||||
reason: "File does not exist".to_string(),
|
reason: "File does not exist".to_string(),
|
||||||
@@ -50,8 +32,6 @@ fn has_streams(paths: Vec<String>) -> Result<Vec<StreamResult>, StreamResultErro
|
|||||||
|
|
||||||
// Check if it's a file (not directory)
|
// Check if it's a file (not directory)
|
||||||
if !path.is_file() {
|
if !path.is_file() {
|
||||||
let truncated_name = transform_filename(&filename, 15);
|
|
||||||
warn!(filename = %truncated_name, "Path is not a file");
|
|
||||||
return Err(StreamResultError {
|
return Err(StreamResultError {
|
||||||
filename: Some(filename),
|
filename: Some(filename),
|
||||||
reason: "Not a file (directory or other)".to_string(),
|
reason: "Not a file (directory or other)".to_string(),
|
||||||
@@ -64,17 +44,11 @@ fn has_streams(paths: Vec<String>) -> Result<Vec<StreamResult>, StreamResultErro
|
|||||||
.map(|metadata| metadata.len())
|
.map(|metadata| metadata.len())
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
|
|
||||||
let truncated_name = transform_filename(&filename, 15);
|
|
||||||
debug!(filename = %truncated_name, size = size, "File metadata retrieved");
|
|
||||||
|
|
||||||
// Detect media type using magic numbers and fallback to extensions
|
// Detect media type using magic numbers and fallback to extensions
|
||||||
let media_type = detect_media_type(path);
|
let media_type = detect_media_type(path);
|
||||||
debug!(filename = %truncated_name, media_type = ?media_type, "Media type detected");
|
|
||||||
|
|
||||||
// Only try to analyze media files with ffprobe
|
// Only try to analyze media files with ffprobe
|
||||||
if is_media_file(&media_type) {
|
if is_media_file(&media_type) {
|
||||||
info!(filename = %truncated_name, media_type = ?media_type, "Analyzing media file with ffprobe");
|
|
||||||
|
|
||||||
// Analyze with ffprobe
|
// Analyze with ffprobe
|
||||||
match ffprobe::ffprobe(&path_str) {
|
match ffprobe::ffprobe(&path_str) {
|
||||||
Ok(info) => {
|
Ok(info) => {
|
||||||
@@ -84,13 +58,6 @@ fn has_streams(paths: Vec<String>) -> Result<Vec<StreamResult>, StreamResultErro
|
|||||||
.duration
|
.duration
|
||||||
.and_then(|dur_str| dur_str.parse::<f64>().ok());
|
.and_then(|dur_str| dur_str.parse::<f64>().ok());
|
||||||
|
|
||||||
info!(
|
|
||||||
filename = %truncated_name,
|
|
||||||
stream_count = streams.len(),
|
|
||||||
duration = ?duration,
|
|
||||||
"Successfully analyzed media file"
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(StreamResult {
|
Ok(StreamResult {
|
||||||
filename,
|
filename,
|
||||||
path: path_str,
|
path: path_str,
|
||||||
@@ -101,7 +68,7 @@ fn has_streams(paths: Vec<String>) -> Result<Vec<StreamResult>, StreamResultErro
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!(filename = %truncated_name, error = %err, "Failed to analyze media file with ffprobe");
|
eprintln!("Could not analyze media file with ffprobe: {err:?}");
|
||||||
Err(StreamResultError {
|
Err(StreamResultError {
|
||||||
filename: Some(filename),
|
filename: Some(filename),
|
||||||
reason: format!("Could not analyze media file: {err}"),
|
reason: format!("Could not analyze media file: {err}"),
|
||||||
@@ -110,7 +77,6 @@ fn has_streams(paths: Vec<String>) -> Result<Vec<StreamResult>, StreamResultErro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug!(filename = %truncated_name, media_type = ?media_type, "Skipping non-media file");
|
|
||||||
// For non-media files, return an error indicating it's not a media file
|
// For non-media files, return an error indicating it's not a media file
|
||||||
Err(StreamResultError {
|
Err(StreamResultError {
|
||||||
filename: Some(filename),
|
filename: Some(filename),
|
||||||
@@ -119,188 +85,28 @@ fn has_streams(paths: Vec<String>) -> Result<Vec<StreamResult>, StreamResultErro
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, _>>();
|
.collect::<Result<Vec<_>, _>>()
|
||||||
|
|
||||||
match &results {
|
|
||||||
Ok(streams) => {
|
|
||||||
info!(successful_files = streams.len(), "Successfully processed all files");
|
|
||||||
}
|
|
||||||
Err(_) => {
|
|
||||||
warn!("Some files failed to process");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
results
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
#[instrument(skip(paths), fields(file_count = paths.len()))]
|
|
||||||
fn analyze_files(paths: Vec<String>) -> Vec<File> {
|
|
||||||
info!(file_count = paths.len(), "Analyzing files for candidacy");
|
|
||||||
|
|
||||||
paths
|
|
||||||
.into_iter()
|
|
||||||
.enumerate()
|
|
||||||
.map(|(index, path_str)| {
|
|
||||||
let path = Path::new(&path_str);
|
|
||||||
let filename = path
|
|
||||||
.file_name()
|
|
||||||
.and_then(|name| name.to_str())
|
|
||||||
.unwrap_or("unknown")
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
// Log full path only on first occurrence, then use truncated filename
|
|
||||||
if index == 0 {
|
|
||||||
debug!(full_path = %path_str, filename = %filename, "Processing first file");
|
|
||||||
} else {
|
|
||||||
let truncated_name = transform_filename(&filename, 15);
|
|
||||||
debug!(filename = %truncated_name, "Processing file");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get file size
|
|
||||||
let size = std::fs::metadata(&path_str)
|
|
||||||
.map(|metadata| metadata.len())
|
|
||||||
.unwrap_or(0) as u32;
|
|
||||||
|
|
||||||
let truncated_name = transform_filename(&filename, 15);
|
|
||||||
debug!(filename = %truncated_name, size = size, "File metadata retrieved");
|
|
||||||
|
|
||||||
// Check if file exists
|
|
||||||
if !path.exists() {
|
|
||||||
let truncated_name = transform_filename(&filename, 15);
|
|
||||||
warn!(filename = %truncated_name, "File does not exist");
|
|
||||||
return File {
|
|
||||||
filename,
|
|
||||||
size,
|
|
||||||
candidacy: FileCandidacy::Error {
|
|
||||||
reason: "File does not exist".to_string(),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if it's a file (not directory)
|
|
||||||
if !path.is_file() {
|
|
||||||
let truncated_name = transform_filename(&filename, 15);
|
|
||||||
warn!(filename = %truncated_name, "Path is not a file");
|
|
||||||
return File {
|
|
||||||
filename,
|
|
||||||
size,
|
|
||||||
candidacy: FileCandidacy::Error {
|
|
||||||
reason: "Not a file (directory or other)".to_string(),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detect media type using magic numbers and fallback to extensions
|
|
||||||
let media_type = detect_media_type(path);
|
|
||||||
debug!(filename = %truncated_name, media_type = ?media_type, "Media type detected");
|
|
||||||
|
|
||||||
// Check if it's a media file
|
|
||||||
if is_media_file(&media_type) {
|
|
||||||
info!(filename = %truncated_name, media_type = ?media_type, "Valid media file detected");
|
|
||||||
File {
|
|
||||||
filename,
|
|
||||||
size,
|
|
||||||
candidacy: FileCandidacy::Success {
|
|
||||||
file_type: media_type,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
debug!(filename = %truncated_name, media_type = ?media_type, "Non-media file detected");
|
|
||||||
File {
|
|
||||||
filename,
|
|
||||||
size,
|
|
||||||
candidacy: FileCandidacy::Error {
|
|
||||||
reason: format!("Not a media file (detected as {media_type:?})"),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
#[instrument(skip(path), fields(path = %path))]
|
|
||||||
fn extract_bitrate_data(path: String) -> Result<BitrateData, String> {
|
|
||||||
info!(path = %path, "Extracting bitrate data from video file");
|
|
||||||
|
|
||||||
let path_obj = Path::new(&path);
|
|
||||||
let filename = path_obj
|
|
||||||
.file_name()
|
|
||||||
.and_then(|name| name.to_str())
|
|
||||||
.unwrap_or("unknown")
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
// Check if file exists
|
|
||||||
if !path_obj.exists() {
|
|
||||||
error!(filename = %filename, "File does not exist");
|
|
||||||
return Err("File does not exist".to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run ffprobe to get frame packet sizes
|
|
||||||
// -v quiet: suppress ffprobe info
|
|
||||||
// -select_streams v:0: only first video stream
|
|
||||||
// -show_entries frame=pkt_size: only show packet size
|
|
||||||
// -of csv=p=0: output as CSV without headers
|
|
||||||
info!(filename = %filename, "Running ffprobe to extract frame data");
|
|
||||||
|
|
||||||
let output = Command::new("ffprobe")
|
|
||||||
.args([
|
|
||||||
"-v", "quiet",
|
|
||||||
"-select_streams", "v:0",
|
|
||||||
"-show_entries", "frame=pkt_size",
|
|
||||||
"-of", "csv=p=0",
|
|
||||||
&path
|
|
||||||
])
|
|
||||||
.output()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!(error = %e, "Failed to execute ffprobe");
|
|
||||||
format!("Failed to execute ffprobe: {e}")
|
|
||||||
})?;
|
|
||||||
|
|
||||||
if !output.status.success() {
|
|
||||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
||||||
error!(stderr = %stderr, "ffprobe command failed");
|
|
||||||
return Err(format!("ffprobe failed: {stderr}"));
|
|
||||||
}
|
|
||||||
|
|
||||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
||||||
debug!(line_count = stdout.lines().count(), "Parsing ffprobe output");
|
|
||||||
|
|
||||||
let frames: Vec<BitrateFrame> = stdout
|
|
||||||
.lines()
|
|
||||||
.enumerate()
|
|
||||||
.filter_map(|(index, line)| {
|
|
||||||
line.trim().parse::<u64>().ok().map(|packet_size| BitrateFrame {
|
|
||||||
frame_num: index as u32,
|
|
||||||
packet_size,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
if frames.is_empty() {
|
|
||||||
warn!(filename = %filename, "No frame data extracted");
|
|
||||||
return Err("No frame data could be extracted from file".to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
info!(
|
|
||||||
filename = %filename,
|
|
||||||
frame_count = frames.len(),
|
|
||||||
"Successfully extracted bitrate data"
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(BitrateData {
|
|
||||||
id: filename,
|
|
||||||
frames,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
info!("Initializing Tauri application");
|
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.plugin(tauri_plugin_opener::init())
|
.plugin(tauri_plugin_opener::init())
|
||||||
.invoke_handler(tauri::generate_handler![has_streams, analyze_files, extract_bitrate_data])
|
.invoke_handler(tauri::generate_handler![has_streams])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::models::StreamDetail;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
use ts_rs::TS;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn export_bindings() {
|
||||||
|
// This will generate TypeScript bindings when you run `cargo test export_bindings`
|
||||||
|
TS::export_all_to("../../src/bindings")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,19 +1,6 @@
|
|||||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Initialize tracing with env-filter
|
|
||||||
tracing_subscriber::registry()
|
|
||||||
.with(
|
|
||||||
EnvFilter::from_default_env()
|
|
||||||
.add_directive("byte_me=debug".parse().unwrap())
|
|
||||||
.add_directive("tauri=info".parse().unwrap()),
|
|
||||||
)
|
|
||||||
.with(tracing_subscriber::fmt::layer())
|
|
||||||
.init();
|
|
||||||
|
|
||||||
tracing::info!("Starting byte-me application");
|
|
||||||
byte_me_lib::run()
|
byte_me_lib::run()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,13 @@
|
|||||||
use crate::models::MediaType;
|
use crate::models::MediaType;
|
||||||
use std::{fs::File, io::Read, path::Path};
|
use std::{fs::File, io::Read, path::Path};
|
||||||
use tracing::{debug, instrument, trace, warn};
|
|
||||||
|
|
||||||
#[instrument(skip(path), fields(path = %path.display()))]
|
|
||||||
pub fn detect_media_type(path: &Path) -> MediaType {
|
pub fn detect_media_type(path: &Path) -> MediaType {
|
||||||
debug!("Starting media type detection");
|
|
||||||
|
|
||||||
// First try to detect using infer crate (magic number detection)
|
// First try to detect using infer crate (magic number detection)
|
||||||
if let Ok(mut file) = File::open(path) {
|
if let Ok(mut file) = File::open(path) {
|
||||||
let mut buffer = [0; 512];
|
let mut buffer = [0; 512];
|
||||||
if let Ok(bytes_read) = file.read(&mut buffer) {
|
if let Ok(bytes_read) = file.read(&mut buffer) {
|
||||||
trace!(bytes_read = bytes_read, "Read file header for magic number detection");
|
|
||||||
|
|
||||||
if let Some(kind) = infer::get(&buffer[..bytes_read]) {
|
if let Some(kind) = infer::get(&buffer[..bytes_read]) {
|
||||||
let mime_type = kind.mime_type();
|
return match kind.mime_type() {
|
||||||
debug!(mime_type = %mime_type, "Detected MIME type from magic numbers");
|
|
||||||
|
|
||||||
let media_type = match mime_type {
|
|
||||||
// Audio types
|
// Audio types
|
||||||
"audio/mpeg" | "audio/mp3" | "audio/m4a" | "audio/ogg" | "audio/x-flac"
|
"audio/mpeg" | "audio/mp3" | "audio/m4a" | "audio/ogg" | "audio/x-flac"
|
||||||
| "audio/x-wav" | "audio/amr" | "audio/aac" | "audio/x-aiff"
|
| "audio/x-wav" | "audio/amr" | "audio/aac" | "audio/x-aiff"
|
||||||
@@ -99,25 +90,13 @@ pub fn detect_media_type(path: &Path) -> MediaType {
|
|||||||
// Library types (covered by executable types above, but keeping for clarity)
|
// Library types (covered by executable types above, but keeping for clarity)
|
||||||
_ => MediaType::Unknown,
|
_ => MediaType::Unknown,
|
||||||
};
|
};
|
||||||
|
|
||||||
debug!(media_type = ?media_type, "Detected media type from magic numbers");
|
|
||||||
return media_type;
|
|
||||||
} else {
|
|
||||||
debug!("Magic number detection failed, falling back to extension-based detection");
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
warn!("Failed to read file for magic number detection");
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
warn!("Failed to open file for magic number detection");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback to extension-based detection
|
// Fallback to extension-based detection
|
||||||
if let Some(extension) = path.extension() {
|
if let Some(extension) = path.extension() {
|
||||||
let ext_str = extension.to_str().unwrap_or("").to_lowercase();
|
match extension.to_str().unwrap_or("").to_lowercase().as_str() {
|
||||||
debug!(extension = %ext_str, "Detecting media type from file extension");
|
|
||||||
|
|
||||||
let media_type = match ext_str.as_str() {
|
|
||||||
// Audio extensions
|
// Audio extensions
|
||||||
"mp3" | "wav" | "flac" | "ogg" | "m4a" | "aac" | "wma" | "mid" | "amr" | "aiff"
|
"mp3" | "wav" | "flac" | "ogg" | "m4a" | "aac" | "wma" | "mid" | "amr" | "aiff"
|
||||||
| "dsf" | "ape" => MediaType::Audio,
|
| "dsf" | "ape" => MediaType::Audio,
|
||||||
@@ -148,23 +127,15 @@ pub fn detect_media_type(path: &Path) -> MediaType {
|
|||||||
"so" | "dylib" => MediaType::Library,
|
"so" | "dylib" => MediaType::Library,
|
||||||
|
|
||||||
_ => MediaType::Unknown,
|
_ => MediaType::Unknown,
|
||||||
};
|
}
|
||||||
|
|
||||||
debug!(media_type = ?media_type, "Detected media type from extension");
|
|
||||||
media_type
|
|
||||||
} else {
|
} else {
|
||||||
debug!("No file extension found, returning Unknown");
|
|
||||||
MediaType::Unknown
|
MediaType::Unknown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(media_type))]
|
|
||||||
pub fn is_media_file(media_type: &MediaType) -> bool {
|
pub fn is_media_file(media_type: &MediaType) -> bool {
|
||||||
let is_media = matches!(
|
matches!(
|
||||||
media_type,
|
media_type,
|
||||||
MediaType::Audio | MediaType::Video | MediaType::Image
|
MediaType::Audio | MediaType::Video | MediaType::Image
|
||||||
);
|
)
|
||||||
|
|
||||||
debug!(media_type = ?media_type, is_media = is_media, "Checking if file is media type");
|
|
||||||
is_media
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use ts_rs::TS;
|
use ts_rs::TS;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, TS)]
|
#[derive(Serialize, Deserialize, Debug, Clone, TS)]
|
||||||
|
#[ts(export)]
|
||||||
pub enum MediaType {
|
pub enum MediaType {
|
||||||
Audio,
|
Audio,
|
||||||
Video,
|
Video,
|
||||||
@@ -14,6 +15,7 @@ pub enum MediaType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, TS)]
|
#[derive(Serialize, Deserialize, Debug, Clone, TS)]
|
||||||
|
#[ts(export)]
|
||||||
pub struct StreamResult {
|
pub struct StreamResult {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
pub filename: String,
|
pub filename: String,
|
||||||
@@ -24,6 +26,7 @@ pub struct StreamResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, TS)]
|
#[derive(Serialize, Deserialize, Debug, Clone, TS)]
|
||||||
|
#[ts(export)]
|
||||||
pub enum StreamDetail {
|
pub enum StreamDetail {
|
||||||
Video {
|
Video {
|
||||||
codec: String,
|
codec: String,
|
||||||
@@ -45,59 +48,9 @@ pub enum StreamDetail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, TS)]
|
#[derive(Serialize, Deserialize, Debug, Clone, TS)]
|
||||||
|
#[ts(export)]
|
||||||
pub struct StreamResultError {
|
pub struct StreamResultError {
|
||||||
pub filename: Option<String>,
|
pub filename: Option<String>,
|
||||||
pub reason: String,
|
pub reason: String,
|
||||||
pub error_type: String,
|
pub error_type: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
// New types for simplified drop overlay
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, TS)]
|
|
||||||
pub struct File {
|
|
||||||
pub filename: String,
|
|
||||||
pub size: u32,
|
|
||||||
pub candidacy: FileCandidacy,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, TS)]
|
|
||||||
pub enum FileCandidacy {
|
|
||||||
Success {
|
|
||||||
#[serde(rename = "type")]
|
|
||||||
file_type: MediaType,
|
|
||||||
},
|
|
||||||
Error {
|
|
||||||
reason: String,
|
|
||||||
},
|
|
||||||
Loading,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bitrate visualization types
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, TS)]
|
|
||||||
pub struct BitrateFrame {
|
|
||||||
pub frame_num: u32,
|
|
||||||
pub packet_size: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, TS)]
|
|
||||||
pub struct BitrateData {
|
|
||||||
pub id: String,
|
|
||||||
pub frames: Vec<BitrateFrame>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn export_bindings() {
|
|
||||||
// This will generate TypeScript bindings when you run `cargo test export_bindings`
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
StreamDetail::export_all_to("../src/bindings").expect("Failed to export bindings");
|
|
||||||
StreamResult::export_all_to("../src/bindings").expect("Failed to export bindings");
|
|
||||||
StreamResultError::export_all_to("../src/bindings").expect("Failed to export bindings");
|
|
||||||
MediaType::export_all_to("../src/bindings").expect("Failed to export bindings");
|
|
||||||
File::export_all_to("../src/bindings").expect("Failed to export bindings");
|
|
||||||
FileCandidacy::export_all_to("../src/bindings").expect("Failed to export bindings");
|
|
||||||
BitrateFrame::export_all_to("../src/bindings").expect("Failed to export bindings");
|
|
||||||
BitrateData::export_all_to("../src/bindings").expect("Failed to export bindings");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,122 +0,0 @@
|
|||||||
/// Transforms a filename to fit within a character limit while preserving the most useful context
|
|
||||||
///
|
|
||||||
/// This function prioritizes preserving:
|
|
||||||
/// 1. File extension (if reasonable length ≤ 5 chars including dot)
|
|
||||||
/// 2. Beginning of filename (for identification)
|
|
||||||
/// 3. End of filename before extension (often contains important info like numbers)
|
|
||||||
///
|
|
||||||
/// # Arguments
|
|
||||||
/// * `filename` - The filename to transform
|
|
||||||
/// * `limit` - Maximum number of characters
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
/// * Transformed filename that fits within the limit, using ellipsis (...) to indicate truncation
|
|
||||||
///
|
|
||||||
/// # Examples
|
|
||||||
/// ```
|
|
||||||
/// use byte_me_lib::strings::transform_filename;
|
|
||||||
///
|
|
||||||
/// // Short filenames remain unchanged
|
|
||||||
/// assert_eq!(transform_filename("test.mp4", 20), "test.mp4");
|
|
||||||
///
|
|
||||||
/// // Long filename with extension - preserve extension and context
|
|
||||||
/// assert_eq!(transform_filename("very_long_video_file_name.mp4", 18), "ver...ile_name.mp4");
|
|
||||||
///
|
|
||||||
/// // Numeric sequences - preserve start and end numbers
|
|
||||||
/// assert_eq!(transform_filename("43509374693.TS.mp4", 15), "435...93.TS.mp4");
|
|
||||||
///
|
|
||||||
/// // No extension - preserve start and end of name
|
|
||||||
/// assert_eq!(transform_filename("very_long_document_name", 15), "ver...ment_name");
|
|
||||||
///
|
|
||||||
/// // Long extension treated as part of name
|
|
||||||
/// assert_eq!(transform_filename("file.verylongextension", 15), "fil...extension");
|
|
||||||
/// ```
|
|
||||||
pub fn transform_filename(filename: &str, limit: usize) -> String {
|
|
||||||
// Handle edge cases
|
|
||||||
if limit == 0 || filename.is_empty() {
|
|
||||||
return String::new();
|
|
||||||
}
|
|
||||||
|
|
||||||
if filename.len() <= limit {
|
|
||||||
return filename.to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find potential extension (last dot, not at start or end)
|
|
||||||
let extension_start = filename
|
|
||||||
.rfind('.')
|
|
||||||
.filter(|&pos| pos > 0 && pos < filename.len() - 1);
|
|
||||||
|
|
||||||
let (name_part, extension_part) = if let Some(ext_pos) = extension_start {
|
|
||||||
let ext = &filename[ext_pos..];
|
|
||||||
// Only treat as extension if it's reasonable length (≤ 5 chars including dot)
|
|
||||||
// and doesn't contain additional dots (compound extensions like .TS.mp4)
|
|
||||||
if ext.len() <= 5 && !ext[1..].contains('.') {
|
|
||||||
(&filename[..ext_pos], ext)
|
|
||||||
} else {
|
|
||||||
(filename, "")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
(filename, "")
|
|
||||||
};
|
|
||||||
|
|
||||||
// If even just the extension is too long, truncate the whole thing
|
|
||||||
if extension_part.len() >= limit {
|
|
||||||
return truncate_string(filename, limit);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate space available for the name part
|
|
||||||
let name_limit = limit - extension_part.len();
|
|
||||||
|
|
||||||
// If name fits in available space, no truncation needed
|
|
||||||
if name_part.len() <= name_limit {
|
|
||||||
return filename.to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Need to truncate the name part
|
|
||||||
let truncated_name = truncate_string(name_part, name_limit);
|
|
||||||
format!("{}{}", truncated_name, extension_part)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Helper function to truncate a string with ellipsis, preserving start and end context
|
|
||||||
pub fn truncate_string(s: &str, limit: usize) -> String {
|
|
||||||
if s.len() <= limit {
|
|
||||||
return s.to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
// For very small limits, just truncate without ellipsis
|
|
||||||
if limit < 5 {
|
|
||||||
return s.chars().take(limit).collect();
|
|
||||||
}
|
|
||||||
|
|
||||||
// For limits 5 and above, use start + "..." + end pattern
|
|
||||||
// Strategy: Use 3 chars for ellipsis, split remaining between start and end
|
|
||||||
// But ensure we get meaningful chunks from both ends
|
|
||||||
|
|
||||||
let available_for_content = limit - 3; // Reserve 3 for "..."
|
|
||||||
|
|
||||||
// Determine start and end characters based on available space
|
|
||||||
let (start_chars, end_chars) = if available_for_content <= 4 {
|
|
||||||
// Very limited space: minimal start, rest for end
|
|
||||||
(1, available_for_content - 1)
|
|
||||||
} else if available_for_content <= 6 {
|
|
||||||
// Medium space: balanced approach
|
|
||||||
let start = available_for_content / 2;
|
|
||||||
(start, available_for_content - start)
|
|
||||||
} else {
|
|
||||||
// Plenty of space: cap start at 3, use more for end to preserve context
|
|
||||||
let start = 3;
|
|
||||||
(start, available_for_content - start)
|
|
||||||
};
|
|
||||||
|
|
||||||
let start: String = s.chars().take(start_chars).collect();
|
|
||||||
let end: String = s
|
|
||||||
.chars()
|
|
||||||
.rev()
|
|
||||||
.take(end_chars)
|
|
||||||
.collect::<String>()
|
|
||||||
.chars()
|
|
||||||
.rev()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
format!("{}...{}", start, end)
|
|
||||||
}
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
use byte_me_lib::strings::{transform_filename, truncate_string};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_transform_filename() {
|
|
||||||
// Test cases focusing on practical, readable outputs
|
|
||||||
|
|
||||||
// 1. Short filenames should remain unchanged
|
|
||||||
assert_eq!(transform_filename("test.mp4", 20), "test.mp4");
|
|
||||||
assert_eq!(transform_filename("short.txt", 15), "short.txt");
|
|
||||||
assert_eq!(transform_filename("a.b", 10), "a.b");
|
|
||||||
|
|
||||||
// 2. No extension cases - preserve meaningful start and end
|
|
||||||
assert_eq!(transform_filename("short_name", 15), "short_name");
|
|
||||||
assert_eq!(
|
|
||||||
transform_filename("very_long_document_name", 15),
|
|
||||||
"ver...ment_name"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
transform_filename("medium_length_name", 13),
|
|
||||||
"med...th_name"
|
|
||||||
);
|
|
||||||
|
|
||||||
// 3. Normal extension cases (preserving extension)
|
|
||||||
assert_eq!(
|
|
||||||
transform_filename("very_long_video_file_name.mp4", 18),
|
|
||||||
"ver...ile_name.mp4"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
transform_filename("document_with_long_name.pdf", 15),
|
|
||||||
"doc..._name.pdf"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
transform_filename("image_file_name.jpeg", 15),
|
|
||||||
"ima...name.jpeg"
|
|
||||||
);
|
|
||||||
|
|
||||||
// 4. Numeric sequences (like user's example) - preserve start and end numbers
|
|
||||||
assert_eq!(
|
|
||||||
transform_filename("43509374693.TS.mp4", 15),
|
|
||||||
"435...93.TS.mp4"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
transform_filename("20231201_video.mp4", 15),
|
|
||||||
"202...video.mp4"
|
|
||||||
);
|
|
||||||
assert_eq!(transform_filename("file_v2.1.3.tar", 12), "fi...1.3.tar");
|
|
||||||
|
|
||||||
// 5. Long extensions (treated as part of filename)
|
|
||||||
assert_eq!(
|
|
||||||
transform_filename("file.verylongextension", 15),
|
|
||||||
"fil...extension"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
transform_filename("document.backup_old", 15),
|
|
||||||
"doc...ackup_old"
|
|
||||||
);
|
|
||||||
|
|
||||||
// 6. Edge cases
|
|
||||||
assert_eq!(transform_filename("", 10), "");
|
|
||||||
assert_eq!(transform_filename("a", 0), "");
|
|
||||||
assert_eq!(transform_filename("test", 4), "test");
|
|
||||||
assert_eq!(transform_filename("test", 3), "tes");
|
|
||||||
assert_eq!(transform_filename("ab", 2), "ab");
|
|
||||||
|
|
||||||
// 7. Very short limits - graceful degradation
|
|
||||||
assert_eq!(transform_filename("test.mp4", 8), "test.mp4");
|
|
||||||
assert_eq!(transform_filename("verylongname", 8), "ve...ame");
|
|
||||||
assert_eq!(transform_filename("test.mp4", 7), "tes.mp4");
|
|
||||||
assert_eq!(transform_filename("hello.txt", 9), "hello.txt");
|
|
||||||
|
|
||||||
// 8. Extension edge cases
|
|
||||||
assert_eq!(transform_filename("file.", 10), "file.");
|
|
||||||
assert_eq!(transform_filename(".hidden", 10), ".hidden");
|
|
||||||
assert_eq!(transform_filename("test.a", 10), "test.a");
|
|
||||||
|
|
||||||
// 9. Real-world examples
|
|
||||||
assert_eq!(
|
|
||||||
transform_filename("IMG_20231201_143022.jpg", 15),
|
|
||||||
"IMG...43022.jpg"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
transform_filename("meeting_recording_final_v2.mp4", 20),
|
|
||||||
"mee...g_final_v2.mp4"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
transform_filename("my document (copy).docx", 15),
|
|
||||||
"my ...opy).docx"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_truncate_string() {
|
|
||||||
// Test the helper function directly
|
|
||||||
assert_eq!(truncate_string("hello", 10), "hello");
|
|
||||||
assert_eq!(truncate_string("hello", 5), "hello");
|
|
||||||
assert_eq!(truncate_string("hello_world", 8), "he...rld");
|
|
||||||
assert_eq!(truncate_string("test", 4), "test");
|
|
||||||
assert_eq!(truncate_string("test", 3), "tes");
|
|
||||||
assert_eq!(truncate_string("ab", 2), "ab");
|
|
||||||
assert_eq!(truncate_string("a", 1), "a");
|
|
||||||
assert_eq!(truncate_string("hello", 1), "h");
|
|
||||||
assert_eq!(truncate_string("hello", 0), "");
|
|
||||||
assert_eq!(truncate_string("very_long_name", 10), "ver...name");
|
|
||||||
assert_eq!(truncate_string("document_name", 9), "doc...ame");
|
|
||||||
}
|
|
||||||
49
src/App.tsx
49
src/App.tsx
@@ -1,45 +1,13 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useDragDropPaths } from "./hooks/useDragDropPaths.js";
|
||||||
import { useDragDropPaths } from "@/hooks/useDragDropPaths";
|
import Graph from "./features/graph/graph.js";
|
||||||
import Graph from "@/components/graph";
|
import DropOverlay from "./features/drop/drop-overlay.js";
|
||||||
import DropOverlay from "@/components/drop-overlay";
|
import type { Frame } from "./types/graph.js";
|
||||||
import type { Frame } from "@/types/graph";
|
|
||||||
import { commands } from "@/bindings";
|
|
||||||
import type { BitrateData } from "@/bindings";
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [data, setData] = useState<Frame[]>([]);
|
const data: Frame[] = [];
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const paths = useDragDropPaths();
|
const paths = useDragDropPaths();
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (paths.length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For minimal prototype, just process the first file
|
|
||||||
const firstPath = paths[0];
|
|
||||||
setIsLoading(true);
|
|
||||||
|
|
||||||
commands
|
|
||||||
.extractBitrateData(firstPath)
|
|
||||||
.then((bitrateData: BitrateData) => {
|
|
||||||
// Transform BitrateData to Nivo's Frame format
|
|
||||||
const frame: Frame = {
|
|
||||||
id: bitrateData.id,
|
|
||||||
data: bitrateData.frames.map((frame) => ({
|
|
||||||
x: frame.frame_num,
|
|
||||||
y: Number(frame.packet_size),
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
setData([frame]);
|
|
||||||
setIsLoading(false);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error("Failed to extract bitrate data:", error);
|
|
||||||
setIsLoading(false);
|
|
||||||
});
|
|
||||||
}, [paths]);
|
|
||||||
|
|
||||||
const graph = <Graph data={data} />;
|
const graph = <Graph data={data} />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -49,11 +17,6 @@ function App() {
|
|||||||
style={{ "--wails-drop-target": "drop" } as React.CSSProperties}
|
style={{ "--wails-drop-target": "drop" } as React.CSSProperties}
|
||||||
>
|
>
|
||||||
<DropOverlay paths={paths} />
|
<DropOverlay paths={paths} />
|
||||||
{isLoading && (
|
|
||||||
<div className="absolute z-20 top-4 right-4 text-white bg-blue-600 px-4 py-2 rounded-lg">
|
|
||||||
Extracting bitrate data...
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{graph}
|
{graph}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
// Import generated TypeScript types from ts-rs
|
// Import generated TypeScript types from ts-rs
|
||||||
import type { StreamResult } from "@/bindings/StreamResult";
|
import type { StreamResult } from "./bindings/StreamResult";
|
||||||
import type { StreamDetail } from "@/bindings/StreamDetail";
|
import type { StreamDetail } from "./bindings/StreamDetail";
|
||||||
import type { StreamResultError } from "@/bindings/StreamResultError";
|
import type { StreamResultError } from "./bindings/StreamResultError";
|
||||||
import type { MediaType } from "@/bindings/MediaType";
|
import type { MediaType } from "./bindings/MediaType";
|
||||||
import type { File } from "@/bindings/File";
|
export type { StreamResult, StreamDetail, StreamResultError, MediaType };
|
||||||
import type { FileCandidacy } from "@/bindings/FileCandidacy";
|
|
||||||
import type { BitrateData } from "@/bindings/BitrateData";
|
|
||||||
import type { BitrateFrame } from "@/bindings/BitrateFrame";
|
|
||||||
export type { StreamResult, StreamDetail, StreamResultError, MediaType, File, FileCandidacy, BitrateData, BitrateFrame };
|
|
||||||
|
|
||||||
// Tauri invoke wrapper
|
// Tauri invoke wrapper
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
@@ -25,13 +21,5 @@ export const commands = {
|
|||||||
if (e instanceof Error) throw e;
|
if (e instanceof Error) throw e;
|
||||||
else return { status: "error", error: e as any };
|
else return { status: "error", error: e as any };
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
async analyzeFiles(paths: string[]): Promise<File[]> {
|
|
||||||
return await invoke<File[]>("analyze_files", { paths });
|
|
||||||
},
|
|
||||||
|
|
||||||
async extractBitrateData(path: string): Promise<BitrateData> {
|
|
||||||
return await invoke<BitrateData>("extract_bitrate_data", { path });
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,196 +0,0 @@
|
|||||||
import { type ReactNode, useEffect, useState } from "react";
|
|
||||||
import { match, P } from "ts-pattern";
|
|
||||||
import {
|
|
||||||
File as FileIcon,
|
|
||||||
FileText,
|
|
||||||
Film,
|
|
||||||
Image,
|
|
||||||
Loader2,
|
|
||||||
Music,
|
|
||||||
XCircle,
|
|
||||||
} from "lucide-react";
|
|
||||||
import { commands } from "@/bindings";
|
|
||||||
import type { File, FileCandidacy, MediaType } from "@/bindings";
|
|
||||||
|
|
||||||
type DropOverlayProps = {
|
|
||||||
paths: string[];
|
|
||||||
};
|
|
||||||
|
|
||||||
const formatFileSize = (bytes: number): string => {
|
|
||||||
if (bytes === 0) return "0 B";
|
|
||||||
const k = 1024;
|
|
||||||
const sizes = ["B", "KB", "MB", "GB"];
|
|
||||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
||||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
|
|
||||||
};
|
|
||||||
|
|
||||||
const getFileIcon = (candidacy: FileCandidacy): ReactNode => {
|
|
||||||
return match(candidacy)
|
|
||||||
.with("Loading", () => (
|
|
||||||
<Loader2 className="w-5 h-5 text-blue-400 animate-spin" />
|
|
||||||
))
|
|
||||||
.with({ Error: P._ }, () => <XCircle className="w-5 h-5 text-red-400" />)
|
|
||||||
.with({ Success: { type: P.select() } }, (mediaType: MediaType) => {
|
|
||||||
switch (mediaType) {
|
|
||||||
case "Audio":
|
|
||||||
return <Music className="w-5 h-5 text-blue-400" />;
|
|
||||||
case "Video":
|
|
||||||
return <Film className="w-5 h-5 text-purple-400" />;
|
|
||||||
case "Image":
|
|
||||||
return <Image className="w-5 h-5 text-pink-400" />;
|
|
||||||
case "Document":
|
|
||||||
return <FileText className="w-5 h-5 text-green-400" />;
|
|
||||||
case "Executable":
|
|
||||||
return <FileIcon className="w-5 h-5 text-orange-400" />;
|
|
||||||
case "Archive":
|
|
||||||
return <FileIcon className="w-5 h-5 text-yellow-400" />;
|
|
||||||
case "Library":
|
|
||||||
return <FileIcon className="w-5 h-5 text-indigo-400" />;
|
|
||||||
default:
|
|
||||||
return <FileIcon className="w-5 h-5 text-neutral-300" />;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.exhaustive();
|
|
||||||
};
|
|
||||||
|
|
||||||
const getStatusColor = (candidacy: FileCandidacy): string => {
|
|
||||||
return match(candidacy)
|
|
||||||
.with("Loading", () => "border-blue-500/50")
|
|
||||||
.with({ Error: P._ }, () => "border-red-500/50")
|
|
||||||
.with({ Success: P._ }, () => "border-green-500/50")
|
|
||||||
.exhaustive();
|
|
||||||
};
|
|
||||||
|
|
||||||
const FileItem = ({ file }: { file: File }) => {
|
|
||||||
const icon = getFileIcon(file.candidacy);
|
|
||||||
const statusColor = getStatusColor(file.candidacy);
|
|
||||||
const fileSize = formatFileSize(file.size);
|
|
||||||
|
|
||||||
const subtitle = match(file.candidacy)
|
|
||||||
.with("Loading", () => "Analyzing...")
|
|
||||||
.with({ Error: { reason: P.select() } }, (reason: string) => reason)
|
|
||||||
.with({ Success: { type: P.select() } }, (mediaType: MediaType) => {
|
|
||||||
switch (mediaType) {
|
|
||||||
case "Audio":
|
|
||||||
return "Audio file";
|
|
||||||
case "Video":
|
|
||||||
return "Video file";
|
|
||||||
case "Image":
|
|
||||||
return "Image file";
|
|
||||||
case "Document":
|
|
||||||
return "Document file";
|
|
||||||
case "Executable":
|
|
||||||
return "Executable file";
|
|
||||||
case "Archive":
|
|
||||||
return "Archive file";
|
|
||||||
case "Library":
|
|
||||||
return "Library file";
|
|
||||||
default:
|
|
||||||
return "Unknown file type";
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.exhaustive();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={`flex items-center gap-3 px-4 py-3 rounded-lg bg-neutral-800 border ${statusColor} transition-all duration-200`}
|
|
||||||
style={{
|
|
||||||
maxWidth: "100%",
|
|
||||||
marginBottom: "0.75rem",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{icon}
|
|
||||||
<div className="flex-1 min-w-0">
|
|
||||||
<div className="truncate text-neutral-100 font-medium">
|
|
||||||
{file.filename}
|
|
||||||
</div>
|
|
||||||
<div className="truncate text-neutral-400 text-sm mt-1">
|
|
||||||
{fileSize} • {subtitle}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const DropOverlay = ({ paths }: DropOverlayProps) => {
|
|
||||||
const [files, setFiles] = useState<File[]>([]);
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (paths.length === 0) {
|
|
||||||
setFiles([]);
|
|
||||||
setIsLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsLoading(true);
|
|
||||||
setFiles([]);
|
|
||||||
|
|
||||||
// Initialize with loading state for all files
|
|
||||||
const loadingFiles: File[] = paths.map((path) => {
|
|
||||||
const filename = path.split(/[/\\]/).pop() || "unknown";
|
|
||||||
return {
|
|
||||||
filename,
|
|
||||||
size: 0,
|
|
||||||
candidacy: "Loading" as const,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
setFiles(loadingFiles);
|
|
||||||
|
|
||||||
// Analyze files
|
|
||||||
commands
|
|
||||||
.analyzeFiles(paths)
|
|
||||||
.then((analyzedFiles) => {
|
|
||||||
setFiles(analyzedFiles);
|
|
||||||
setIsLoading(false);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error("Failed to analyze files:", error);
|
|
||||||
// Set all files to error state
|
|
||||||
const errorFiles: File[] = paths.map((path) => {
|
|
||||||
const filename = path.split(/[/\\]/).pop() || "unknown";
|
|
||||||
return {
|
|
||||||
filename,
|
|
||||||
size: 0,
|
|
||||||
candidacy: {
|
|
||||||
Error: {
|
|
||||||
reason: "Failed to analyze file",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
|
||||||
setFiles(errorFiles);
|
|
||||||
setIsLoading(false);
|
|
||||||
});
|
|
||||||
}, [paths]);
|
|
||||||
|
|
||||||
if (files.length === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="absolute z-10 top-0 left-0 w-full h-full backdrop-blur-[1px] backdrop-saturate-0 transition-all duration-300 ease-in-out">
|
|
||||||
<div className="flex flex-col justify-center items-center h-full p-8">
|
|
||||||
<div className="rounded-xl p-6 max-w-2xl w-full">
|
|
||||||
<div className="flex flex-col items-center gap-4">
|
|
||||||
{isLoading && (
|
|
||||||
<div className="flex items-center gap-2 text-blue-400 mb-4">
|
|
||||||
<Loader2 className="w-6 h-6 animate-spin" />
|
|
||||||
<span className="text-lg font-medium">
|
|
||||||
Analyzing {files.length} file{files.length > 1 ? "s" : ""}...
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div className="max-h-96 overflow-y-auto w-full">
|
|
||||||
{files.map((file, index) => (
|
|
||||||
<FileItem key={`${file.filename}-${index}`} file={file} />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default DropOverlay;
|
|
||||||
381
src/features/drop/drop-overlay.tsx
Normal file
381
src/features/drop/drop-overlay.tsx
Normal file
@@ -0,0 +1,381 @@
|
|||||||
|
import { ReactNode, useEffect, useRef, useState } from "react";
|
||||||
|
import { match, P } from "ts-pattern";
|
||||||
|
import {
|
||||||
|
CheckCircle,
|
||||||
|
File as FileIcon,
|
||||||
|
FileText,
|
||||||
|
Film,
|
||||||
|
Image,
|
||||||
|
Loader2,
|
||||||
|
Music,
|
||||||
|
XCircle,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { commands } from "../../bindings";
|
||||||
|
import type { MediaType, StreamDetail } from "../../bindings";
|
||||||
|
|
||||||
|
type DropOverlayProps = {
|
||||||
|
paths: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
type State =
|
||||||
|
| { status: "hidden" }
|
||||||
|
| { status: "loading"; count: number }
|
||||||
|
| {
|
||||||
|
status: "ready";
|
||||||
|
files: {
|
||||||
|
name: string;
|
||||||
|
key: string;
|
||||||
|
media_type: MediaType;
|
||||||
|
duration?: number | null;
|
||||||
|
size: number;
|
||||||
|
streams: StreamDetail[];
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
| { status: "error"; reason: string; filename?: string; error_type?: string };
|
||||||
|
|
||||||
|
type FileItemProps = {
|
||||||
|
filename: string;
|
||||||
|
media_type: MediaType;
|
||||||
|
duration?: number | null;
|
||||||
|
size: number;
|
||||||
|
streams: StreamDetail[];
|
||||||
|
error?: string;
|
||||||
|
error_type?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatFileSize = (bytes: number): string => {
|
||||||
|
if (bytes === 0) return "0 B";
|
||||||
|
const k = 1024;
|
||||||
|
const sizes = ["B", "KB", "MB", "GB"];
|
||||||
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||||
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatDuration = (seconds: number): string => {
|
||||||
|
const hours = Math.floor(seconds / 3600);
|
||||||
|
const minutes = Math.floor((seconds % 3600) / 60);
|
||||||
|
const secs = Math.floor(seconds % 60);
|
||||||
|
|
||||||
|
if (hours > 0) {
|
||||||
|
return `${hours}:${minutes.toString().padStart(2, "0")}:${secs
|
||||||
|
.toString()
|
||||||
|
.padStart(2, "0")}`;
|
||||||
|
}
|
||||||
|
return `${minutes}:${secs.toString().padStart(2, "0")}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getFileIcon = (
|
||||||
|
mediaType: MediaType,
|
||||||
|
error?: string,
|
||||||
|
errorType?: string,
|
||||||
|
) => {
|
||||||
|
// For non-media files, show a neutral icon instead of error icon
|
||||||
|
if (errorType === "not_media") {
|
||||||
|
switch (mediaType) {
|
||||||
|
case "Executable":
|
||||||
|
return <FileIcon className="w-5 h-5 text-orange-400" />;
|
||||||
|
case "Archive":
|
||||||
|
return <FileIcon className="w-5 h-5 text-yellow-400" />;
|
||||||
|
case "Library":
|
||||||
|
return <FileIcon className="w-5 h-5 text-indigo-400" />;
|
||||||
|
case "Document":
|
||||||
|
return <FileText className="w-5 h-5 text-green-400" />;
|
||||||
|
default:
|
||||||
|
return <FileIcon className="w-5 h-5 text-neutral-300" />;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return <XCircle className="w-5 h-5 text-red-400" />;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (mediaType) {
|
||||||
|
case "Audio":
|
||||||
|
return <Music className="w-5 h-5 text-blue-400" />;
|
||||||
|
case "Video":
|
||||||
|
return <Film className="w-5 h-5 text-purple-400" />;
|
||||||
|
case "Image":
|
||||||
|
return <Image className="w-5 h-5 text-pink-400" />;
|
||||||
|
case "Document":
|
||||||
|
return <FileText className="w-5 h-5 text-green-400" />;
|
||||||
|
case "Executable":
|
||||||
|
return <FileIcon className="w-5 h-5 text-orange-400" />;
|
||||||
|
case "Archive":
|
||||||
|
return <FileIcon className="w-5 h-5 text-yellow-400" />;
|
||||||
|
case "Library":
|
||||||
|
return <FileIcon className="w-5 h-5 text-indigo-400" />;
|
||||||
|
default:
|
||||||
|
return <FileIcon className="w-5 h-5 text-neutral-300" />;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getStreamInfo = (
|
||||||
|
streams: StreamDetail[],
|
||||||
|
mediaType: MediaType,
|
||||||
|
): string => {
|
||||||
|
// For non-media files, return file type description
|
||||||
|
if (!["Audio", "Video", "Image"].includes(mediaType)) {
|
||||||
|
switch (mediaType) {
|
||||||
|
case "Executable":
|
||||||
|
return "Executable file";
|
||||||
|
case "Archive":
|
||||||
|
return "Archive file";
|
||||||
|
case "Library":
|
||||||
|
return "Library file";
|
||||||
|
case "Document":
|
||||||
|
return "Document file";
|
||||||
|
default:
|
||||||
|
return "Unknown file type";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// For media files, analyze streams
|
||||||
|
const videoStreams = streams.filter((s: any) => "Video" in s);
|
||||||
|
const audioStreams = streams.filter((s: any) => "Audio" in s);
|
||||||
|
const subtitleStreams = streams.filter((s: any) => "Subtitle" in s);
|
||||||
|
|
||||||
|
const parts = [] as string[];
|
||||||
|
if (videoStreams.length > 0) {
|
||||||
|
const video: any = videoStreams[0] as any;
|
||||||
|
if ("Video" in video) {
|
||||||
|
const width = (video as any).Video.width;
|
||||||
|
const height = (video as any).Video.height;
|
||||||
|
const codec = (video as any).Video.codec;
|
||||||
|
if (width && height) {
|
||||||
|
parts.push(`${width}x${height} ${codec}`);
|
||||||
|
} else {
|
||||||
|
parts.push(codec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (audioStreams.length > 0) {
|
||||||
|
const audio: any = audioStreams[0] as any;
|
||||||
|
if ("Audio" in audio) {
|
||||||
|
parts.push(`${(audio as any).Audio.codec} audio`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (subtitleStreams.length > 0) {
|
||||||
|
parts.push(`${subtitleStreams.length} subtitle(s)`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parts.join(", ");
|
||||||
|
};
|
||||||
|
|
||||||
|
const Item = ({
|
||||||
|
icon,
|
||||||
|
text,
|
||||||
|
subtitle,
|
||||||
|
status,
|
||||||
|
}: {
|
||||||
|
icon: ReactNode;
|
||||||
|
text: ReactNode;
|
||||||
|
subtitle?: ReactNode;
|
||||||
|
status?: "success" | "error" | "loading";
|
||||||
|
}) => {
|
||||||
|
const statusColor =
|
||||||
|
status === "success"
|
||||||
|
? "border-green-500"
|
||||||
|
: status === "error"
|
||||||
|
? "border-red-500"
|
||||||
|
: status === "loading"
|
||||||
|
? "border-blue-500"
|
||||||
|
: "border-neutral-600";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`flex items-center gap-3 px-4 py-3 bg-neutral-800 rounded-lg shadow-lg border-2 ${statusColor} transition-all duration-200`}
|
||||||
|
style={{
|
||||||
|
maxWidth: "100%",
|
||||||
|
marginBottom: "0.75rem",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{icon}
|
||||||
|
<div className="flex-1 min-w-0">
|
||||||
|
<div className="truncate text-neutral-100 font-medium">{text}</div>
|
||||||
|
{subtitle && (
|
||||||
|
<div className="truncate text-neutral-400 text-sm mt-1">
|
||||||
|
{subtitle}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const FileItem = ({
|
||||||
|
filename,
|
||||||
|
media_type,
|
||||||
|
duration,
|
||||||
|
size,
|
||||||
|
streams,
|
||||||
|
error,
|
||||||
|
error_type,
|
||||||
|
}: FileItemProps) => {
|
||||||
|
const icon = getFileIcon(media_type, error, error_type);
|
||||||
|
const fileSize = formatFileSize(size);
|
||||||
|
|
||||||
|
let subtitle: ReactNode;
|
||||||
|
let status: "success" | "error" | "loading" | undefined;
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
subtitle = error;
|
||||||
|
// For non-media files, show as neutral instead of error
|
||||||
|
status = error_type === "not_media" ? undefined : "error";
|
||||||
|
} else {
|
||||||
|
const streamInfo = getStreamInfo(streams, media_type);
|
||||||
|
const durationStr = duration ? formatDuration(duration) : null;
|
||||||
|
const details = [streamInfo, durationStr, fileSize].filter(
|
||||||
|
Boolean,
|
||||||
|
) as string[];
|
||||||
|
subtitle = details.join(" • ");
|
||||||
|
status = "success";
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Item icon={icon} text={filename} subtitle={subtitle} status={status} />
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const DropOverlay = ({ paths }: DropOverlayProps) => {
|
||||||
|
const [state, setState] = useState<State>({ status: "hidden" });
|
||||||
|
const aborterRef = useRef<AbortController | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (paths.length === 0) {
|
||||||
|
setState({ status: "hidden" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setState({ status: "loading", count: paths.length });
|
||||||
|
|
||||||
|
aborterRef.current = new AbortController();
|
||||||
|
|
||||||
|
commands.hasStreams(paths).then((result) => {
|
||||||
|
setState((_state) => {
|
||||||
|
return match(result)
|
||||||
|
.with({ status: "ok" }, (r) => ({
|
||||||
|
status: "ready" as const,
|
||||||
|
files: r.data.map((item) => ({
|
||||||
|
name: item.filename,
|
||||||
|
key: item.path,
|
||||||
|
media_type: item.media_type,
|
||||||
|
duration: item.duration,
|
||||||
|
size: Number(item.size),
|
||||||
|
streams: item.streams,
|
||||||
|
})),
|
||||||
|
}))
|
||||||
|
.with({ status: "error" }, (r) => {
|
||||||
|
if (r.error.filename) {
|
||||||
|
return {
|
||||||
|
status: "error" as const,
|
||||||
|
reason: r.error.reason,
|
||||||
|
filename: r.error.filename,
|
||||||
|
error_type: r.error.error_type,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: "error" as const,
|
||||||
|
reason: r.error.reason,
|
||||||
|
error_type: r.error.error_type,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.exhaustive();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, [paths]);
|
||||||
|
|
||||||
|
if (state.status === "hidden") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const inner = match(state)
|
||||||
|
.with({ status: "loading" }, ({ count }) => (
|
||||||
|
<div className="flex flex-col items-center gap-4">
|
||||||
|
<Loader2 className="w-8 h-8 text-blue-400 animate-spin" />
|
||||||
|
<div className="text-white text-lg font-medium">
|
||||||
|
Analyzing {count} file{count > 1 ? "s" : ""}...
|
||||||
|
</div>
|
||||||
|
{Array.from({ length: Math.min(count, 3) }).map((_, i) => (
|
||||||
|
<Item
|
||||||
|
key={i}
|
||||||
|
icon={
|
||||||
|
<Loader2 className="w-5 h-5 text-neutral-300/50 animate-spin" />
|
||||||
|
}
|
||||||
|
text={
|
||||||
|
<span className="inline-block w-32 h-5 bg-neutral-300/10 rounded animate-pulse" />
|
||||||
|
}
|
||||||
|
status="loading"
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
.with({ status: "ready" }, (r) => {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col items-center gap-4">
|
||||||
|
<div className="flex items-center gap-2 text-green-400">
|
||||||
|
<CheckCircle className="w-6 h-6" />
|
||||||
|
<span className="text-lg font-medium">Files Ready</span>
|
||||||
|
</div>
|
||||||
|
<div className="max-h-96 overflow-y-auto">
|
||||||
|
{r.files.slice(0, 8).map((file) => (
|
||||||
|
<FileItem
|
||||||
|
key={file.key}
|
||||||
|
filename={file.name}
|
||||||
|
media_type={file.media_type}
|
||||||
|
duration={file.duration}
|
||||||
|
size={file.size}
|
||||||
|
streams={file.streams}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.with({ status: "error", filename: P.string }, (r) => {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col items-center gap-4">
|
||||||
|
<div className="flex items-center gap-2 text-red-400">
|
||||||
|
<XCircle className="w-6 h-6" />
|
||||||
|
<span className="text-lg font-medium">Error</span>
|
||||||
|
</div>
|
||||||
|
<FileItem
|
||||||
|
filename={r.filename}
|
||||||
|
media_type="Unknown"
|
||||||
|
size={0}
|
||||||
|
streams={[]}
|
||||||
|
error={r.reason}
|
||||||
|
error_type={r.error_type}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.with({ status: "error" }, ({ reason }) => {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col items-center gap-4">
|
||||||
|
<div className="flex items-center gap-2 text-red-400">
|
||||||
|
<XCircle className="w-6 h-6" />
|
||||||
|
<span className="text-lg font-medium">Error</span>
|
||||||
|
</div>
|
||||||
|
<Item
|
||||||
|
icon={<XCircle className="w-5 h-5 text-red-400" />}
|
||||||
|
text={reason}
|
||||||
|
status="error"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.exhaustive();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="absolute z-10 top-0 left-0 w-full h-full bg-black/60 backdrop-blur-sm transition-all duration-300 ease-in-out">
|
||||||
|
<div className="flex flex-col justify-center items-center h-full p-8">
|
||||||
|
<div className="bg-neutral-900 rounded-xl p-6 shadow-2xl max-w-2xl w-full">
|
||||||
|
{inner}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DropOverlay;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { ResponsiveLine } from "@nivo/line";
|
import { ResponsiveLine } from "@nivo/line";
|
||||||
import { formatBytes } from "@/lib/format";
|
import { formatBytes } from "../../lib/format.js";
|
||||||
import type { Frame } from "@/types/graph";
|
import type { Frame } from "../../types/graph.js";
|
||||||
|
|
||||||
type GraphProps = {
|
type GraphProps = {
|
||||||
data: Frame[];
|
data: Frame[];
|
||||||
@@ -51,11 +51,11 @@ const Graph = ({ data }: GraphProps) => (
|
|||||||
fill: "#6e6a86",
|
fill: "#6e6a86",
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
axisBottom={{ legend: "Frame Number", legendOffset: 36 }}
|
axisBottom={{ legend: "transportation", legendOffset: 36 }}
|
||||||
axisLeft={{
|
axisLeft={{
|
||||||
legend: "Packet Size",
|
legend: "count",
|
||||||
legendOffset: -40,
|
legendOffset: -40,
|
||||||
format: (v) => formatBytes(v),
|
format: (v) => formatBytes(v * 1024 * 53),
|
||||||
}}
|
}}
|
||||||
pointSize={10}
|
pointSize={10}
|
||||||
colors={["#3e8faf", "#c4a7e7", "#f5c276", "#EA9B96", "#EB7092", "#9CCFD8"]}
|
colors={["#3e8faf", "#c4a7e7", "#f5c276", "#EA9B96", "#EB7092", "#9CCFD8"]}
|
||||||
@@ -7,13 +7,14 @@ export function useDragDropPaths(): string[] {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const unlistenPromise = getCurrentWebview().onDragDropEvent(
|
const unlistenPromise = getCurrentWebview().onDragDropEvent(
|
||||||
async ({ payload }) => {
|
async ({ payload }) => {
|
||||||
if (payload.type === "drop") {
|
if (payload.type === "enter") {
|
||||||
setPaths(payload.paths);
|
setPaths(payload.paths);
|
||||||
} else if (payload.type === "leave") {
|
} else if (payload.type === "leave" || payload.type === "drop") {
|
||||||
setPaths([]);
|
setPaths([]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
unlistenPromise.then((unlisten) => unlisten());
|
unlistenPromise.then((unlisten) => unlisten());
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { formatBytes } from "@/lib/format";
|
import { formatBytes } from "./format.js";
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
|
|
||||||
test("formats bytes less than 1024", () => {
|
test("formats bytes less than 1024", () => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import ReactDOM from "react-dom/client";
|
import ReactDOM from "react-dom/client";
|
||||||
import App from "@/App";
|
import App from "./App";
|
||||||
import "@/global.css";
|
import "./global.css";
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
|
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
|
|||||||
@@ -1,10 +1,25 @@
|
|||||||
{
|
{
|
||||||
"extends": "@tsconfig/vite-react/tsconfig.json",
|
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
/* Paths */
|
"target": "ES2020",
|
||||||
"paths": {
|
"useDefineForClassFields": true,
|
||||||
"@/*": ["./src/*"]
|
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||||
}
|
"module": "ESNext",
|
||||||
|
"skipLibCheck": true,
|
||||||
|
|
||||||
|
/* Bundler mode */
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"noEmit": true,
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
|
||||||
|
/* Linting */
|
||||||
|
"strict": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"noFallthroughCasesInSwitch": true
|
||||||
},
|
},
|
||||||
"include": ["src"]
|
"include": ["src"],
|
||||||
|
"references": [{ "path": "./tsconfig.node.json" }]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,13 @@
|
|||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import react from "@vitejs/plugin-react";
|
import react from "@vitejs/plugin-react";
|
||||||
import tailwindcss from "@tailwindcss/vite";
|
import tailwindcss from "@tailwindcss/vite";
|
||||||
import path from "path";
|
|
||||||
|
|
||||||
|
// @ts-expect-error process is a nodejs global
|
||||||
const host = process.env.TAURI_DEV_HOST;
|
const host = process.env.TAURI_DEV_HOST;
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig(async () => ({
|
export default defineConfig(async () => ({
|
||||||
plugins: [react(), tailwindcss()],
|
plugins: [react(), tailwindcss()],
|
||||||
resolve: {
|
|
||||||
alias: {
|
|
||||||
"@": path.resolve(__dirname, "src"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
|
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user