Skip to content

Commit a81e49b

Browse files
committed
bugfix: correction save document by public, if has more size
1 parent d79c991 commit a81e49b

4 files changed

Lines changed: 25 additions & 13 deletions

File tree

.idea/dataSources.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

document_manager/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ utoipa = { version = "4.2.3", features = ["actix_extras", "non_strict_integers",
3131
utoipa-swagger-ui = { version = "7.1.0", features = ["actix-web"] }
3232
actix-web-lab = "0.20.2"
3333

34-
reqwest = { version = "0.11", features = ["blocking", "json"] }
34+
reqwest = { version = "0.11", features = ["blocking", "json", "stream"] }
3535
bytes = "1.7.1"
3636
mime_guess = "2.0.5"
3737

document_manager/src/operations/fs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ pub async fn save_file(to: PathBuf, content: &[u8]) -> Result<()> {
121121

122122
debug!("Saving file in: {:?}", to);
123123
let mut f = File::create(to).await?;
124-
let _ = f.write(content).await?;
125-
124+
f.write_all(content).await?;
125+
f.flush().await?;
126126
Ok(())
127127
}
128128

document_manager/src/operations/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub async fn save_document_by_url(params: SaveDocumentByUrlRequest,
9494
conn: &DbPool) -> Result<Uuid> {
9595
let conn = &mut conn.get().await?;
9696
let uuid_document = Uuid::new_v4();
97-
debug!("Generate UUID: {uuid_document}, to save document");
97+
info!("Generate UUID: {uuid_document}, to save document");
9898

9999

100100
let r = conn.transaction::<Uuid, Report, _>(|conn| {
@@ -106,7 +106,9 @@ pub async fn save_document_by_url(params: SaveDocumentByUrlRequest,
106106
let (filename, extension) = get_extension_and_file_name(file_name_in_url);
107107

108108
let mime_type = extension.map(get_content_type_by_extension);
109+
info!("Starting download file id_generated: {}, url: {}",uuid_document,params.url_file);
109110
let info_download = download_file(&params.url_file).await?;
111+
info!("Finish download file id_generated: {}, url: {}",uuid_document,params.url_file);
110112
let new_document = NewDocument {
111113
id_document: &uuid_document,
112114
name: filename,
@@ -122,7 +124,7 @@ pub async fn save_document_by_url(params: SaveDocumentByUrlRequest,
122124
.with_context(|| "Error create document")?;
123125

124126
if params.is_private_document {
125-
debug!("Document is private saving in database");
127+
info!("Document is private saving in database {uuid_document}");
126128
let content_file = read_content_bytes_to_base64(&info_download.content).await?;
127129
let content = NewContent {
128130
id_document: &uuid_document,
@@ -140,10 +142,10 @@ pub async fn save_document_by_url(params: SaveDocumentByUrlRequest,
140142
extension.unwrap_or(""),
141143
uuid_document,
142144
)?);
143-
debug!("Document is public saving in {:?}", new_path);
145+
info!("Document {uuid_document} is public saving in {:?}", new_path);
144146
save_file(new_path, &info_download.content).await?;
145147
}
146-
debug!("Finish procces save document");
148+
info!("Finish procces save document {uuid_document}");
147149
Ok(uuid_document)
148150
}
149151
.scope_boxed()
@@ -171,12 +173,10 @@ async fn download_file(url: &str) -> Result<DownloadFileInfo> {
171173

172174
if response.status().is_success() {
173175
let content = response.bytes().await?;
174-
info!("File downloaded");
175-
Ok(
176-
DownloadFileInfo {
177-
content,
178-
}
179-
)
176+
177+
Ok(DownloadFileInfo {
178+
content,
179+
})
180180
} else {
181181
error!("Error download file: {}", response.status());
182182
Err(Report::msg("Error download file"))

0 commit comments

Comments
 (0)