mirror of
https://github.com/LLukas22/Jellyswarrm.git
synced 2025-12-23 22:47:47 -05:00
Show ui version
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
/ui/dist
|
||||
|
||||
# Git
|
||||
.git
|
||||
.gitignore
|
||||
.gitattributes
|
||||
|
||||
|
||||
23
Dockerfile
23
Dockerfile
@@ -3,10 +3,10 @@
|
||||
#################################
|
||||
FROM node:20-alpine AS ui-build
|
||||
|
||||
WORKDIR /app/ui
|
||||
# Install git for version detection
|
||||
RUN apk add --no-cache git
|
||||
|
||||
# Copy UI version file to detect changes
|
||||
COPY ui-version.env ./
|
||||
WORKDIR /app/ui
|
||||
|
||||
# Copy package files for dependency caching
|
||||
COPY ui/package.json ui/package-lock.json* ./
|
||||
@@ -15,12 +15,27 @@ COPY ui/package.json ui/package-lock.json* ./
|
||||
RUN --mount=type=cache,target=/root/.npm \
|
||||
npm install --engine-strict=false --ignore-scripts
|
||||
|
||||
# Copy UI source code
|
||||
# Copy UI source code and git metadata
|
||||
COPY ui/ ./
|
||||
COPY .git/modules/ui/ /app/.git/modules/ui/
|
||||
|
||||
# Get and print UI version info
|
||||
RUN UI_VERSION=$(git describe --tags) && \
|
||||
UI_COMMIT=$(git rev-parse HEAD) && \
|
||||
echo "UI_VERSION=$UI_VERSION" && \
|
||||
echo "UI_COMMIT=$UI_COMMIT"
|
||||
|
||||
# Build production UI bundle
|
||||
RUN npm run build:production
|
||||
|
||||
# Write ui-version.env file
|
||||
RUN UI_VERSION=$(git describe --tags) && \
|
||||
UI_COMMIT=$(git rev-parse HEAD) && \
|
||||
printf "UI_VERSION=%s\nUI_COMMIT=%s\n" "$UI_VERSION" "$UI_COMMIT" > dist/ui-version.env && \
|
||||
echo "Generated dist/ui-version.env"
|
||||
|
||||
|
||||
|
||||
#################################
|
||||
# Stage 2: Rust Dependencies Cache
|
||||
#################################
|
||||
|
||||
@@ -16,19 +16,12 @@ fn main() {
|
||||
let ui_dir = workspace_root.join("ui");
|
||||
let dist_dir = manifest_dir.join("static"); // static/ in the crate
|
||||
|
||||
// Get the latest commit hash for the ui directory
|
||||
// Get the latest commit hash for the ui submodule
|
||||
let output = Command::new("git")
|
||||
.args([
|
||||
"log",
|
||||
"-n",
|
||||
"1",
|
||||
"--pretty=format:%H",
|
||||
"--",
|
||||
ui_dir.to_str().unwrap(),
|
||||
])
|
||||
.current_dir(workspace_root)
|
||||
.args(["rev-parse", "HEAD"])
|
||||
.current_dir(&ui_dir)
|
||||
.output()
|
||||
.expect("Failed to get git commit hash for ui directory");
|
||||
.expect("Failed to get git commit hash for ui submodule");
|
||||
let current_hash = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
||||
|
||||
// Read the last built commit hash
|
||||
@@ -74,7 +67,7 @@ fn main() {
|
||||
file.write_all(current_hash.as_bytes())
|
||||
.expect("Failed to write hash");
|
||||
|
||||
// Generate UI version file for Docker builds
|
||||
// Generate UI version file for runtime access
|
||||
generate_ui_version_file(workspace_root);
|
||||
} else {
|
||||
println!("cargo:warning=UI unchanged, skipping build");
|
||||
@@ -104,8 +97,12 @@ fn generate_ui_version_file(workspace_root: &std::path::Path) {
|
||||
|
||||
// Write version file
|
||||
let version_content = format!("UI_VERSION={}\nUI_COMMIT={}\n", ui_version, ui_commit);
|
||||
let version_file = workspace_root.join("ui-version.env");
|
||||
fs::write(&version_file, version_content).expect("Failed to write ui-version.env");
|
||||
|
||||
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
|
||||
let dist_dir = manifest_dir.join("static");
|
||||
let version_file_in_dist = dist_dir.join("ui-version.env");
|
||||
fs::write(&version_file_in_dist, version_content)
|
||||
.expect("Failed to write ui-version.env in static/");
|
||||
|
||||
println!(
|
||||
"Generated ui-version.env with UI_VERSION={} UI_COMMIT={}",
|
||||
|
||||
@@ -8,8 +8,9 @@ use axum::{
|
||||
use axum_login::login_required;
|
||||
use hyper::StatusCode;
|
||||
use rust_embed::RustEmbed;
|
||||
use tracing::error;
|
||||
|
||||
use crate::AppState;
|
||||
use crate::{AppState, Asset};
|
||||
|
||||
mod auth;
|
||||
pub mod root;
|
||||
@@ -34,6 +35,37 @@ async fn resource_handler(Path(path): Path<String>) -> impl IntoResponse {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
pub struct JellyfinUiVersion {
|
||||
pub version: String,
|
||||
pub commit: String,
|
||||
}
|
||||
|
||||
fn get_jellyfin_ui_version() -> Option<JellyfinUiVersion> {
|
||||
if let Some(file) = Asset::get("ui-version.env") {
|
||||
let content = String::from_utf8_lossy(&file.data);
|
||||
let mut version = "unknown";
|
||||
let mut commit = "unknown";
|
||||
for line in content.lines() {
|
||||
if line.starts_with("UI_VERSION=") {
|
||||
version = line.trim_start_matches("UI_VERSION=");
|
||||
} else if line.starts_with("UI_COMMIT=") {
|
||||
commit = line.trim_start_matches("UI_COMMIT=");
|
||||
}
|
||||
}
|
||||
Some(JellyfinUiVersion {
|
||||
version: version.to_string(),
|
||||
commit: commit.to_string(),
|
||||
})
|
||||
} else {
|
||||
error!("Failed to load Jellyfin UI version info from embedded resources");
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub static JELLYFIN_UI_VERSION: once_cell::sync::Lazy<Option<JellyfinUiVersion>> =
|
||||
once_cell::sync::Lazy::new(get_jellyfin_ui_version);
|
||||
|
||||
pub fn ui_routes() -> axum::Router<AppState> {
|
||||
Router::new()
|
||||
// Root
|
||||
|
||||
@@ -6,7 +6,10 @@ use axum::{
|
||||
};
|
||||
use tracing::error;
|
||||
|
||||
use crate::AppState;
|
||||
use crate::{
|
||||
ui::{JellyfinUiVersion, JELLYFIN_UI_VERSION},
|
||||
AppState,
|
||||
};
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "index.html")]
|
||||
@@ -14,6 +17,7 @@ pub struct IndexTemplate {
|
||||
pub version: Option<String>,
|
||||
pub ui_route: String,
|
||||
pub root: Option<String>,
|
||||
pub jellyfin_ui_version: Option<JellyfinUiVersion>,
|
||||
}
|
||||
|
||||
/// Root/home page
|
||||
@@ -22,6 +26,7 @@ pub async fn index(State(state): State<AppState>) -> impl IntoResponse {
|
||||
version: Some(env!("CARGO_PKG_VERSION").to_string()),
|
||||
ui_route: state.get_ui_route().await,
|
||||
root: state.get_url_prefix().await,
|
||||
jellyfin_ui_version: JELLYFIN_UI_VERSION.clone(),
|
||||
};
|
||||
|
||||
match template.render() {
|
||||
|
||||
@@ -81,6 +81,10 @@
|
||||
{% match version %}{% when Some with (v) %} v{{ v }}{% when None %}{% endmatch %}
|
||||
</a>
|
||||
</p>
|
||||
<p style="margin: 0.5rem 0 0 0; color: var(--pico-muted-color); font-size: 0.75rem;">
|
||||
<i class="fas fa-film" style="margin-right: 0.5rem;"></i>
|
||||
{% match jellyfin_ui_version %}{% when Some with (ui) %}<a href="https://github.com/jellyfin/jellyfin-web/tree/{{ ui.version }}" target="_blank">Jellyfin Web UI {{ ui.version }}</a>{% when None %}Jellyfin Web UI: UNKNOWN{% endmatch %}
|
||||
</p>
|
||||
<p style="margin: 0.5rem 0 0 0; color: var(--pico-muted-color); font-size: 0.75rem;">
|
||||
<i class="fas fa-heart" style="margin-right: 0.25rem; color: var(--pico-del-color);"></i>
|
||||
Built with Rust & HTMX
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Generate a file that tracks the UI version
|
||||
# This helps Docker detect when the UI submodule has changed
|
||||
|
||||
set -e
|
||||
|
||||
UI_VERSION=$(git -C ui describe --tags 2>/dev/null || echo "unknown")
|
||||
UI_COMMIT=$(git -C ui rev-parse HEAD 2>/dev/null || echo "unknown")
|
||||
|
||||
echo "UI_VERSION=${UI_VERSION}" > ui-version.env
|
||||
echo "UI_COMMIT=${UI_COMMIT}" >> ui-version.env
|
||||
|
||||
echo "Generated ui-version.env with UI_VERSION=${UI_VERSION} UI_COMMIT=${UI_COMMIT}"
|
||||
@@ -1,2 +0,0 @@
|
||||
UI_VERSION=v10.11.2
|
||||
UI_COMMIT=933e1b255bcd734ce1f14f0dc12c47d470d4da42
|
||||
Reference in New Issue
Block a user