2025-12-12 21:18:46 +00:00
|
|
|
import Foundation
|
|
|
|
|
|
2026-01-30 03:15:10 +01:00
|
|
|
public enum OpenClawNodeStorage {
|
2025-12-12 21:18:46 +00:00
|
|
|
public static func appSupportDir() throws -> URL {
|
2026-01-18 20:46:29 +01:00
|
|
|
let base = FileManager().urls(for: .applicationSupportDirectory, in: .userDomainMask).first
|
2025-12-12 21:18:46 +00:00
|
|
|
guard let base else {
|
2026-01-30 03:15:10 +01:00
|
|
|
throw NSError(domain: "OpenClawNodeStorage", code: 1, userInfo: [
|
2025-12-12 21:18:46 +00:00
|
|
|
NSLocalizedDescriptionKey: "Application Support directory unavailable",
|
|
|
|
|
])
|
|
|
|
|
}
|
2026-01-30 03:15:10 +01:00
|
|
|
return base.appendingPathComponent("OpenClaw", isDirectory: true)
|
2025-12-12 21:18:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static func canvasRoot(sessionKey: String) throws -> URL {
|
|
|
|
|
let root = try appSupportDir().appendingPathComponent("canvas", isDirectory: true)
|
|
|
|
|
let safe = sessionKey.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
|
|
|
let session = safe.isEmpty ? "main" : safe
|
|
|
|
|
return root.appendingPathComponent(session, isDirectory: true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static func cachesDir() throws -> URL {
|
2026-01-18 20:46:29 +01:00
|
|
|
let base = FileManager().urls(for: .cachesDirectory, in: .userDomainMask).first
|
2025-12-12 21:18:46 +00:00
|
|
|
guard let base else {
|
2026-01-30 03:15:10 +01:00
|
|
|
throw NSError(domain: "OpenClawNodeStorage", code: 2, userInfo: [
|
2025-12-12 21:18:46 +00:00
|
|
|
NSLocalizedDescriptionKey: "Caches directory unavailable",
|
|
|
|
|
])
|
|
|
|
|
}
|
2026-01-30 03:15:10 +01:00
|
|
|
return base.appendingPathComponent("OpenClaw", isDirectory: true)
|
2025-12-12 21:18:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static func canvasSnapshotsRoot(sessionKey: String) throws -> URL {
|
|
|
|
|
let root = try cachesDir().appendingPathComponent("canvas-snapshots", isDirectory: true)
|
|
|
|
|
let safe = sessionKey.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
|
|
|
let session = safe.isEmpty ? "main" : safe
|
|
|
|
|
return root.appendingPathComponent(session, isDirectory: true)
|
|
|
|
|
}
|
|
|
|
|
}
|