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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,10 @@ pub async fn get_document_id_by_attachment_id(
r#"
SELECT document_id
FROM document_email de
INNER JOIN "Document" d on de.document_id = d.id
INNER JOIN email_attachments ea on de.email_attachment_id = ea.id
INNER JOIN email_messages em on ea.message_id = em.id
WHERE em.link_id = $1 AND email_attachment_id = $2
WHERE em.link_id = $1 AND email_attachment_id = $2 AND d."deletedAt" IS NULL
"#,
link_id,
email_attachment_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub async fn handler(
&gmail_token,
&link,
&attachment_metadata,
false,
)
.await
.map_err(GetAttachmentDocumentIdError::UploadError)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub async fn backfill_attachment(
access_token,
link,
&p.metadata,
true,
)
.await
.map_err(|e| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ async fn handle_attachment_upload(
gmail_access_token,
link,
&attachment,
false,
)
.await
{
Expand Down
14 changes: 11 additions & 3 deletions rust/cloud-storage/email_service/src/util/upload_attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub async fn upload_attachment(
access_token: &str,
link: &link::Link,
p: &AttachmentUploadMetadata,
backfill: bool,
) -> anyhow::Result<String> {
// 1. Check rate limits before making a Gmail API call.
check_gmail_rate_limit(
Expand All @@ -41,8 +42,10 @@ pub async fn upload_attachment(
let (file_name, file_type) = determine_file_metadata(p)?;

// 5. Create the document record in DSS and get a presigned URL for the upload.
let dss_response =
create_dss_document_record(dss_client, link, p, &hex_hash, &file_name, &file_type).await?;
let dss_response = create_dss_document_record(
dss_client, link, p, &hex_hash, &file_name, &file_type, backfill,
)
.await?;

// 6. Upload the attachment data to the presigned URL.
upload_data_to_presigned_url(&dss_response, attachment_data, &base64_hash).await?;
Expand Down Expand Up @@ -115,7 +118,12 @@ async fn create_dss_document_record(
hex_hash: &str,
file_name: &str,
file_type: &str,
backfill: bool,
) -> anyhow::Result<CreateDocumentResponse> {
// if we are backfilling, use the email timestamp. if it's an on-demand upload, use the current
// time so the document shows up at the top of soup views.
let created_at = backfill.then_some(p.internal_date_ts);

let request = CreateDocumentRequest {
id: None,
sha: hex_hash.to_string(),
Expand All @@ -127,7 +135,7 @@ async fn create_dss_document_record(
branched_from_version_id: None,
job_id: None,
project_id: None,
created_at: Some(p.internal_date_ts),
created_at,
email_attachment_id: Some(p.attachment_db_id),
is_task: false,
};
Expand Down
Loading