|
@@ -1,4 +1,5 @@
|
|
|
use crate::{
|
|
|
+ cache::Cache,
|
|
|
error::NtitledError,
|
|
|
htmx::{DirHtmx, FileHtmx, SubtitleResponseHtmx},
|
|
|
ost::{data::SubtitleResponse, hash::compute_hash},
|
|
@@ -29,7 +30,7 @@ pub async fn get_directory(
|
|
|
|
|
|
info!("Listing {path}");
|
|
|
|
|
|
- let files = state.0.scan_dir_contents(path)?;
|
|
|
+ let files = state.scan_dir_contents(path)?;
|
|
|
|
|
|
let response = files
|
|
|
.into_iter()
|
|
@@ -109,7 +110,7 @@ pub struct DownloadQuery {
|
|
|
}
|
|
|
|
|
|
pub async fn download_subtitles(
|
|
|
- state: axum::extract::State<State>,
|
|
|
+ mut state: axum::extract::State<State>,
|
|
|
query: axum::extract::Query<DownloadQuery>,
|
|
|
) -> Result<String, NtitledError> {
|
|
|
let file_id = urlencoding::decode(&query.file_id)?.parse()?;
|
|
@@ -122,10 +123,21 @@ pub async fn download_subtitles(
|
|
|
|
|
|
let ext = Path::new(&full_path).extension().and_then(OsStr::to_str);
|
|
|
|
|
|
- let path = ext
|
|
|
+ let srt_path = ext
|
|
|
.map(|ext| query.full_path.replace(&format!(".{ext}"), ".srt"))
|
|
|
.unwrap_or(format!("{full_path}.srt"));
|
|
|
|
|
|
- state.client.download_subtitles(file_id, &path).await?;
|
|
|
+ state.client.download_subtitles(file_id, &srt_path).await?;
|
|
|
+
|
|
|
+ if let Some(name) = file {
|
|
|
+ let existing_meta = state
|
|
|
+ .cache
|
|
|
+ .get_file_meta(&name.replace(&format!(".{}", ext.unwrap_or_default()), ""))?;
|
|
|
+ if let Some(mut meta) = existing_meta {
|
|
|
+ meta.has_subs = true;
|
|
|
+ state.cache.set_file_meta(&meta)?;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
Ok(String::from("Successfully downloaded subtitles"))
|
|
|
}
|