Class: Growi::ImageConverter::Esa
- Inherits:
-
Object
- Object
- Growi::ImageConverter::Esa
- Defined in:
- lib/growi/image_converter/esa.rb
Overview
img.esa.io の画像を GROWI にアタッチし直すクラス
Class Method Summary collapse
Instance Method Summary collapse
- #convert(dry_run: true) ⇒ Object
-
#initialize(client) ⇒ Esa
constructor
A new instance of Esa.
Constructor Details
#initialize(client) ⇒ Esa
Returns a new instance of Esa.
17 18 19 |
# File 'lib/growi/image_converter/esa.rb', line 17 def initialize(client) @client = client end |
Class Method Details
.get_image_from_esa(url, tempdir) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/growi/image_converter/esa.rb', line 8 def get_image_from_esa(url, tempdir) tmp_file = URI.parse(url).open image_file = File.open(tempdir + '/' + File.basename(URI.parse(url).path), 'w+b') image_file.write(tmp_file.read) image_file.rewind image_file end |
Instance Method Details
#convert(dry_run: true) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/growi/image_converter/esa.rb', line 21 def convert(dry_run: true) Signal.trap(:INT) { throw :exit_convert } catch :exit_convert do begin page_list = get_page_list rescue StandardError => e puts 'Error: ' + e. exit 1 end page_list.each do |page_summary| Dir.mktmpdir do |tempdir| begin page = Growi::ImageConverter::Page.new(page_summary._id, @client, dry_run: dry_run) page.body.scan_markdown_image_esa page.attach_files(page.body.group_by_url, tempdir) page.replace_markdown_image page.update rescue StandardError => e puts 'PageID: ' + page_summary._id + ', Result: Failed to convert' + ', Message: ' + e. next end end end end end |