Skip to content

Commit 1325855

Browse files
authored
Add a field mime_type for GoogleDrive source. (#172)
#108
1 parent c56a9fa commit 1325855

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/base/value.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,15 @@ impl From<FieldValues> for Value {
395395
}
396396
}
397397

398+
impl<T: Into<Value>> From<Option<T>> for Value {
399+
fn from(value: Option<T>) -> Self {
400+
match value {
401+
Some(v) => v.into(),
402+
None => Value::Null,
403+
}
404+
}
405+
}
406+
398407
impl<VS> Value<VS> {
399408
pub fn from_alternative<AltVS>(value: Value<AltVS>) -> Self
400409
where

src/ops/sources/google_drive.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl SourceExecutor for Executor {
196196
.doit()
197197
.await?;
198198

199-
let resp_body = if let Some(export_mime_type) = file
199+
let (mime_type, resp_body) = if let Some(export_mime_type) = file
200200
.mime_type
201201
.as_ref()
202202
.and_then(|mime_type| EXPORT_MIME_TYPES.get(mime_type.as_str()))
@@ -206,13 +206,15 @@ impl SourceExecutor for Executor {
206206
} else {
207207
export_mime_type.text
208208
};
209-
self.drive_hub
209+
let content = self
210+
.drive_hub
210211
.files()
211212
.export(&file_id, target_mime_type)
212213
.add_scope(Scope::Readonly)
213214
.doit()
214215
.await?
215-
.into_body()
216+
.into_body();
217+
(Some(target_mime_type.to_string()), content)
216218
} else {
217219
let (resp, _) = self
218220
.drive_hub
@@ -222,11 +224,12 @@ impl SourceExecutor for Executor {
222224
.param("alt", "media")
223225
.doit()
224226
.await?;
225-
resp.into_body()
227+
(file.mime_type, resp.into_body())
226228
};
227229
let content = resp_body.collect().await?;
228230
let mut fields = Vec::with_capacity(2);
229231
fields.push(file.name.unwrap_or_default().into());
232+
fields.push(mime_type.into());
230233
if self.binary {
231234
fields.push(content.to_bytes().to_vec().into());
232235
} else {
@@ -261,6 +264,7 @@ impl SourceFactoryBase for Factory {
261264
vec![
262265
FieldSchema::new("file_id", make_output_type(BasicValueType::Str)),
263266
FieldSchema::new("filename", make_output_type(BasicValueType::Str)),
267+
FieldSchema::new("mime_type", make_output_type(BasicValueType::Str)),
264268
FieldSchema::new(
265269
"content",
266270
make_output_type(if spec.binary {

0 commit comments

Comments
 (0)