有关 AppleScript cURL 文件上传的帮助

发布于 2024-10-06 08:37:19 字数 2014 浏览 6 评论 0原文

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

curl http://testflightapp.com/api/builds.json 
  -F [email protected] 
  -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

我似乎遇到问题的是文件位置。我不确定,但我认为它返回了错误的格式:路径而不是 / 。

预先感谢您的任何建议。

This is a sample CURL, which is what I am using to try and achieve an automatic upload of a file.

curl http://testflightapp.com/api/builds.json 
  -F [email protected] 
  -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'

I have made an AppleScript that asks for "notes", the file and whether to notify:

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

Where I seem to have problems is with the file location. I am not sure, but I think it's returning the wrong format with : instead of / for the path.

Thanks in advance for any advice.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖阳 2024-10-13 08:37:19

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

  1. 对进入 shell 的任何用户输入使用带引号的形式。否则,如果用户写 It's good.,shell 将看到文字 '。更糟糕的是,有人可以编写 ; rm -rf ~,然后您就会被淹没。

  2. 您不需要为每个变量都有一个属性;它们实际上是针对常量的。

  3. 你的命名不一致。最好只看到 these_varstheseVarsTheseVars,而不是全部三个。不过,这是一个相当小的问题。一个类似的小问题是,您可以删除一些额外的变量,尽管这又是一个样式点。

  4. 我不知道您想要哪个,但是在返回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

To get a POSIX path of the form /Users/you/file instead of the classic Mac style path of Macintosh HD:Users:you:file, you can use POSIX path of: set pathToIPA to POSIX path of pathToIPA. However, there are a couple of other things you should fix, in order of importance.

  1. Use quoted form of for any user input which goes to the shell. Otherwise, if the user writes It's good., the shell will see the literal '. Worse, someone could write ; rm -rf ~, and then you'd be hosed.

  2. You don't need a property for every variable; they're really for constants.

  3. You're inconsistent with your naming. It'd be nice to just see these_vars, theseVars, or TheseVars, not all three. A rather minor point, though. A similarly minor point is that you can remove some extra variables, though this is again a style point.

  4. I don't know which you meant to have, but right after return UploadResponse, you have more code. That code won't run, because you just returned. Make sure you only leave one of those code paths!

You need to do #1; the other three things are definitely optional. Even so, this is how I'd rewrite the code:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文