Method: Saber::Tracker::BIB#do_upload

Defined in:
lib/saber/tracker/bib.rb

#do_upload(file, info) ⇒ Boolean

Upload one torrent file to the site.

Parameters:

  • file (String)

    a filename

  • info (Optimism)

    comes from <file>.yml data file.

Returns:

  • (Boolean)

    result-code



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/saber/tracker/bib.rb', line 136

def do_upload(file, info)
  info["TorrentFile"] = "#{file}.torrent"

  agent.get("/upload/#{info.type}") {|p|
    ret = p.form_with(action: "") {|f|
      FIELDS[info.type].each {|k,t|
        f.set(t, "#{k}Field", info[k])
      }
    }.submit

    # error if return path is "/upload/<type>"
    if ret.uri.path == "/upload/#{info.type}"
      msg = nil
      if (err=ret.at("//*[@id='formerrorlist']"))
        # convert html to markdown for pretty print.
        msg = ReverseMarkdown.parse(err)
      else
        msg = ret.body
      end
      Saber.ui.error "ERROR:\n#{msg}"
      return false
    else
      return true
    end
  }
end