0wQ / air724ug-forwarder

Air724UG 短信转发 & 来电通知 & 语音信箱
MIT License
289 stars 39 forks source link

大佬能否将demo中采用 multipart/form-data 上传文件的方式集成到里面,用作上传Alist网盘,这样就可以免费了 #19

Closed guiwushaonian closed 5 months ago

guiwushaonian commented 1 year ago

以下是从官方demo中找到的,但是奈何不会lua,调试半天也一直报错,不知哪里有问题

{"code":500,"message":"multipart: NextPart: EOF","data":null}

--如下示例代码是利用multipart/form-data模式,上传2参数和1个照片文件
--[[
local function postMultipartFormData(url,cert,params,timeout,cbFnc,rcvFileName)
    local boundary,body,k,v,kk,vv = "--------------------------"..os.time()..rtos.tick(),{}

    for k,v in pairs(params) do
        if k=="texts" then
            local bodyText = ""
            for kk,vv in pairs(v) do
                bodyText = bodyText.."--"..boundary.."\r\nContent-Disposition: form-data; name=\""..kk.."\"\r\n\r\n"..vv.."\r\n"
            end
            body[#body+1] = bodyText
        elseif k=="files" then
            local contentType =
            {
                jpg = "image/jpeg",
                jpeg = "image/jpeg",
                png = "image/png",                
            }
            for kk,vv in pairs(v) do
                print(kk,vv)
                body[#body+1] = "--"..boundary.."\r\nContent-Disposition: form-data; name=\""..kk.."\"; filename=\""..kk.."\"\r\nContent-Type: "..contentType[vv:match("%.(%w+)$")].."\r\n\r\n"
                body[#body+1] = {file = vv}
                body[#body+1] = "\r\n"
            end
        end
    end    
    body[#body+1] = "--"..boundary.."--\r\n"

    http.request(
        "POST",
        url,
        cert,
        {
            ["Content-Type"] = "multipart/form-data; boundary="..boundary,
            ["Connection"] = "keep-alive"
        },
        body,
        timeout,
        cbFnc,
        rcvFileName
        )    
end

postMultipartFormData(
    "1.202.80.121:4567/api/uploadimage",
    nil,
    {
        texts = 
        {
            ["imei"] = "862991234567890",
            ["time"] = "20180802180345"
        },

        files =
        {
            ["logo_color.jpg"] = "/ldata/logo_color.jpg"
        }
    },
    60000,
    cbFnc
)
]]
0wQ commented 1 year ago

简单写了一下,测试可以用了,还没写 auth 部分,有时间我再完善一下吧

-- 录音上传 alist 版本
local function upload_alist()
    local time = os.time()
    local date = os.date("*t", time)
    local date_str =
        table.concat(
        {
            date.year .. "/",
            string.format("%02d", date.month) .. "/",
            string.format("%02d", date.day) .. "/",
            string.format("%02d", date.hour) .. "-",
            string.format("%02d", date.min) .. "-",
            string.format("%02d", date.sec)
        },
        ""
    )
    -- alist 上传接口
    local base_url = "http://{改成自己的alist域名}"
    local url = base_url .. "/api/fs/put"
    -- 录音上传路径:  /xxx/record/18888888888/2022/12/12/12-00-00/10086_1668784328.wav
    local path = "/{改成自己的alist上传路径}/record/"
    path = path .. (sim.getNumber() or "unknown") .. "/"
    path = path .. date_str .. "/"
    path = path .. CALL_NUMBER .. "_" .. time .. "." .. record_extention

    record_upload_header["File-Path"] = path

    local function httpCallback(...)
        customHttpCallback(base_url .. path, ...)
    end

    sys.taskInit(http.request, "PUT", url, nil, record_upload_header, record_upload_body, 50000, httpCallback)
end
LintonGo commented 1 year ago

试了一下,可以了。感谢大佬!!! Thanks♪(・ω・)ノ 哈哈,看文档不仔细,只看到了表单上传文件接口,没有看到下面还有一个流式上传文件接口

LintonGo commented 1 year ago
配置项中新增一个Alist的token配置

UPLOAD_ALIST_TOKEN = "xxx"

handler_call.lua中修改,新增一个Authorization头

-- ALIST token
local alist_token = config.UPLOAD_ALIST_TOKEN

handler_call.lua中upload_list方法增加一个header头

record_upload_header["File-Path"] = path
record_upload_header["Authorization"] = alist_token

改了一下,采用token验证更安全一点

lfmwuy commented 11 months ago

其实设置无条件呼叫转移就可以了 实现短信收发就可以了 来电用无条件呼叫转移, 这样也能及时收到消息

0wQ commented 11 months ago

其实设置无条件呼叫转移就可以了 实现短信收发就可以了 来电用无条件呼叫转移, 这样也能及时收到消息

是的,通话录音我实际使用下来真的没有多少人会去用,大多都是听到提示音直接挂掉