diff --git a/R/utils-paths.R b/R/utils-paths.R index 6b1b0f8b0..ec0caeed0 100644 --- a/R/utils-paths.R +++ b/R/utils-paths.R @@ -181,6 +181,9 @@ file_ext_safe <- function(x) { ## add an extension if it is not already present apply_extension <- function(path, ext) { + if (is.na(ext) || ext == "") { + return(path) + } ext_orig <- file_ext_safe(path) if (!identical(ext, ext_orig)) { path <- paste(path, ext, sep = ".") diff --git a/data-raw/extension-mime-type-defaults.csv b/data-raw/extension-mime-type-defaults.csv index e41a2eb1b..5e927d75c 100644 --- a/data-raw/extension-mime-type-defaults.csv +++ b/data-raw/extension-mime-type-defaults.csv @@ -25,4 +25,5 @@ text/csv,csv application/vnd.oasis.opendocument.presentation,odp text/richtext,rtx application/zip,zip -image/svg+xml,svg \ No newline at end of file +image/svg+xml,svg +text/markdown,md diff --git a/inst/extdata/data/mime_tbl.csv b/inst/extdata/data/mime_tbl.csv index 843202072..ffa700657 100644 --- a/inst/extdata/data/mime_tbl.csv +++ b/inst/extdata/data/mime_tbl.csv @@ -1,32 +1,37 @@ mime_type,ext,description,human_type,default -application/epub+zip,NA,NA,NA,NA +application/epub+zip,epub,NA,epub,FALSE application/msword,doc,NA,doc,TRUE -application/msword,dot,NA,dot,FALSE application/pdf,pdf,NA,pdf,TRUE application/rtf,rtf,NA,rtf,TRUE application/vnd.google-apps.audio,NA,NA,audio,NA application/vnd.google-apps.document,NA,Google Docs,document,NA -application/vnd.google-apps.drawing,NA,Google Drawing,drawing,NA -application/vnd.google-apps.drive-sdk,NA,3rd party shortcut,drive-sdk,NA +application/vnd.google-apps.drawing,NA,Google Drawings,drawing,NA +application/vnd.google-apps.drive-sdk,NA,Third-party shortcut,drive-sdk,NA application/vnd.google-apps.file,NA,Google Drive file,file,NA application/vnd.google-apps.folder,NA,Google Drive folder,folder,NA application/vnd.google-apps.form,NA,Google Forms,form,NA application/vnd.google-apps.fusiontable,NA,Google Fusion Tables,fusiontable,NA +application/vnd.google-apps.jam,NA,Google Jamboard,jam,NA +application/vnd.google-apps.mail-layout,NA,Email layout,mail-layout,NA application/vnd.google-apps.map,NA,Google My Maps,map,NA -application/vnd.google-apps.photo,NA,NA,photo,NA +application/vnd.google-apps.photo,NA,Google Photos,photo,NA application/vnd.google-apps.presentation,NA,Google Slides,presentation,NA -application/vnd.google-apps.script,NA,Google Apps Scripts,script,NA +application/vnd.google-apps.script,NA,Google Apps Script,script,NA application/vnd.google-apps.script+json,NA,NA,script+json,NA application/vnd.google-apps.script+text/plain,NA,NA,script+text/plain,NA application/vnd.google-apps.shortcut,NA,Shortcut,shortcut,NA application/vnd.google-apps.site,NA,Google Sites,site,NA application/vnd.google-apps.spreadsheet,NA,Google Sheets,spreadsheet,NA application/vnd.google-apps.unknown,NA,NA,unknown,NA +application/vnd.google-apps.vid,NA,Google Vids,vid,NA application/vnd.google-apps.video,NA,NA,video,NA application/vnd.google.colab,ipynb,Colab notebook,colab,TRUE -application/vnd.ms-excel,xlb,NA,xlb,FALSE +application/vnd.ms-excel,xla,NA,xla,FALSE +application/vnd.ms-excel,xlc,NA,xlc,FALSE +application/vnd.ms-excel,xlm,NA,xlm,FALSE application/vnd.ms-excel,xls,NA,xls,TRUE application/vnd.ms-excel,xlt,NA,xlt,FALSE +application/vnd.ms-excel,xlw,NA,xlw,FALSE application/vnd.ms-excel.sheet.macroenabled.12,NA,NA,NA,NA application/vnd.ms-excel.template.macroenabled.12,NA,NA,NA,NA application/vnd.ms-powerpoint,pps,NA,pps,FALSE @@ -52,8 +57,9 @@ application/x-vnd.oasis.opendocument.presentation,NA,NA,NA,NA application/x-vnd.oasis.opendocument.spreadsheet,NA,NA,NA,NA application/x-vnd.oasis.opendocument.text,NA,NA,NA,NA application/zip,zip,NA,zip,TRUE -image/bmp,NA,NA,NA,NA +image/bmp,bmp,NA,bmp,FALSE image/gif,gif,NA,gif,TRUE +image/jpeg,jfif,NA,jfif,FALSE image/jpeg,jpe,NA,jpe,FALSE image/jpeg,jpeg,NA,jpeg,TRUE image/jpeg,jpg,NA,jpg,FALSE @@ -68,12 +74,17 @@ text/csv,csv,NA,csv,TRUE text/html,htm,NA,htm,FALSE text/html,html,NA,html,TRUE text/html,shtml,NA,shtml,FALSE -text/plain,asc,NA,asc,FALSE +text/markdown,markdown,NA,markdown,FALSE +text/markdown,md,NA,md,TRUE text/plain,brf,NA,brf,FALSE text/plain,pot,NA,pot,FALSE text/plain,srt,NA,srt,FALSE text/plain,text,NA,text,FALSE text/plain,txt,NA,txt,TRUE -text/richtext,rtx,NA,rtx,TRUE +text/richtext,NA,NA,NA,NA text/rtf,NA,NA,NA,NA text/tab-separated-values,tsv,NA,tsv,TRUE +text/x-markdown,NA,NA,NA,NA +video/mp4,m4v,NA,m4v,FALSE +video/mp4,mp4,NA,mp4,FALSE +video/mp4,mpg4,NA,mpg4,FALSE diff --git a/inst/extdata/data/translate_mime_types.csv b/inst/extdata/data/translate_mime_types.csv index 9b388663c..2cc2c6fc3 100644 --- a/inst/extdata/data/translate_mime_types.csv +++ b/inst/extdata/data/translate_mime_types.csv @@ -6,13 +6,16 @@ export,application/vnd.google-apps.document,application/vnd.oasis.opendocument.t export,application/vnd.google-apps.document,application/vnd.openxmlformats-officedocument.wordprocessingml.document,TRUE export,application/vnd.google-apps.document,application/zip,FALSE export,application/vnd.google-apps.document,text/html,FALSE +export,application/vnd.google-apps.document,text/markdown,FALSE export,application/vnd.google-apps.document,text/plain,FALSE +export,application/vnd.google-apps.document,text/x-markdown,FALSE export,application/vnd.google-apps.drawing,application/pdf,FALSE export,application/vnd.google-apps.drawing,image/jpeg,FALSE export,application/vnd.google-apps.drawing,image/png,TRUE export,application/vnd.google-apps.drawing,image/svg+xml,FALSE export,application/vnd.google-apps.form,application/zip,TRUE export,application/vnd.google-apps.jam,application/pdf,FALSE +export,application/vnd.google-apps.mail-layout,text/plain,FALSE export,application/vnd.google-apps.presentation,application/pdf,FALSE export,application/vnd.google-apps.presentation,application/vnd.oasis.opendocument.presentation,FALSE export,application/vnd.google-apps.presentation,application/vnd.openxmlformats-officedocument.presentationml.presentation,TRUE @@ -26,6 +29,7 @@ export,application/vnd.google-apps.spreadsheet,application/x-vnd.oasis.opendocum export,application/vnd.google-apps.spreadsheet,application/zip,FALSE export,application/vnd.google-apps.spreadsheet,text/csv,FALSE export,application/vnd.google-apps.spreadsheet,text/tab-separated-values,FALSE +export,application/vnd.google-apps.vid,video/mp4,FALSE import,application/vnd.google-apps.document,application/msword,NA import,application/vnd.google-apps.document,application/pdf,NA import,application/vnd.google-apps.document,application/rtf,NA @@ -45,9 +49,11 @@ import,application/vnd.google-apps.document,image/png,NA import,application/vnd.google-apps.document,image/x-bmp,NA import,application/vnd.google-apps.document,image/x-png,NA import,application/vnd.google-apps.document,text/html,NA +import,application/vnd.google-apps.document,text/markdown,NA import,application/vnd.google-apps.document,text/plain,NA import,application/vnd.google-apps.document,text/richtext,NA import,application/vnd.google-apps.document,text/rtf,NA +import,application/vnd.google-apps.document,text/x-markdown,NA import,application/vnd.google-apps.drawing,application/x-msmetafile,NA import,application/vnd.google-apps.presentation,application/vnd.ms-powerpoint,NA import,application/vnd.google-apps.presentation,application/vnd.ms-powerpoint.presentation.macroenabled.12,NA diff --git a/tests/testthat/_snaps/drive_download.md b/tests/testthat/_snaps/drive_download.md index 34673f94c..67f064088 100644 --- a/tests/testthat/_snaps/drive_download.md +++ b/tests/testthat/_snaps/drive_download.md @@ -55,3 +55,13 @@ Saved locally as: * '{download_filename}' +# drive_download() respects `path` when `type` specified and no default extension + + Code + write_utf8(drive_download_message) + Output + File downloaded: + * '{file_to_download}' + Saved locally as: + * '{download_filename}' + diff --git a/tests/testthat/test-drive_download.R b/tests/testthat/test-drive_download.R index 8afed45f7..8afc836b4 100644 --- a/tests/testthat/test-drive_download.R +++ b/tests/testthat/test-drive_download.R @@ -147,3 +147,34 @@ test_that("drive_download() converts using default MIME type, if necessary", { expect_true(file.exists(file.path(tmpdir, download_filename))) }) + +test_that("drive_download() respects `path` when `type` specified and no default extension", { + skip_if_no_token() + skip_if_offline() + + file_to_download <- nm_("DESC-doc") + tmpdir <- withr::local_tempdir(file_to_download) + download_filename <- paste0(file_to_download, ".md") + local_drive_loud_and_wide() + + drive_download_message <- capture.output( + withr::with_dir( + tmpdir, + drive_download( + file = file_to_download, + type = "text/x-markdown", + path = download_filename + ) + ), + type = "message" + ) + drive_download_message <- drive_download_message %>% + scrub_filepath(download_filename) %>% + scrub_filepath(file_to_download) %>% + scrub_file_id() + expect_snapshot( + write_utf8(drive_download_message) + ) + + expect_true(file.exists(file.path(tmpdir, download_filename))) +})