mirror of
https://github.com/Xinrea/bili-shadowreplay.git
synced 2025-11-25 04:22:24 +08:00
fix: update video with new cover
This commit is contained in:
@@ -92,7 +92,7 @@ impl Database {
|
||||
Ok(video)
|
||||
}
|
||||
|
||||
pub async fn update_video_cover(&self, id: i64, cover: String) -> Result<(), DatabaseError> {
|
||||
pub async fn update_video_cover(&self, id: i64, cover: &str) -> Result<(), DatabaseError> {
|
||||
let lock = self.db.read().await.clone().unwrap();
|
||||
sqlx::query("UPDATE videos SET cover = $1 WHERE id = $2")
|
||||
.bind(cover)
|
||||
|
||||
@@ -733,7 +733,20 @@ pub async fn update_video_cover(
|
||||
id: i64,
|
||||
cover: String,
|
||||
) -> Result<(), String> {
|
||||
Ok(state.db.update_video_cover(id, cover).await?)
|
||||
let video = state.db.get_video(id).await?;
|
||||
let output_path = Path::new(state.config.read().await.output.as_str()).join(&video.file);
|
||||
let cover_path = output_path.with_extension("jpg");
|
||||
// decode cover and write into file
|
||||
let base64 = cover.split("base64,").nth(1).unwrap();
|
||||
let bytes = base64::engine::general_purpose::STANDARD
|
||||
.decode(base64)
|
||||
.unwrap();
|
||||
tokio::fs::write(&cover_path, bytes)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
let cover_file_name = cover_path.file_name().unwrap().to_str().unwrap();
|
||||
log::debug!("Update video cover: {} {}", id, cover_file_name);
|
||||
Ok(state.db.update_video_cover(id, cover_file_name).await?)
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "gui", tauri::command)]
|
||||
|
||||
@@ -120,12 +120,7 @@ pub async fn try_convert_clip_covers(
|
||||
// update record
|
||||
db.update_video_cover(
|
||||
video.id,
|
||||
cover_file_path
|
||||
.file_name()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
cover_file_path.file_name().unwrap().to_str().unwrap(),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ const log = {
|
||||
|
||||
async function invoke<T>(
|
||||
command: string,
|
||||
args?: Record<string, any>
|
||||
args?: Record<string, any>,
|
||||
): Promise<T> {
|
||||
try {
|
||||
if (TAURI_ENV) {
|
||||
@@ -53,7 +53,7 @@ async function invoke<T>(
|
||||
// open new page to live_index.html
|
||||
window.open(
|
||||
`index_live.html?platform=${args.platform}&room_id=${args.roomId}&live_id=${args.liveId}`,
|
||||
"_blank"
|
||||
"_blank",
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -74,7 +74,7 @@ async function invoke<T>(
|
||||
// if status is 405, it means the command is not allowed
|
||||
if (response.status === 405) {
|
||||
throw new Error(
|
||||
`Command ${command} is not allowed, maybe bili-shadowreplay is running in readonly mode or HTTP method mismatch`
|
||||
`Command ${command} is not allowed, maybe bili-shadowreplay is running in readonly mode or HTTP method mismatch`,
|
||||
);
|
||||
}
|
||||
if (!response.ok) {
|
||||
|
||||
Reference in New Issue
Block a user