fixed issue creating cache folder
fixed issues saving access token to file
This commit is contained in:
parent
baa03a4281
commit
d9cbb90575
|
@ -6,7 +6,7 @@ import PackageDescription
|
|||
let package = Package(
|
||||
name: "Seanut",
|
||||
platforms: [
|
||||
.macOS(.v10_15),
|
||||
.macOS(.v13),
|
||||
],
|
||||
products: [
|
||||
.executable(name: "seanut", targets: ["Seanut"])
|
||||
|
|
|
@ -21,18 +21,21 @@ extension Seanut {
|
|||
|
||||
mutating func run() async {
|
||||
Seanut.maybeSetLogger(options)
|
||||
|
||||
let seanutCacheFolder = "~/.seanut/".expandingTildeInPath
|
||||
|
||||
let seanutCacheFolder = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".seanut/")
|
||||
if !FileManager.default.fileExists(atPath: seanutCacheFolder.absoluteString) {
|
||||
if !FileManager.default.fileExists(atPath: seanutCacheFolder) {
|
||||
do {
|
||||
try FileManager.default.createDirectory(at: seanutCacheFolder, withIntermediateDirectories: false)
|
||||
try FileManager.default.createDirectory(
|
||||
at: URL(filePath: seanutCacheFolder),
|
||||
withIntermediateDirectories: false
|
||||
)
|
||||
} catch {
|
||||
fatalError("could not create seanut token cache folder. quitting...")
|
||||
}
|
||||
}
|
||||
|
||||
let client = APIClient(baseURL: options.domain.toURL()!)
|
||||
// Seanut.generateJellyfinConfiguration(url: options.domain.toURL()!)
|
||||
|
||||
await Seanut.getAccessToken(
|
||||
client: client,
|
||||
|
|
|
@ -72,12 +72,9 @@ struct Seanut: AsyncParsableCommand {
|
|||
|
||||
let domain = client.configuration.baseURL!
|
||||
let configuration = generateJellyfinConfiguration(url: domain)
|
||||
let fileName = FileManager.default
|
||||
.homeDirectoryForCurrentUser
|
||||
.appendingPathComponent(".seanut/\(domain)")
|
||||
let fileName = "~/.seanut/\(domain.host()!)".expandingTildeInPath
|
||||
|
||||
do {
|
||||
// FIXME: remove helper function "signIn" and call path directly
|
||||
let signIn: Request<AuthenticationResponse> = jellyfinRequest(
|
||||
result: AuthenticationResponse(),
|
||||
config: configuration,
|
||||
|
@ -87,8 +84,8 @@ struct Seanut: AsyncParsableCommand {
|
|||
)
|
||||
|
||||
let resp = try await client.send(signIn).value
|
||||
|
||||
try resp.accessToken!.write(to: fileName, atomically: false, encoding: .utf8)
|
||||
try resp.accessToken!.write(to: URL(filePath: fileName), atomically: false, encoding: .utf8)
|
||||
|
||||
print("Access token retrieved ☑️")
|
||||
} catch {
|
||||
print("Failed to login with provided credentials. please try again later.")
|
||||
|
|
Loading…
Reference in New Issue