This commit is contained in:
parent
cc9f3c85da
commit
e6d6de4cc6
1 changed files with 17 additions and 19 deletions
|
@ -5,28 +5,26 @@ pub async fn fix_attachments_types(ctx: upub::Context) -> Result<(), Box<dyn std
|
|||
tracing::info!("fixing attachments documentType...");
|
||||
let tx = ctx.db().begin().await?;
|
||||
|
||||
{
|
||||
let mut stream = upub::model::attachment::Entity::find()
|
||||
.filter(upub::model::attachment::Column::DocumentType.eq(apb::DocumentType::Document))
|
||||
.stream(&tx)
|
||||
.await?;
|
||||
let mut stream = upub::model::attachment::Entity::find()
|
||||
.filter(upub::model::attachment::Column::DocumentType.eq(apb::DocumentType::Document))
|
||||
.stream(ctx.db())
|
||||
.await?;
|
||||
|
||||
while let Some(attachment) = stream.try_next().await? {
|
||||
let Some((mime_kind, _mime_type)) = attachment.media_type.split_once('/') else { continue };
|
||||
while let Some(attachment) = stream.try_next().await? {
|
||||
let Some((mime_kind, _mime_type)) = attachment.media_type.split_once('/') else { continue };
|
||||
|
||||
let document_type = match mime_kind {
|
||||
"image" => apb::DocumentType::Image,
|
||||
"video" => apb::DocumentType::Video,
|
||||
"audio" => apb::DocumentType::Audio,
|
||||
"text" => apb::DocumentType::Page,
|
||||
_ => continue,
|
||||
};
|
||||
let document_type = match mime_kind {
|
||||
"image" => apb::DocumentType::Image,
|
||||
"video" => apb::DocumentType::Video,
|
||||
"audio" => apb::DocumentType::Audio,
|
||||
"text" => apb::DocumentType::Page,
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
tracing::info!("updating {} to {document_type}", attachment.url);
|
||||
let mut active = attachment.into_active_model();
|
||||
active.document_type = Set(document_type);
|
||||
active.update(&tx).await?;
|
||||
}
|
||||
tracing::info!("updating {} to {document_type}", attachment.url);
|
||||
let mut active = attachment.into_active_model();
|
||||
active.document_type = Set(document_type);
|
||||
active.update(&tx).await?;
|
||||
}
|
||||
|
||||
tracing::info!("committing transaction...");
|
||||
|
|
Loading…
Add table
Reference in a new issue