|
@@ -1,4 +1,5 @@
|
|
use crate::{
|
|
use crate::{
|
|
|
|
+ cache::Cache,
|
|
error::NtitledError,
|
|
error::NtitledError,
|
|
htmx::{DirHtmx, FileHtmx, SubtitleResponseHtmx},
|
|
htmx::{DirHtmx, FileHtmx, SubtitleResponseHtmx},
|
|
ost::{data::SubtitleResponse, hash::compute_hash},
|
|
ost::{data::SubtitleResponse, hash::compute_hash},
|
|
@@ -29,7 +30,7 @@ pub async fn get_directory(
|
|
|
|
|
|
info!("Listing {path}");
|
|
info!("Listing {path}");
|
|
|
|
|
|
- let files = state.0.scan_dir_contents(path)?;
|
|
|
|
|
|
+ let files = state.scan_dir_contents(path)?;
|
|
|
|
|
|
let response = files
|
|
let response = files
|
|
.into_iter()
|
|
.into_iter()
|
|
@@ -109,7 +110,7 @@ pub struct DownloadQuery {
|
|
}
|
|
}
|
|
|
|
|
|
pub async fn download_subtitles(
|
|
pub async fn download_subtitles(
|
|
- state: axum::extract::State<State>,
|
|
|
|
|
|
+ mut state: axum::extract::State<State>,
|
|
query: axum::extract::Query<DownloadQuery>,
|
|
query: axum::extract::Query<DownloadQuery>,
|
|
) -> Result<String, NtitledError> {
|
|
) -> Result<String, NtitledError> {
|
|
let file_id = urlencoding::decode(&query.file_id)?.parse()?;
|
|
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 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"))
|
|
.map(|ext| query.full_path.replace(&format!(".{ext}"), ".srt"))
|
|
.unwrap_or(format!("{full_path}.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"))
|
|
Ok(String::from("Successfully downloaded subtitles"))
|
|
}
|
|
}
|