fix: 尝试修复下载错误 (#379)
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
use std::path::Path;
|
||||
use std::pin::Pin;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use anyhow::{Context, Result, ensure};
|
||||
use bili_sync_entity::*;
|
||||
use chrono::Utc;
|
||||
use futures::Stream;
|
||||
use sea_orm::ActiveValue::Set;
|
||||
use sea_orm::entity::prelude::*;
|
||||
use sea_orm::sea_query::{OnConflict, SimpleExpr};
|
||||
use sea_orm::sea_query::SimpleExpr;
|
||||
use sea_orm::{DatabaseConnection, Unchanged};
|
||||
|
||||
use crate::adapter::{_ActiveModel, VideoSource, VideoSourceEnum};
|
||||
@@ -108,32 +108,24 @@ impl VideoSource for collection::Model {
|
||||
},
|
||||
);
|
||||
let collection_info = collection.get_info().await?;
|
||||
collection::Entity::insert(collection::ActiveModel {
|
||||
s_id: Set(collection_info.sid),
|
||||
m_id: Set(collection_info.mid),
|
||||
r#type: Set(collection_info.collection_type.into()),
|
||||
ensure!(
|
||||
collection_info.sid == self.s_id
|
||||
&& collection_info.mid == self.m_id
|
||||
&& collection_info.collection_type == CollectionType::from(self.r#type),
|
||||
"collection info mismatch: {:?} != {:?}",
|
||||
collection_info,
|
||||
collection.collection
|
||||
);
|
||||
collection::ActiveModel {
|
||||
id: Unchanged(self.id),
|
||||
name: Set(collection_info.name.clone()),
|
||||
..Default::default()
|
||||
})
|
||||
.on_conflict(
|
||||
OnConflict::columns([
|
||||
collection::Column::SId,
|
||||
collection::Column::MId,
|
||||
collection::Column::Type,
|
||||
])
|
||||
.update_column(collection::Column::Name)
|
||||
.to_owned(),
|
||||
)
|
||||
.exec(connection)
|
||||
}
|
||||
.save(connection)
|
||||
.await?;
|
||||
Ok((
|
||||
collection::Entity::find()
|
||||
.filter(
|
||||
collection::Column::SId
|
||||
.eq(self.s_id)
|
||||
.and(collection::Column::MId.eq(self.m_id))
|
||||
.and(collection::Column::Type.eq(self.r#type)),
|
||||
)
|
||||
.filter(collection::Column::Id.eq(self.id))
|
||||
.one(connection)
|
||||
.await?
|
||||
.context("collection not found")?
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use std::path::Path;
|
||||
use std::pin::Pin;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use anyhow::{Context, Result, ensure};
|
||||
use bili_sync_entity::*;
|
||||
use futures::Stream;
|
||||
use sea_orm::ActiveValue::Set;
|
||||
use sea_orm::entity::prelude::*;
|
||||
use sea_orm::sea_query::{OnConflict, SimpleExpr};
|
||||
use sea_orm::sea_query::SimpleExpr;
|
||||
use sea_orm::{DatabaseConnection, Unchanged};
|
||||
|
||||
use crate::adapter::{_ActiveModel, VideoSource, VideoSourceEnum};
|
||||
@@ -71,21 +71,22 @@ impl VideoSource for favorite::Model {
|
||||
)> {
|
||||
let favorite = FavoriteList::new(bili_client, self.f_id.to_string());
|
||||
let favorite_info = favorite.get_info().await?;
|
||||
favorite::Entity::insert(favorite::ActiveModel {
|
||||
f_id: Set(favorite_info.id),
|
||||
ensure!(
|
||||
favorite_info.id == self.f_id,
|
||||
"favorite id mismatch: {} != {}",
|
||||
favorite_info.id,
|
||||
self.f_id
|
||||
);
|
||||
favorite::ActiveModel {
|
||||
id: Unchanged(self.id),
|
||||
name: Set(favorite_info.title.clone()),
|
||||
..Default::default()
|
||||
})
|
||||
.on_conflict(
|
||||
OnConflict::column(favorite::Column::FId)
|
||||
.update_column(favorite::Column::Name)
|
||||
.to_owned(),
|
||||
)
|
||||
.exec(connection)
|
||||
}
|
||||
.save(connection)
|
||||
.await?;
|
||||
Ok((
|
||||
favorite::Entity::find()
|
||||
.filter(favorite::Column::FId.eq(favorite_info.id))
|
||||
.filter(favorite::Column::Id.eq(self.id))
|
||||
.one(connection)
|
||||
.await?
|
||||
.context("favorite not found")?
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use std::path::Path;
|
||||
use std::pin::Pin;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use anyhow::{Context, Result, ensure};
|
||||
use bili_sync_entity::*;
|
||||
use futures::Stream;
|
||||
use sea_orm::ActiveValue::Set;
|
||||
use sea_orm::entity::prelude::*;
|
||||
use sea_orm::sea_query::{OnConflict, SimpleExpr};
|
||||
use sea_orm::sea_query::SimpleExpr;
|
||||
use sea_orm::{DatabaseConnection, Unchanged};
|
||||
|
||||
use crate::adapter::{_ActiveModel, VideoSource, VideoSourceEnum};
|
||||
@@ -71,21 +71,22 @@ impl VideoSource for submission::Model {
|
||||
)> {
|
||||
let submission = Submission::new(bili_client, self.upper_id.to_string());
|
||||
let upper = submission.get_info().await?;
|
||||
submission::Entity::insert(submission::ActiveModel {
|
||||
upper_id: Set(upper.mid.parse()?),
|
||||
ensure!(
|
||||
upper.mid == submission.upper_id,
|
||||
"submission upper id mismatch: {} != {}",
|
||||
upper.mid,
|
||||
submission.upper_id
|
||||
);
|
||||
submission::ActiveModel {
|
||||
id: Unchanged(self.id),
|
||||
upper_name: Set(upper.name),
|
||||
..Default::default()
|
||||
})
|
||||
.on_conflict(
|
||||
OnConflict::column(submission::Column::UpperId)
|
||||
.update_column(submission::Column::UpperName)
|
||||
.to_owned(),
|
||||
)
|
||||
.exec(connection)
|
||||
}
|
||||
.save(connection)
|
||||
.await?;
|
||||
Ok((
|
||||
submission::Entity::find()
|
||||
.filter(submission::Column::UpperId.eq(upper.mid))
|
||||
.filter(submission::Column::Id.eq(self.id))
|
||||
.one(connection)
|
||||
.await?
|
||||
.context("submission not found")?
|
||||
|
||||
@@ -55,7 +55,7 @@ pub struct CollectionItem {
|
||||
|
||||
pub struct Collection<'a> {
|
||||
client: &'a BiliClient,
|
||||
collection: CollectionItem,
|
||||
pub collection: CollectionItem,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::bilibili::favorite_list::Upper;
|
||||
use crate::bilibili::{BiliClient, MIXIN_KEY, Validate, VideoInfo};
|
||||
pub struct Submission<'a> {
|
||||
client: &'a BiliClient,
|
||||
upper_id: String,
|
||||
pub upper_id: String,
|
||||
}
|
||||
|
||||
impl<'a> Submission<'a> {
|
||||
|
||||
@@ -7,16 +7,14 @@ use axum::response::IntoResponse;
|
||||
use axum::routing::get;
|
||||
use axum::{Extension, ServiceExt};
|
||||
use reqwest::StatusCode;
|
||||
use rust_embed_for_web::{EmbedableFile, RustEmbed};
|
||||
use rust_embed::Embed;
|
||||
use sea_orm::DatabaseConnection;
|
||||
|
||||
use crate::api::{MpscWriter, router};
|
||||
use crate::bilibili::BiliClient;
|
||||
use crate::config::VersionedConfig;
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[preserve_source = false]
|
||||
#[gzip = false]
|
||||
#[derive(Embed)]
|
||||
#[folder = "../../web/build"]
|
||||
struct Asset;
|
||||
|
||||
@@ -46,21 +44,6 @@ async fn frontend_files(uri: Uri) -> impl IntoResponse {
|
||||
let Some(content) = Asset::get(path) else {
|
||||
return (StatusCode::NOT_FOUND, "404 Not Found").into_response();
|
||||
};
|
||||
let mime_type = content.mime_type();
|
||||
let content_type = mime_type.as_deref().unwrap_or("application/octet-stream");
|
||||
if cfg!(debug_assertions) {
|
||||
(
|
||||
[(header::CONTENT_TYPE, content_type)],
|
||||
// safety: `RustEmbed` returns uncompressed files directly from the filesystem in debug mode
|
||||
content.data().unwrap(),
|
||||
)
|
||||
.into_response()
|
||||
} else {
|
||||
(
|
||||
[(header::CONTENT_TYPE, content_type), (header::CONTENT_ENCODING, "br")],
|
||||
// safety: `RustEmbed` will always generate br-compressed files if the feature is enabled
|
||||
content.data_br().unwrap(),
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
let mime = mime_guess::from_path(path).first_or_octet_stream();
|
||||
([(header::CONTENT_TYPE, mime.as_ref())], content.data).into_response()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user