Compare commits
9 Commits
20a01c89af
...
Fixing-med
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a54a88729 | ||
|
|
78bfcf0261 | ||
|
|
194f3fbd9a | ||
|
|
147c21a19b | ||
|
|
5cb5a78032 | ||
|
|
53314a0896 | ||
|
|
998a84f992 | ||
|
|
59d3a1eec1 | ||
|
|
dce72a6ab9 |
@@ -7,6 +7,11 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, flake-utils }:
|
outputs = { self, nixpkgs, flake-utils }:
|
||||||
|
{
|
||||||
|
# NixOS module (system-independent)
|
||||||
|
nixosModules.default = import ./module.nix;
|
||||||
|
}
|
||||||
|
//
|
||||||
flake-utils.lib.eachDefaultSystem (system:
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
|
|||||||
@@ -746,18 +746,21 @@ def stream_transcoded(request: Request, file_id: str, start_time: float = 0.0):
|
|||||||
time_start_sec = (byte_start / estimated_total_bytes) * video_duration
|
time_start_sec = (byte_start / estimated_total_bytes) * video_duration
|
||||||
time_start_sec = max(0.0, min(time_start_sec, video_duration - 0.5))
|
time_start_sec = max(0.0, min(time_start_sec, video_duration - 0.5))
|
||||||
|
|
||||||
# For seeking, don't limit duration - stream to end
|
|
||||||
# The browser will handle buffering
|
|
||||||
duration_sec = None # None means stream to end
|
|
||||||
|
|
||||||
# Update headers for range response
|
# Update headers for range response
|
||||||
# For seeking, we typically don't know the exact end, so estimate
|
# For seeking, we typically don't know the exact end, so estimate
|
||||||
actual_byte_end = min(byte_end or estimated_total_bytes - 1, estimated_total_bytes - 1)
|
actual_byte_end = min(byte_end or estimated_total_bytes - 1, estimated_total_bytes - 1)
|
||||||
headers["Content-Range"] = f"bytes {byte_start}-{actual_byte_end}/{estimated_total_bytes}"
|
headers["Content-Range"] = f"bytes {byte_start}-{actual_byte_end}/{estimated_total_bytes}"
|
||||||
headers["Content-Length"] = str(actual_byte_end - byte_start + 1)
|
headers["Content-Length"] = str(actual_byte_end - byte_start + 1)
|
||||||
|
|
||||||
|
# Honor the requested range: approximate duration based on bitrate so the
|
||||||
|
# transcoded response length matches the declared Content-Length.
|
||||||
|
requested_bytes = actual_byte_end - byte_start + 1
|
||||||
|
duration_sec = requested_bytes * 8 / transcoded_bitrate if transcoded_bitrate else None
|
||||||
|
if duration_sec is not None:
|
||||||
|
# Clamp to remaining duration.
|
||||||
|
duration_sec = max(0.0, min(duration_sec, video_duration - time_start_sec))
|
||||||
|
|
||||||
# Stream from the calculated time position using FFmpeg's -ss flag
|
# Stream from the calculated time position using FFmpeg's -ss flag
|
||||||
# Duration is None, so it will stream to the end
|
|
||||||
return StreamingResponse(
|
return StreamingResponse(
|
||||||
generate_transcoded_stream(p, time_start_sec, duration_sec),
|
generate_transcoded_stream(p, time_start_sec, duration_sec),
|
||||||
media_type=content_type,
|
media_type=content_type,
|
||||||
|
|||||||
179
module.nix
Normal file
179
module.nix
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
cfg = config.services.usda-vision;
|
||||||
|
|
||||||
|
# Get packages from the package option (must be provided)
|
||||||
|
camera-sdk = cfg.package.camera-sdk;
|
||||||
|
usda-vision-app = cfg.package.usda-vision;
|
||||||
|
in
|
||||||
|
|
||||||
|
{
|
||||||
|
options.services.usda-vision = {
|
||||||
|
enable = lib.mkEnableOption "USDA Vision system";
|
||||||
|
|
||||||
|
package = lib.mkOption {
|
||||||
|
type = lib.types.attrs;
|
||||||
|
default = {};
|
||||||
|
description = "Package set containing camera-sdk and usda-vision packages";
|
||||||
|
};
|
||||||
|
|
||||||
|
hostname = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "exp-dash";
|
||||||
|
description = "Hostname or IP address to replace exp-dash and localhost with in configuration";
|
||||||
|
};
|
||||||
|
|
||||||
|
replaceHostnames = lib.mkOption {
|
||||||
|
type = lib.types.bool;
|
||||||
|
default = false;
|
||||||
|
description = "Whether to replace exp-dash and localhost hostnames with the configured hostname";
|
||||||
|
};
|
||||||
|
|
||||||
|
envFile = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.path;
|
||||||
|
default = null;
|
||||||
|
description = "Path to environment file (managed by ragenix in deployment)";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
# System packages
|
||||||
|
environment.systemPackages = with pkgs; [
|
||||||
|
docker
|
||||||
|
docker-compose
|
||||||
|
supabase-cli
|
||||||
|
camera-sdk
|
||||||
|
usda-vision-app
|
||||||
|
];
|
||||||
|
|
||||||
|
# Make camera SDK libraries available system-wide
|
||||||
|
environment.variables = {
|
||||||
|
LD_LIBRARY_PATH = "${camera-sdk}/lib";
|
||||||
|
};
|
||||||
|
|
||||||
|
# Enable Docker service
|
||||||
|
virtualisation.docker = {
|
||||||
|
enable = true;
|
||||||
|
autoPrune.enable = true;
|
||||||
|
daemon.settings = {
|
||||||
|
experimental = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# Create persistent directories
|
||||||
|
systemd.tmpfiles.rules = [
|
||||||
|
"d /var/lib/usda-vision 0755 root root -"
|
||||||
|
"f /var/lib/usda-vision/.env 0644 root root -"
|
||||||
|
"d /var/lib/supabase 0755 root root -"
|
||||||
|
];
|
||||||
|
|
||||||
|
# Supabase CLI service
|
||||||
|
systemd.services.supabase-cli = {
|
||||||
|
enable = true;
|
||||||
|
description = "Supabase CLI Service";
|
||||||
|
|
||||||
|
preStart = ''
|
||||||
|
rm -rf /var/lib/supabase/*
|
||||||
|
rm -rf /var/lib/supabase/.* 2>/dev/null || true
|
||||||
|
|
||||||
|
if [ -d ${usda-vision-app}/opt/usda-vision/supabase ]; then
|
||||||
|
${pkgs.rsync}/bin/rsync -av ${usda-vision-app}/opt/usda-vision/supabase/ /var/lib/supabase/supabase/
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p /var/lib/supabase/supabase/.branches
|
||||||
|
chmod -R 755 /var/lib/supabase
|
||||||
|
'';
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
WorkingDirectory = "/var/lib/supabase";
|
||||||
|
EnvironmentFile = lib.mkIf (cfg.envFile != null) cfg.envFile;
|
||||||
|
ExecStart = "${pkgs.supabase-cli}/bin/supabase start";
|
||||||
|
ExecStop = "${pkgs.supabase-cli}/bin/supabase stop";
|
||||||
|
Type = "oneshot";
|
||||||
|
RemainAfterExit = true;
|
||||||
|
User = "root";
|
||||||
|
Group = "root";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# USDA Vision docker compose service
|
||||||
|
systemd.services.usda-vision = {
|
||||||
|
description = "USDA Vision Docker Compose Stack";
|
||||||
|
after = [ "docker.service" "network-online.target" "systemd-tmpfiles-setup.service" ];
|
||||||
|
wants = [ "network-online.target" ];
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
|
||||||
|
unitConfig = lib.mkIf (cfg.envFile != null) {
|
||||||
|
ConditionPathExists = cfg.envFile;
|
||||||
|
};
|
||||||
|
|
||||||
|
preStart = ''
|
||||||
|
echo "Syncing application code to /var/lib/usda-vision..."
|
||||||
|
${pkgs.rsync}/bin/rsync -av --delete \
|
||||||
|
--checksum \
|
||||||
|
--exclude='node_modules' \
|
||||||
|
--exclude='.env' \
|
||||||
|
--exclude='.env.azure' \
|
||||||
|
--exclude='__pycache__' \
|
||||||
|
--exclude='.venv' \
|
||||||
|
${usda-vision-app}/opt/usda-vision/ /var/lib/usda-vision/
|
||||||
|
|
||||||
|
${lib.optionalString cfg.replaceHostnames ''
|
||||||
|
echo "Replacing hostnames (exp-dash, localhost) with ${cfg.hostname} in docker-compose.yml..."
|
||||||
|
${pkgs.gnused}/bin/sed -i \
|
||||||
|
-e 's|exp-dash|${cfg.hostname}|g' \
|
||||||
|
-e 's|localhost|${cfg.hostname}|g' \
|
||||||
|
/var/lib/usda-vision/docker-compose.yml
|
||||||
|
''}
|
||||||
|
|
||||||
|
# Configure docker-compose to use Nix-provided camera SDK
|
||||||
|
echo "Configuring camera SDK in docker-compose.yml..."
|
||||||
|
${pkgs.gnused}/bin/sed -i \
|
||||||
|
-e '/^ - \/etc\/timezone:\/etc\/timezone:ro$/a\ - ${camera-sdk}/lib:/opt/camera-sdk/lib:ro' \
|
||||||
|
-e 's|LD_LIBRARY_PATH=/usr/local/lib:/lib:/usr/lib|LD_LIBRARY_PATH=/opt/camera-sdk/lib:/usr/local/lib:/lib:/usr/lib|' \
|
||||||
|
/var/lib/usda-vision/docker-compose.yml
|
||||||
|
|
||||||
|
# Fix env_file paths to point to /var/lib/usda-vision/.env
|
||||||
|
echo "Fixing env_file paths in docker-compose.yml..."
|
||||||
|
${pkgs.gnused}/bin/sed -i \
|
||||||
|
's|/var/lib/usda-vision/management-dashboard-web-app/\.env|/var/lib/usda-vision/.env|g' \
|
||||||
|
/var/lib/usda-vision/docker-compose.yml
|
||||||
|
|
||||||
|
# Replace [REDACTED] placeholders with actual VITE_SUPABASE_ANON_KEY reference
|
||||||
|
echo "Fixing ANON_KEY references in docker-compose.yml..."
|
||||||
|
${pkgs.gnused}/bin/sed -i \
|
||||||
|
's|\[REDACTED\]|$${VITE_SUPABASE_ANON_KEY}|g' \
|
||||||
|
/var/lib/usda-vision/docker-compose.yml
|
||||||
|
|
||||||
|
if [ -n "${cfg.envFile}" ]; then
|
||||||
|
echo "Copying environment file from managed secret..."
|
||||||
|
cp ${cfg.envFile} /var/lib/usda-vision/.env
|
||||||
|
chmod 644 /var/lib/usda-vision/.env
|
||||||
|
fi
|
||||||
|
|
||||||
|
${lib.optionalString (cfg.envFile == null) ''
|
||||||
|
if [ ! -s /var/lib/usda-vision/.env ]; then
|
||||||
|
if [ -f ${usda-vision-app}/opt/usda-vision/.env.example ]; then
|
||||||
|
echo "WARNING: No environment file provided, using .env.example"
|
||||||
|
cp ${usda-vision-app}/opt/usda-vision/.env.example /var/lib/usda-vision/.env
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
''}
|
||||||
|
'';
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
RemainAfterExit = true;
|
||||||
|
WorkingDirectory = "/var/lib/usda-vision";
|
||||||
|
User = "root";
|
||||||
|
Group = "root";
|
||||||
|
ExecStart = "${pkgs.docker-compose}/bin/docker-compose -f /var/lib/usda-vision/docker-compose.yml up -d --build";
|
||||||
|
ExecStop = "${pkgs.docker-compose}/bin/docker-compose -f /var/lib/usda-vision/docker-compose.yml down";
|
||||||
|
ExecReload = "${pkgs.bash}/bin/bash -c '${pkgs.docker-compose}/bin/docker-compose -f /var/lib/usda-vision/docker-compose.yml down && ${pkgs.docker-compose}/bin/docker-compose -f /var/lib/usda-vision/docker-compose.yml up -d --build'";
|
||||||
|
TimeoutStartSec = 300;
|
||||||
|
TimeoutStopSec = 120;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -52,7 +52,10 @@ export const VideoModal: React.FC<Props> = ({ fileId, onClose }) => {
|
|||||||
sources: [
|
sources: [
|
||||||
{
|
{
|
||||||
src: src,
|
src: src,
|
||||||
type: 'video/mp4'
|
// Do not hardcode the MIME type: the "regular" endpoint may serve
|
||||||
|
// non-mp4 containers (avi/mkv/etc), and forcing mp4 can trigger
|
||||||
|
// MEDIA_ERR_SRC_NOT_SUPPORTED in Video.js/browser.
|
||||||
|
// Let Video.js/browser sniff based on the actual response.
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user