Skip to content

Commit

Permalink
Return URL
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacMarovitz committed Jun 19, 2023
1 parent 04f6040 commit 13753b8
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions Whisky/Utils/WineDownload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,41 @@
import Foundation

class WineDownload {
static func getLatestWine() async {
static func getLatestWineURL() async -> URL? {
let githubURL = "https://api.github.com/repos/IsaacMarovitz/WhiskyBuilder/actions/artifacts"
if let artifactsURL = URL(string: githubURL) {
URLSession.shared.dataTask(with: URLRequest(url: artifactsURL)) { data, _, error in
do {
if error == nil, let data = data {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
let artifacts: Artifacts = try decoder.decode(Artifacts.self, from: data)
// We gotta turn the URL into a nightly.link URL
if let latest = artifacts.artifacts.first {
var url = latest.url
url.replace("https://api.github.com/repos/", with: "https://nightly.link/")
let selection = "actions/"
if let range = url.range(of: selection) {
url = String(url[..<range.upperBound])
url += "runs/\(latest.workflowRun.id)/\(latest.name).zip"
print(url)
return await withCheckedContinuation { continuation in
URLSession.shared.dataTask(with: URLRequest(url: artifactsURL)) { data, _, error in
do {
if error == nil, let data = data {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
let artifacts: Artifacts = try decoder.decode(Artifacts.self, from: data)
// We gotta turn the URL into a nightly.link URL
if let latest = artifacts.artifacts.first {
var url = latest.url
url.replace("https://api.github.com/repos/", with: "https://nightly.link/")
let selection = "actions/"
if let range = url.range(of: selection) {
url = String(url[..<range.upperBound])
url += "runs/\(latest.workflowRun.id)/\(latest.name).zip"
continuation.resume(returning: URL(string: url))
return
}
}
}
} catch {
print(error)
}
} catch {
print(error)
}
}.resume()
continuation.resume(returning: nil)
}.resume()
}
}
return nil
}

static func downloadWine(from: URL) async {

}
}

Expand Down

0 comments on commit 13753b8

Please sign in to comment.