プロジェクト

全般

プロフィール

0001-Retriever-URI-URI-uri_filter-refs-954.patch

toshi_a 初音, 2017-10-13 09:08

差分を表示:

core/lib/retriever/uri.rb
118 118
  end
119 119

  
120 120
  def generate_uri_by_string
121
    URI.parse(@uri_string)
122
  rescue URI::InvalidComponentError
123
    Addressable::URI.parse(@uri_string)
121
    uri, = Plugin.filtering(:uri_filter, @uri_string)
122
    case uri
123
    when URI, Addressable::URI
124
      uri
125
    when String
126
      raise Retriever::InvalidURIError, 'The string is not URI.'
127
    else
128
      raise Retriever::InvalidURIError, "Filter `uri_filter' returns instance of `#{uri.class}', but expect URI or Addressable::URI."
129
    end
124 130
  end
125 131

  
126 132
  def generate_uri_by_hash
core/plugin/photo/model/photo.rb
16 16
      case uri
17 17
      when self
18 18
        uri
19
      when URI, Addressable::URI, Retriever::URI
19
      when URI, Addressable::URI, Retriever::URI, String
20 20
        photos[uri.to_s.hash] ||= new(perma_link: uri)
21
      when String
22
        if uri.start_with?('http')
23
          photos[uri.hash] ||= new(perma_link: uri)
24
        elsif uri.start_with?('/')
25
          uri = Retriever::URI.new(scheme: 'file', path: uri)
26
          photos[uri.hash] ||= new(perma_link: uri)
27
        end
28 21
      end
29 22
    end
30 23

  
core/plugin/photo/photo.rb
10 10
    photos << Plugin::Photo::Photo[permalink]
11 11
    [permalink, photos]
12 12
  end
13

  
14
  # Generic URI
15
  filter_uri_filter do |uri|
16
    if uri.is_a?(String) && uri.match(%r<\A\w+:>)
17
      [Addressable::URI.parse(uri)]
18
    else
19
      [uri]
20
    end
21
  end
22

  
23
  # Unix local file path
24
  filter_uri_filter do |uri|
25
    if uri.is_a?(String) && uri.start_with?('/')
26
      [Addressable::URI.new(scheme: 'file', path: uri)]
27
    else
28
      [uri]
29
    end
30
  end
13 31
end
14 32

  
15
-