File: photo.rb

package info (click to toggle)
mikutter 5.0.4%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 9,700 kB
  • sloc: ruby: 21,307; sh: 181; makefile: 19
file content (33 lines) | stat: -rw-r--r-- 805 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# -*- coding: utf-8 -*-

module Plugin::Openimg
  class Photo < Diva::Model
    include Diva::Model::PhotoMixin
    register :openimg_photo, name: Plugin[:openimg]._('画像ビューア')

    field.uri    :perma_link

    handle ->uri{
      uri_str = uri.to_s
      openers = Plugin.collect(:openimg_image_openers)
      openers.any?{ |opener| opener.condition === uri_str } if !openers.first(1).empty?
    } do |uri|
      new(perma_link: uri)
    end

    private

    def download_routine
      _, raw = Plugin.filtering(:openimg_raw_image_from_display_url, perma_link.to_s, nil)
      if raw
        download_mainloop(raw)
      else
        raise "couldn't resolve actual image url of #{perma_link}."
      end
    rescue EOFError
      true
    ensure
      raw.close rescue nil
    end
  end
end