This commit is contained in:
2022-07-15 07:11:32 +00:00
committed by GitHub
parent 2e3761a758
commit 26f2bb32bd
7 changed files with 193 additions and 15 deletions

View File

@@ -6,27 +6,31 @@ use crate::exif::ExifTypeID;
use crate::exif::ExifValue;
use crate::ext::try_err::TryErr;
use crate::parser::description::parse_description;
use proc_macros::call_parent_data_source_fun;
use proc_macros::define_exif_data_source;
use std::convert::TryFrom;
use std::ffi::OsStr;
use utf16string::LittleEndian;
use utf16string::WString;
pub trait ExifDataSource {
fn image_author(&self) -> Option<String> {
None
}
define_exif_data_source!("src/data/exif_data_source.json");
}
fn image_comment(&self) -> Option<String> {
None
}
impl<T: ExifDataSource> ExifDataSource for std::sync::Arc<T> {
call_parent_data_source_fun!("src/data/exif_data_source.json", *self,);
}
fn image_id(&self) -> Option<String> {
None
}
fn image_title(&self) -> Option<String> {
None
}
impl<T: ExifDataSource> ExifDataSource for Option<T> {
call_parent_data_source_fun!(
"src/data/exif_data_source.json",
match self {
Some(data) => data,
None => {
return None;
}
},
);
}
fn add_image_id<D: ExifDataSource>(data: &mut ExifData, d: &D) -> Result<(), ()> {

View File

@@ -0,0 +1,6 @@
{
"image_author": { "return": "String", "description": "The author of the image." },
"image_comment": { "return": "String", "description": "The comment of the image." },
"image_id": { "return": "String", "description": "The image id." },
"image_title": { "return": "String", "description": "The title of the image." }
}

View File

@@ -1,12 +1,18 @@
#[cfg(feature = "exif")]
use super::exif::ExifDataSource;
use crate::fanbox::post::FanboxPost;
use crate::pixiv_link::PixivID;
use crate::pixiv_link::ToPixivID;
use json::JsonValue;
#[cfg(feature = "exif")]
use proc_macros::call_parent_data_source_fun;
pub struct FanboxData {
pub id: PixivID,
/// Raw data
pub raw: JsonValue,
#[cfg(feature = "exif")]
pub exif_data: Option<Box<dyn ExifDataSource>>,
}
impl FanboxData {
@@ -15,8 +21,28 @@ impl FanboxData {
Some(id) => Some(Self {
id,
raw: post.get_json().clone(),
#[cfg(feature = "exif")]
exif_data: None,
}),
None => None,
}
}
}
#[cfg(feature = "exif")]
impl ExifDataSource for FanboxData {
call_parent_data_source_fun!(
"src/data/exif_data_source.json",
match &self.exif_data {
Some(d) => d,
None => {
return None;
}
},
image_id,
);
fn image_id(&self) -> Option<String> {
Some(self.id.to_link())
}
}