qstatus/qStatus/Models/PostingService.swift
Paweł Orzech 733334df9b
Deduplicate shared constants, MIME helper, and cache normalized URLs
- 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
2026-03-07 22:22:08 +01:00

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"
}
}