final fixes for linux

This commit is contained in:
a. fox 2024-02-29 22:16:13 -05:00
parent 54f71ce23f
commit 637f011814
5 changed files with 33 additions and 8 deletions

View File

@ -6,7 +6,7 @@ import PackageDescription
let package = Package(
name: "Seanut",
platforms: [
.macOS(.v13),
.macOS(.v10_15),
],
products: [
.executable(name: "seanut", targets: ["Seanut"])

15
Sources/APIClient.swift Normal file
View File

@ -0,0 +1,15 @@
// APIClient.swift
import Foundation
import Get
extension APIClient {
#if os(Linux)
public func download<T>(for request: Request<T>, to location: URL) async throws {
let data = try await data(for: request).value
try data.write(to: location)
}
#endif
}

View File

@ -62,7 +62,11 @@ extension Seanut {
config: DownloadCommand.config,
path: "/Items",
method: .get,
query: [("userId", DownloadCommand.userId!), ("parentId", id)]
query: [
("userId", DownloadCommand.userId!),
("parentId", id),
("fields", "Path,ChildCount")
]
)
guard let childInfo = try? await DownloadCommand.client.send(childReq).value.items else {
return
@ -75,11 +79,11 @@ extension Seanut {
}
} else {
let pathUrl = URL(string: rootInfo.path!)!
Seanut.Logger?.info("Downloading \(rootInfo.name!)...")
let pathUrl = URL(fileURLWithPath: rootInfo.path!)
let itemName: String = rootInfo.name! + "." + pathUrl.pathExtension
let filePath = outputPath.appendingPathComponent(itemName.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!)
Seanut.Logger?.info("Downloading \(rootInfo.name!)...")
await downloadItem(id: id, outputPath: filePath)
}
}
@ -92,9 +96,15 @@ extension Seanut {
path: "/Items/\(id)/Download",
method: .get
)
let response = try await DownloadCommand.client.download(for: dlReq)
#if os(Linux)
try await DownloadCommand.client.download(for: dlReq, to: outputPath)
#else
let response = try await DownloadCommand.client.download(for: dlReq)
try FileManager.default.moveItem(at: response.location, to: outputPath)
#endif
} catch {
fatalError("Encountered \(error) downloading media. Please try again later.")
}

View File

@ -27,7 +27,7 @@ extension Seanut {
if !FileManager.default.fileExists(atPath: seanutCacheFolder) {
do {
try FileManager.default.createDirectory(
at: URL(filePath: seanutCacheFolder),
at: URL(fileURLWithPath: seanutCacheFolder),
withIntermediateDirectories: false
)
} catch {

View File

@ -72,7 +72,7 @@ struct Seanut: AsyncParsableCommand {
let domain = client.configuration.baseURL!
let configuration = generateJellyfinConfiguration(url: domain)
let fileName = "~/.seanut/\(domain.host()!)".expandingTildeInPath
let fileName = "~/.seanut/\(domain.host!)".expandingTildeInPath
do {
let signIn: Request<AuthenticationResponse> = jellyfinRequest(
@ -84,7 +84,7 @@ struct Seanut: AsyncParsableCommand {
)
let resp = try await client.send(signIn).value
try resp.accessToken!.write(to: URL(filePath: fileName), atomically: false, encoding: .utf8)
try resp.accessToken!.write(to: URL(fileURLWithPath: fileName), atomically: false, encoding: .utf8)
print("Access token retrieved ☑️")
} catch {