From cd5ca1f80373fa7a57379f64a93d0b35c0299e99 Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Mon, 24 Oct 2022 23:10:50 +0700 Subject: [PATCH 1/2] epub is an export format of Google Document mimeType is "application/epub+zip" --- lib/google_drive/util.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/google_drive/util.rb b/lib/google_drive/util.rb index 9a445c08..2d5676c9 100644 --- a/lib/google_drive/util.rb +++ b/lib/google_drive/util.rb @@ -27,6 +27,7 @@ module Util '.htm' => 'text/html', '.html' => 'text/html', '.zip' => 'application/zip', + '.epub' => 'application/epub+zip', '.swf' => 'application/x-shockwave-flash' }.freeze From dcdfd9e20b36ba877b926af0d5d4c5e01cff3978 Mon Sep 17 00:00:00 2001 From: y-bonfire Date: Thu, 31 Jul 2025 09:00:31 +0900 Subject: [PATCH 2/2] export as epub test --- test/test_google_drive_export.rb | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/test_google_drive_export.rb diff --git a/test/test_google_drive_export.rb b/test/test_google_drive_export.rb new file mode 100644 index 00000000..c19a209d --- /dev/null +++ b/test/test_google_drive_export.rb @@ -0,0 +1,34 @@ +# test/test_google_drive_export.rb + +$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib') +require 'yaml' + +require 'rubygems' +require 'bundler/setup' +require 'highline' +require 'test/unit' + +require 'google_drive' +require_relative 'test_helper' + +class TestGoogleDriveExport < Test::Unit::TestCase + include(SessionHelper) + + def test_upload_and_download + session = get_session + return unless auth_type == AuthType::USER_ACCOUNT + test_file_path = File.join(File.dirname(__FILE__), 'test_file.txt') + test_file_title = 'test_file_123.txt' + file = session.upload_from_file( + test_file_path, test_file_title, convert: true + ) + assert { file.is_a?(GoogleDrive::File) } + assert { file.title == "test_file_123" } + assert { file.available_content_types == [] } + assert { file.mime_type == 'application/vnd.google-apps.document' } + download_path = File.join(File.dirname(__FILE__), 'sample-epub-file-dl.epub') + file.export_as_file(download_path) + assert { File.exist?(download_path) } + File.delete(download_path) + end +end \ No newline at end of file