gpt4 book ai didi

file-upload - 帮助 AppleScript cURL 文件上传

转载 作者:行者123 更新时间:2023-12-04 06:40:13 25 4
gpt4 key购买 nike

这是一个示例 CURL,这是我用来尝试实现文件自动上传的示例。

curl http://testflightapp.com/api/builds.json 
-F file=@testflightapp.ipa
-F api_token='your_api_token'
-F team_token='your_team_token'
-F notes='This build was uploaded via the upload API'
-F notify=True
-F distribution_lists='Internal, QA'

我制作了一个 AppleScript,要求提供“注释”、文件以及是否通知:
property api_token : "SECRET"
property team_token : "SECRET"
property notify : "False"
property pathToIPA : ""
property whats_new : ""

set whats_new_prompt to (display dialog "What's new in this version?" default answer "")
set whats_new to text returned of whats_new_prompt

set pathToIPA to (choose file with prompt "Select IPA")

set pathToIPA to (pathToIPA as text)

set notify_question to display dialog "Notify testers?" buttons {"No", "Yes"} default button 2
set notify_answer to button returned of notify_question

if notify_answer is equal to "No" then
set notify to "False"
end if

if notify_answer is equal to "Yes" then
set notify to "True"
end if

uploadIPA(api_token, team_token, notify, whats_new, pathToIPA)

on uploadIPA(api_token, team_token, notify, whats_new, pathToIPA)
set TestFlightAPIUploadScript to "/usr/bin/curl" & ¬
" http://testflightapp.com/api/builds.json " & ¬
" –F " & "file=" & pathToIPA & ¬
" –F " & "api_token=" & api_token & ¬
" –F " & "team_token=" & team_token & ¬
" –F " & "notes=" & whats_new & ¬
" –F " & "notify=" & notify

set UploadResponse to do shell script TestFlightAPIUploadScript
return UploadResponse
if UploadResponse contains "Status: 200 OK" then
return "Success!"
else
return "Failure!"
end if
end uploadIPA

我似乎有问题的地方是文件位置。我不确定,但我认为它使用 : 而不是/作为路径返回错误的格式。

提前感谢您的任何建议。

最佳答案

获取形式为 /Users/you/file 的 POSIX 路径而不是 Macintosh HD:Users:you:file 的经典 Mac 风格路径,您可以使用 POSIX path of :set pathToIPA to POSIX path of pathToIPA .但是,您还应该按重要性顺序修复其他一些问题。

  • 使用 quoted form of对于进入 shell 的任何用户输入。否则,如果用户写 It's good. ,shell 将看到文字 ' .更糟糕的是,有人可以写 ; rm -rf ~ ,然后你会被冲洗掉。
  • 您不需要 property对于每个变量;他们真的是为了常量。
  • 你的命名不一致。很高兴看到 these_vars , theseVars , 或 TheseVars ,不是所有三个。一个相当小的点,虽然。一个类似的小点是您可以删除一些额外的变量,尽管这又是一个样式点。
  • 我不知道你想要哪个,但就在 return UploadResponse 之后,你有更多的代码。该代码不会运行,因为您刚刚返回。确保您只留下这些代码路径之一!

  • 你需要做#1;其他三件事绝对是可选的。即便如此,这就是我重写代码的方式:
    property api_token : "SECRET"
    property team_token : "SECRET"

    set whats_new to text returned of ¬
    (display dialog "What's new in this version?" default answer "")
    set path_to_IPA to POSIX path of (choose file with prompt "Select IPA")
    set notify_answer to button returned of ¬
    (display dialog "Notify testers?" buttons {"No", "Yes"} default button 2)
    if notify_answer is equal to "No" then
    set notify to "False"
    else if notify_answer is equal to "Yes" then
    set notify to "True"
    else
    error "\"Notify testers\" check failed."
    end if

    upload_IPA(api_token, team_token, notify, whats_new, path_to_IPA)

    on upload_IPA(api_token, team_token, notify, whats_new, path_to_IPA)
    set test_flight_API_upload_script to "/usr/bin/curl" & ¬
    " http://testflightapp.com/api/builds.json" & ¬
    -- add `@` to refer to the file itself not its path
    " -F " & "file=@" & quoted form of path_to_IPA & ¬
    " -F " & "api_token=" & quoted form of api_token & ¬
    " -F " & "team_token=" & quoted form of team_token & ¬
    " -F " & "notes=" & quoted form of whats_new & ¬
    " -F " & "notify=" & quoted form of notify

    set upload_response to do shell script test_flight_API_upload_script
    return upload_response
    -- Delete the above line or this if
    if upload_response contains "Status: 200 OK" then
    return "Success!"
    else
    return "Failure!"
    end if
    end upload_IPA

    关于file-upload - 帮助 AppleScript cURL 文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4346593/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com