Changeset 2379


Ignore:
Timestamp:
Sep 18, 2014, 2:17:57 PM (4 years ago)
Author:
matthijs
Message:

uploadd: Switch Flickr upload to use HTTPS

The API is no longer available over HTTP, using TLS is no mandatory.

In addition to switching the urls, the actual upload code needed some
changes, since nixio.sendfile only operates on real sockets (with
OS-level file descriptors), which breaks on the socket-like object that
the tls library makes available.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/luci/libs/uploadd/luasrc/fon/flickr.lua

    r2378 r2379  
    3131        local file = fs.basename(filename)
    3232        local disposition = content_disposition()
    33         local uri = "http://api.flickr.com/services/upload/"
     33        local uri = "https://api.flickr.com/services/upload/"
    3434        local privacy = ((uci:get("flickr", "flickr", "privacy") == "0") and "1" or "0")
    3535        local sig = flickr.sign("api_key"..api_key.."auth_token"..auth_token.."content_type1is_family"..privacy.."is_friend"..privacy.."is_public"..privacy.."safety_level1")
     
    7272                local file = nixio.open(filename)
    7373                local sent, code, msg
    74                 repeat
    75                         sent, code, msg = nixio.sendfile(socket, file, 65536)
    76                         sent_size = sent_size + sent
    77                         local perc = math.floor((sent_size * 1000)/ full_size) / 10
    78                         uci:revert("uploadd", section, "progress")
    79                         uci:set("uploadd", section, "progress", perc)
    80                         uci:save("uploadd")
    81                 until not sent or sent == 0
    82                 if not sent then
    83                         return nil, code, msg
     74                while true do
     75                        data, code, msg = file:read(65536)
     76                        if not data then
     77                                return nil, code, msg
     78                        elseif #data == 0 then
     79                                break
     80                        else
     81                                socket:writeall(data)
     82                                sent_size = sent_size + #data
     83                                local perc = math.floor((sent_size * 1000)/ full_size) / 10
     84                                uci:revert("uploadd", section, "progress")
     85                                uci:set("uploadd", section, "progress", perc)
     86                                uci:save("uploadd")
     87                        end
    8488                end
    8589                socket:writeall(footer)
     
    118122function create_album(name, pid)
    119123        local httpc = require "luci.httpclient"
    120         local uri = "http://api.flickr.com/services/rest/"
     124        local uri = "https://api.flickr.com/services/rest/"
    121125
    122126        local sig = flickr.sign("api_key"..api_key.."title"..name.."description"..name.."primary_photo_id"..pid.."methodflickr.photosets.create")
     
    147151        end
    148152        local httpc = require "luci.httpclient"
    149         local uri = "http://www.flickr.com/services/rest/"
     153        local uri = "https://www.flickr.com/services/rest/"
    150154        local sig = flickr.sign("api_key"..api_key.."methodflickr.auth.getFullTokenmini_token"..frob)
    151155        local query = "api_key="..api_key.."&method=flickr.auth.getFullToken&mini_token="..frob.."&api_sig="..sig
Note: See TracChangeset for help on using the changeset viewer.