diff --git a/.gitignore b/.gitignore index 8181bf8..e186a91 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ test.db-shm test.db-wal test.lum test.pres -profile.json.gz \ No newline at end of file +profile.json.gz +result \ No newline at end of file diff --git a/TODO.org b/TODO.org index e3c5539..dfa3328 100644 --- a/TODO.org +++ b/TODO.org @@ -3,6 +3,8 @@ #+CATEGORY: dev +* TODO [#A] Deployment pipeline and get a MVP going + * TODO [#A] Add Action system This will be based on each slide having the ability to activate an action (i.e. OBS scene switch, OBS start or stop) when it is active. diff --git a/flake.lock b/flake.lock index aa3d695..e7c26ba 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,20 @@ { "nodes": { + "crane": { + "locked": { + "lastModified": 1775839657, + "narHash": "sha256-SPm9ck7jh3Un9nwPuMGbRU04UroFmOHjLP56T10MOeM=", + "owner": "ipetkov", + "repo": "crane", + "rev": "7cf72d978629469c4bd4206b95c402514c1f6000", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, "fenix": { "inputs": { "nixpkgs": "nixpkgs", @@ -144,6 +159,7 @@ }, "root": { "inputs": { + "crane": "crane", "fenix": "fenix", "flake-utils": "flake-utils", "naersk": "naersk", diff --git a/flake.nix b/flake.nix index 3df8bdb..0dec83a 100644 --- a/flake.nix +++ b/flake.nix @@ -7,6 +7,7 @@ flake-utils.url = "github:numtide/flake-utils"; fenix.url = "github:nix-community/fenix"; rust-overlay.url = "github:oxalica/rust-overlay"; + crane.url = "github:ipetkov/crane"; }; outputs = @@ -21,10 +22,21 @@ # overlays = [ rust-overlay.overlays.default ]; # overlays = [cargo2nix.overlays.default]; }; + inherit (pkgs) lib; + craneLib = crane.mkLib pkgs; naersk' = pkgs.callPackage naersk { }; # toolchain = (with pkgs.fenix.default; [cargo clippy rust-std rust-src rustc rustfmt rust-analyzer-nightly]); - + unfilteredRoot = ./.; # The original, unfiltered source + src = lib.fileset.toSource { + root = unfilteredRoot; + fileset = lib.fileset.unions [ + # Default files from crane (Rust and cargo files) + (craneLib.fileset.commonCargoSources unfilteredRoot) + # Include all the .sql migrations as well + ./migrations + ]; + }; nativeBuildInputs = with pkgs; [ # Rust tools @@ -49,6 +61,10 @@ libxkbcommon pkg-config sccache + just + sqlx-cli + cargo-watch + samply ]; buildInputs = with pkgs; [ @@ -83,11 +99,6 @@ ffmpeg-full mupdf # yt-dlp - - just - sqlx-cli - cargo-watch - samply ]; LD_LIBRARY_PATH = "$LD_LIBRARY_PATH:${ @@ -112,6 +123,28 @@ pkgs.libclang ] }"; + + commonArgs = { + strictDeps = false; + inherit src buildInputs nativeBuildInputs LD_LIBRARY_PATH; + }; + + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + lumina = craneLib.buildPackage ( + commonArgs + // { + inherit cargoArtifacts buildInputs nativeBuildInputs LD_LIBRARY_PATH; + + preBuild = '' + export DATABASE_URL=sqlite:./db.sqlite3 + sqlx database create + sqlx migrate run + ''; + cargoTestCommand = ""; + cargoExtraArgs = ""; + } + ); + in rec { devShell = @@ -125,15 +158,9 @@ DATABASE_URL = "sqlite://./test.db"; # RUST_SRC_PATH = "${toolchain.rust-src}/lib/rustlib/src/rust/library"; }; - defaultPackage = naersk'.buildPackage { - inherit nativeBuildInputs buildInputs LD_LIBRARY_PATH; - src = ./.; - }; + defaultPackage = lumina; packages = { - default = naersk'.buildPackage { - inherit nativeBuildInputs buildInputs LD_LIBRARY_PATH; - src = ./.; - }; + default = lumina; }; } ); diff --git a/src/core/settings.rs b/src/core/settings.rs index 9b64ea1..e7ecfa1 100644 --- a/src/core/settings.rs +++ b/src/core/settings.rs @@ -44,6 +44,7 @@ impl AppTheme { pub struct Settings { pub app_theme: AppTheme, pub obs_url: Option, + pub genius_token: Option, } impl Default for Settings { @@ -51,6 +52,7 @@ impl Default for Settings { Self { app_theme: AppTheme::System, obs_url: None, + genius_token: None, } } } diff --git a/src/core/song_search.rs b/src/core/song_search.rs index a9779b0..bd8c85a 100644 --- a/src/core/song_search.rs +++ b/src/core/song_search.rs @@ -1,6 +1,9 @@ use std::collections::HashMap; -use crate::core::songs::{Song, VerseName}; +use crate::core::{ + settings, + songs::{Song, VerseName}, +}; use itertools::Itertools; use miette::{IntoDiagnostic, Result, miette}; use nom::{ @@ -147,13 +150,16 @@ fn parse_verse_lyrics(lyrics: &str) -> IResult<&str, String> { pub async fn search_genius_links( query: impl AsRef + std::fmt::Display, + auth_token: String, ) -> Result> { - let auth_token = env!("GENIUS_TOKEN"); + // let Some(auth_token) = option_env!("GENIUS_TOKEN") else { + // return Err(miette!("No Genius Token")); + // }; + + let head_value = header::HeaderValue::from_str(&auth_token) + .into_diagnostic()?; let mut headers = header::HeaderMap::new(); - headers.insert( - header::AUTHORIZATION, - header::HeaderValue::from_static(auth_token), - ); + headers.insert(header::AUTHORIZATION, head_value); let client = reqwest::Client::builder() .default_headers(headers) .build() @@ -365,9 +371,12 @@ mod test { site: "https://genius.com".to_string(), link: "https://genius.com/North-point-worship-death-was-arrested-lyrics".to_string(), }; - let hits = search_genius_links("Death was arrested") - .await - .map_err(|e| e.to_string())?; + let hits = search_genius_links( + "Death was arrested", + "test".to_string(), + ) + .await + .map_err(|e| e.to_string())?; assert!( hits.iter().find(|hit| **hit == song).is_some(),