feat(decks): γ-1 bis γ-8 — AI/CSV-Import, Card-Edit, Pull-Update, Marketplace-Publish + Moderation + PDF
Vervollständigt die Cardecky-Web-Parität für Deck- und Card-Workflows. γ-1+γ-2 (AI-Deck-Generierung) - 4-Modi-Picker im DeckEditorView Create-Sheet: Leer/KI/Bild/CSV - POST /api/v1/decks/generate für Text-Prompt + 10/min Rate-Limit-UI - POST /api/v1/decks/from-image mit PhotosPicker + PDF-Importer (max 5 Files, 10 MiB/Bild, 30 MiB/PDF), Multipart-Body in CardsAPI+Generation - Loading-Overlay mit Task-Cancellation, Error-Mapping für 429/413/502 γ-3 (Card-Edit) - CardEditorView mit Mode .create(deckId:) / .edit(card:) - Image-Occlusion + Audio-Front behalten bestehenden Media-Ref, solange User nicht ersetzt — MediaCache lädt Bild nach - Type-Picker im Edit-Modus aus (Server-immutable) - CardEditorPayload + CardEditorMediaFields als Sub-Views γ-4 (Pull-Update + Duplicate + Archive) - POST /marketplace/private/:id/pull-update mit Smart-Merge-Anzeige - POST /decks/:id/duplicate - Archive-Toggle im Edit-Modus, Server filtert Liste serverseitig - DeckSecondaryActions als eigenes Sub-View γ-6 (CSV-Import) - RFC-4180-ish Parser (Quote-Escape, Header-Detect, BOM-strip) - Preview-Liste + sequentielle Card-Inserts mit Live-Progress - Image-Occlusion/Audio-Front werden geskipped (UI flaggt) γ-7 (Marketplace-Publish) + Follow-up (Report + Block + Re-Publish) - MarketplacePublishView mit lazy Author-Setup + Init + Publish 1.0.0 - Re-Publish-Modus: Picker für eigene Marketplace-Decks + Auto-Semver-Bump (Minor +1) - MarketplaceCardConverter (typing → type-in, audio-front → skipped, image-occlusion → skipped — Server hat keinen MP-Media-Re-Upload) - Toolbar-Menü auf PublicDeckView: „Deck melden …" + Author-Blockieren (App-Store-Guideline 5.1.1(v)) - ReportDeckSheet mit Reason-Picker (6 Kategorien) + optional Message - BlockedAuthorsView in Settings mit Swipe-Entblocken γ-8 (PDF-Export) - DeckPrintView mit SFSafariViewController auf cardecky.mana.how/decks/:id/print — iOS Share-Sheet → PDF speichern Side-Fixes (mid-stream) - StudySessionView: Card-Aspect-Ratio springt nicht mehr beim Flip (Bottom-Bar in ZStack fixer Höhe) - RootView: Glass-Pille für „Neues Deck"-Accessory + .guest- und .twoFactorRequired-Cases nachgezogen - DeckListView: Account-Toolbar-Button entfernt (Account-Tab unten ist alleinige Anlaufstelle) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
8ca7bd3636
commit
73f9081fa1
26 changed files with 3419 additions and 442 deletions
|
|
@ -1,11 +1,16 @@
|
|||
import Foundation
|
||||
import ManaCore
|
||||
|
||||
// swiftlint:disable file_length
|
||||
// swiftlint:disable type_body_length
|
||||
|
||||
/// Cards-spezifischer API-Client. Wrapper um `AuthenticatedTransport`
|
||||
/// aus ManaCore, der die Cardecky-Endpoints kennt.
|
||||
/// aus ManaCore, der die Cardecky-Endpoints kennt. Marketplace-Moderation
|
||||
/// + Self-Endpoints + AI-Generation sind in `CardsAPI+Marketplace.swift`
|
||||
/// und `CardsAPI+Generation.swift` ausgelagert.
|
||||
actor CardsAPI {
|
||||
private let transport: AuthenticatedTransport
|
||||
private let decoder: JSONDecoder
|
||||
let transport: AuthenticatedTransport
|
||||
let decoder: JSONDecoder
|
||||
|
||||
init(auth: AuthClient) {
|
||||
transport = AuthenticatedTransport(baseURL: AppConfig.apiBaseURL, auth: auth)
|
||||
|
|
@ -97,7 +102,7 @@ actor CardsAPI {
|
|||
var items: [URLQueryItem] = [
|
||||
.init(name: "sort", value: sort.rawValue),
|
||||
.init(name: "limit", value: "\(limit)"),
|
||||
.init(name: "offset", value: "\(offset)"),
|
||||
.init(name: "offset", value: "\(offset)")
|
||||
]
|
||||
if let query, !query.trimmingCharacters(in: .whitespaces).isEmpty {
|
||||
items.append(.init(name: "q", value: query))
|
||||
|
|
@ -218,6 +223,87 @@ actor CardsAPI {
|
|||
try ensureOK(http, data: data)
|
||||
}
|
||||
|
||||
/// `POST /api/v1/decks/:id/duplicate` — Server-seitige Kopie mit
|
||||
/// "(Kopie)"-Suffix, ohne FSRS-Verlauf, ohne Marketplace-Pointer.
|
||||
@discardableResult
|
||||
func duplicateDeck(id: String) async throws -> Deck {
|
||||
let (data, http) = try await transport.request(
|
||||
path: "/api/v1/decks/\(id)/duplicate",
|
||||
method: "POST"
|
||||
)
|
||||
try ensureOK(http, data: data)
|
||||
return try decoder.decode(Deck.self, from: data)
|
||||
}
|
||||
|
||||
/// `POST /api/v1/marketplace/private/:deckId/pull-update` — Smart-Merge-
|
||||
/// Pull. Holt neue/geänderte Karten aus der jüngsten Marketplace-Version
|
||||
/// in das geforkte private Deck. Removed-Karten bleiben lokal (User-
|
||||
/// Choice gewinnt). 422 wenn das Deck kein Fork ist.
|
||||
func pullUpdate(deckId: String) async throws -> PullUpdateResponse {
|
||||
let (data, http) = try await transport.request(
|
||||
path: "/api/v1/marketplace/private/\(deckId)/pull-update",
|
||||
method: "POST"
|
||||
)
|
||||
try ensureOK(http, data: data)
|
||||
return try decoder.decode(PullUpdateResponse.self, from: data)
|
||||
}
|
||||
|
||||
// MARK: - Marketplace-Publish
|
||||
|
||||
/// `POST /api/v1/marketplace/authors/me` — Author-Profil upserten.
|
||||
/// Pflicht-Schritt vor dem ersten Deck-Init im Marketplace.
|
||||
func upsertAuthor(_ body: AuthorUpsertBody) async throws {
|
||||
let payload = try makeJSON(body)
|
||||
let (data, http) = try await transport.request(
|
||||
path: "/api/v1/marketplace/authors/me",
|
||||
method: "POST",
|
||||
body: payload
|
||||
)
|
||||
try ensureOK(http, data: data)
|
||||
}
|
||||
|
||||
/// `GET /api/v1/marketplace/authors/me` — eigenes Author-Profil
|
||||
/// lesen, gibt `nil` zurück wenn noch keins existiert.
|
||||
func myAuthor() async throws -> Bool {
|
||||
let (data, http) = try await transport.request(path: "/api/v1/marketplace/authors/me")
|
||||
try ensureOK(http, data: data)
|
||||
// Server liefert entweder Author-Objekt oder JSON-null.
|
||||
if let raw = try? JSONSerialization.jsonObject(with: data), raw is NSNull {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/// `POST /api/v1/marketplace/decks` — Marketplace-Deck-Init.
|
||||
/// Erstellt nur Metadaten; Karten folgen via `publishMarketplaceVersion`.
|
||||
@discardableResult
|
||||
func initMarketplaceDeck(_ body: MarketplaceDeckInitBody) async throws -> PublicDeck {
|
||||
let payload = try makeJSON(body)
|
||||
let (data, http) = try await transport.request(
|
||||
path: "/api/v1/marketplace/decks",
|
||||
method: "POST",
|
||||
body: payload
|
||||
)
|
||||
try ensureOK(http, data: data)
|
||||
return try decoder.decode(PublicDeck.self, from: data)
|
||||
}
|
||||
|
||||
/// `POST /api/v1/marketplace/decks/:slug/publish` — neue Version
|
||||
/// publishen. Karten werden serverseitig durch AI-Moderation geschickt.
|
||||
func publishMarketplaceVersion(
|
||||
slug: String,
|
||||
body: MarketplacePublishBody
|
||||
) async throws -> MarketplacePublishResponse {
|
||||
let payload = try makeJSON(body)
|
||||
let (data, http) = try await transport.request(
|
||||
path: "/api/v1/marketplace/decks/\(slug)/publish",
|
||||
method: "POST",
|
||||
body: payload
|
||||
)
|
||||
try ensureOK(http, data: data)
|
||||
return try decoder.decode(MarketplacePublishResponse.self, from: data)
|
||||
}
|
||||
|
||||
// MARK: - Card-Mutations
|
||||
|
||||
/// `POST /api/v1/cards` — Karte anlegen. Server validiert `fields`
|
||||
|
|
@ -293,37 +379,15 @@ actor CardsAPI {
|
|||
|
||||
// MARK: - JSON-Encoding
|
||||
|
||||
private func makeJSON<T: Encodable>(_ value: T) throws -> Data {
|
||||
func makeJSON(_ value: some Encodable) throws -> Data {
|
||||
let encoder = JSONEncoder()
|
||||
encoder.dateEncodingStrategy = .iso8601
|
||||
return try encoder.encode(value)
|
||||
}
|
||||
|
||||
// MARK: - Multipart
|
||||
|
||||
private func makeMultipartBody(
|
||||
file: Data,
|
||||
filename: String,
|
||||
mimeType: String,
|
||||
boundary: String
|
||||
) -> Data {
|
||||
var body = Data()
|
||||
let lineBreak = "\r\n"
|
||||
let header = """
|
||||
--\(boundary)\(lineBreak)\
|
||||
Content-Disposition: form-data; name="file"; filename="\(filename)"\(lineBreak)\
|
||||
Content-Type: \(mimeType)\(lineBreak)\(lineBreak)
|
||||
"""
|
||||
body.append(header.data(using: .utf8) ?? Data())
|
||||
body.append(file)
|
||||
body.append(lineBreak.data(using: .utf8) ?? Data())
|
||||
body.append("--\(boundary)--\(lineBreak)".data(using: .utf8) ?? Data())
|
||||
return body
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private func ensureOK(_ http: HTTPURLResponse, data: Data) throws {
|
||||
func ensureOK(_ http: HTTPURLResponse, data: Data) throws {
|
||||
guard (200 ..< 300).contains(http.statusCode) else {
|
||||
let message = (try? JSONDecoder().decode(CardsServerError.self, from: data))?.error
|
||||
throw AuthError.serverError(status: http.statusCode, code: nil, message: message)
|
||||
|
|
@ -331,6 +395,8 @@ actor CardsAPI {
|
|||
}
|
||||
}
|
||||
|
||||
// swiftlint:enable type_body_length
|
||||
|
||||
private struct CardsServerError: Decodable {
|
||||
let error: String?
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue