Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/base/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,15 @@ impl From<FieldValues> for Value {
}
}

impl<T: Into<Value>> From<Option<T>> for Value {
fn from(value: Option<T>) -> Self {
match value {
Some(v) => v.into(),
None => Value::Null,
}
}
}

impl<VS> Value<VS> {
pub fn from_alternative<AltVS>(value: Value<AltVS>) -> Self
where
Expand Down
12 changes: 8 additions & 4 deletions src/ops/sources/google_drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl SourceExecutor for Executor {
.doit()
.await?;

let resp_body = if let Some(export_mime_type) = file
let (mime_type, resp_body) = if let Some(export_mime_type) = file
.mime_type
.as_ref()
.and_then(|mime_type| EXPORT_MIME_TYPES.get(mime_type.as_str()))
Expand All @@ -206,13 +206,15 @@ impl SourceExecutor for Executor {
} else {
export_mime_type.text
};
self.drive_hub
let content = self
.drive_hub
.files()
.export(&file_id, target_mime_type)
.add_scope(Scope::Readonly)
.doit()
.await?
.into_body()
.into_body();
(Some(target_mime_type.to_string()), content)
} else {
let (resp, _) = self
.drive_hub
Expand All @@ -222,11 +224,12 @@ impl SourceExecutor for Executor {
.param("alt", "media")
.doit()
.await?;
resp.into_body()
(file.mime_type, resp.into_body())
};
let content = resp_body.collect().await?;
let mut fields = Vec::with_capacity(2);
fields.push(file.name.unwrap_or_default().into());
fields.push(mime_type.into());
if self.binary {
fields.push(content.to_bytes().to_vec().into());
} else {
Expand Down Expand Up @@ -261,6 +264,7 @@ impl SourceFactoryBase for Factory {
vec![
FieldSchema::new("file_id", make_output_type(BasicValueType::Str)),
FieldSchema::new("filename", make_output_type(BasicValueType::Str)),
FieldSchema::new("mime_type", make_output_type(BasicValueType::Str)),
FieldSchema::new(
"content",
make_output_type(if spec.binary {
Expand Down