- Extract OAuth UserDefaults keys into shared OAuthKeys enum - Extract triplicated mimeTypeFor() into shared mimeTypeForImage() - Cache normalized base URL at client init instead of per-request
27 lines
826 B
Swift
27 lines
826 B
Swift
import AppKit
|
|
|
|
protocol PostingService: Sendable {
|
|
var account: Account { get }
|
|
func uploadMedia(imageData: Data, filename: String, altText: String?) async throws -> String
|
|
func createPost(text: String, mediaIDs: [String]) async throws -> URL
|
|
}
|
|
|
|
struct PostingError: LocalizedError {
|
|
let message: String
|
|
var errorDescription: String? { message }
|
|
}
|
|
|
|
enum OAuthKeys {
|
|
static let pendingMastodonAccount = "qstatus.pending-mastodon-account"
|
|
static let pendingMastodonError = "qstatus.pending-mastodon-account-error"
|
|
}
|
|
|
|
func mimeTypeForImage(_ filename: String) -> String {
|
|
let ext = (filename as NSString).pathExtension.lowercased()
|
|
switch ext {
|
|
case "png": return "image/png"
|
|
case "gif": return "image/gif"
|
|
case "webp": return "image/webp"
|
|
default: return "image/jpeg"
|
|
}
|
|
}
|