Revert "Save remote post only when it doesn't exist on local"
This reverts commit 37cbf537bb
.
This commit is contained in:
parent
28380021a7
commit
af5674074d
@ -11,7 +11,7 @@ use plume_common::{
|
|||||||
utils::MediaProcessor,
|
utils::MediaProcessor,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
fs,
|
fs::{self, DirBuilder},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
@ -206,6 +206,10 @@ impl Media {
|
|||||||
pub fn from_activity(conn: &DbConn, image: &Image) -> Result<Media> {
|
pub fn from_activity(conn: &DbConn, image: &Image) -> Result<Media> {
|
||||||
let remote_url = image.object_props.url_string().ok()?;
|
let remote_url = image.object_props.url_string().ok()?;
|
||||||
let path = determine_mirror_file_path(&remote_url);
|
let path = determine_mirror_file_path(&remote_url);
|
||||||
|
let parent = path.parent()?;
|
||||||
|
if !parent.is_dir() {
|
||||||
|
DirBuilder::new().recursive(true).create(parent)?;
|
||||||
|
}
|
||||||
|
|
||||||
let mut dest = fs::File::create(path.clone()).ok()?;
|
let mut dest = fs::File::create(path.clone()).ok()?;
|
||||||
if let Some(proxy) = CONFIG.proxy() {
|
if let Some(proxy) = CONFIG.proxy() {
|
||||||
|
@ -637,7 +637,6 @@ impl FromId<DbConn> for Post {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let post = Self::from_db(conn, &article.object_props.id_string()?).or_else(|_| {
|
|
||||||
let cover = article
|
let cover = article
|
||||||
.object_props
|
.object_props
|
||||||
.icon_object::<Image>()
|
.icon_object::<Image>()
|
||||||
@ -645,7 +644,7 @@ impl FromId<DbConn> for Post {
|
|||||||
.and_then(|img| Media::from_activity(conn, &img).ok().map(|m| m.id));
|
.and_then(|img| Media::from_activity(conn, &img).ok().map(|m| m.id));
|
||||||
|
|
||||||
let title = article.object_props.name_string()?;
|
let title = article.object_props.name_string()?;
|
||||||
Self::insert(
|
let post = Post::insert(
|
||||||
conn,
|
conn,
|
||||||
NewPost {
|
NewPost {
|
||||||
blog_id: blog?.id,
|
blog_id: blog?.id,
|
||||||
@ -664,10 +663,7 @@ impl FromId<DbConn> for Post {
|
|||||||
source: article.ap_object_props.source_object::<Source>()?.content,
|
source: article.ap_object_props.source_object::<Source>()?.content,
|
||||||
cover_id: cover,
|
cover_id: cover,
|
||||||
},
|
},
|
||||||
)
|
)?;
|
||||||
})?;
|
|
||||||
|
|
||||||
// TODO: Update cover image if post's cover changes
|
|
||||||
|
|
||||||
for author in authors {
|
for author in authors {
|
||||||
PostAuthor::insert(
|
PostAuthor::insert(
|
||||||
|
Loading…
Reference in New Issue
Block a user