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
149
Sources/Features/Editor/CardEditorPayload.swift
Normal file
149
Sources/Features/Editor/CardEditorPayload.swift
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
import Foundation
|
||||
import ManaCore
|
||||
|
||||
/// Resultat von `CardEditorPayload.build` — was an `CardsAPI.createCard`
|
||||
/// oder `updateCard` durchgereicht wird.
|
||||
struct CardEditorPayload {
|
||||
let fields: [String: String]
|
||||
let mediaRefs: [String]?
|
||||
}
|
||||
|
||||
/// Snapshot der CardEditor-Felder zum Submit-Zeitpunkt. Ein Wert-Typ,
|
||||
/// damit `buildPayload` außerhalb der View testbar ist und der View-
|
||||
/// Struct kompakt bleibt.
|
||||
struct CardEditorPayloadInputs {
|
||||
let type: CardType
|
||||
let front: String
|
||||
let back: String
|
||||
let clozeText: String
|
||||
let typingAnswer: String
|
||||
let multipleChoiceAnswer: String
|
||||
let occlusionImageData: Data?
|
||||
let occlusionMimeType: String
|
||||
let occlusionRegions: [MaskRegion]
|
||||
let occlusionNote: String
|
||||
let existingImageRef: String?
|
||||
let audioFileURL: URL?
|
||||
let existingAudioRef: String?
|
||||
let existingMediaRefs: [String]
|
||||
}
|
||||
|
||||
enum CardEditorPayloadError: LocalizedError {
|
||||
case missingImage
|
||||
case missingAudio
|
||||
|
||||
var errorDescription: String? {
|
||||
switch self {
|
||||
case .missingImage: "Bitte ein Bild wählen."
|
||||
case .missingAudio: "Bitte eine Audio-Datei wählen."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum CardEditorPayloadBuilder {
|
||||
/// Baut den Payload für `POST /cards` bzw. `PATCH /cards/:id`.
|
||||
/// Lädt für Image-Occlusion / Audio-Front bei Bedarf neue Media
|
||||
/// hoch; sonst wird der bestehende `*_ref` aus der Card weiterverwendet.
|
||||
static func build(inputs: CardEditorPayloadInputs, api: CardsAPI) async throws -> CardEditorPayload {
|
||||
switch inputs.type {
|
||||
case .basic, .basicReverse:
|
||||
CardEditorPayload(
|
||||
fields: CardFieldsBuilder.basic(front: inputs.front, back: inputs.back),
|
||||
mediaRefs: nil
|
||||
)
|
||||
case .cloze:
|
||||
CardEditorPayload(
|
||||
fields: CardFieldsBuilder.cloze(text: inputs.clozeText),
|
||||
mediaRefs: nil
|
||||
)
|
||||
case .typing:
|
||||
CardEditorPayload(
|
||||
fields: CardFieldsBuilder.typing(front: inputs.front, answer: inputs.typingAnswer),
|
||||
mediaRefs: nil
|
||||
)
|
||||
case .multipleChoice:
|
||||
CardEditorPayload(
|
||||
fields: CardFieldsBuilder.multipleChoice(
|
||||
front: inputs.front,
|
||||
answer: inputs.multipleChoiceAnswer
|
||||
),
|
||||
mediaRefs: nil
|
||||
)
|
||||
case .imageOcclusion:
|
||||
try await buildImageOcclusionPayload(inputs: inputs, api: api)
|
||||
case .audioFront:
|
||||
try await buildAudioFrontPayload(inputs: inputs, api: api)
|
||||
}
|
||||
}
|
||||
|
||||
private static func buildImageOcclusionPayload(
|
||||
inputs: CardEditorPayloadInputs,
|
||||
api: CardsAPI
|
||||
) async throws -> CardEditorPayload {
|
||||
let imageRef: String
|
||||
var refs = inputs.existingMediaRefs
|
||||
|
||||
if let newData = inputs.occlusionImageData {
|
||||
let media = try await api.uploadMedia(
|
||||
data: newData,
|
||||
filename: "occlusion.\(inputs.occlusionMimeType.contains("png") ? "png" : "jpg")",
|
||||
mimeType: inputs.occlusionMimeType
|
||||
)
|
||||
imageRef = media.id
|
||||
refs = [media.id]
|
||||
} else if let ref = inputs.existingImageRef {
|
||||
imageRef = ref
|
||||
} else {
|
||||
throw CardEditorPayloadError.missingImage
|
||||
}
|
||||
|
||||
return CardEditorPayload(
|
||||
fields: CardFieldsBuilder.imageOcclusion(
|
||||
imageRef: imageRef,
|
||||
regions: inputs.occlusionRegions,
|
||||
note: inputs.occlusionNote.isEmpty ? nil : inputs.occlusionNote
|
||||
),
|
||||
mediaRefs: refs
|
||||
)
|
||||
}
|
||||
|
||||
private static func buildAudioFrontPayload(
|
||||
inputs: CardEditorPayloadInputs,
|
||||
api: CardsAPI
|
||||
) async throws -> CardEditorPayload {
|
||||
let audioRef: String
|
||||
var refs = inputs.existingMediaRefs
|
||||
|
||||
if let url = inputs.audioFileURL {
|
||||
let didStart = url.startAccessingSecurityScopedResource()
|
||||
defer { if didStart { url.stopAccessingSecurityScopedResource() } }
|
||||
let data = try Data(contentsOf: url)
|
||||
let media = try await api.uploadMedia(
|
||||
data: data,
|
||||
filename: url.lastPathComponent,
|
||||
mimeType: audioMimeType(for: url)
|
||||
)
|
||||
audioRef = media.id
|
||||
refs = [media.id]
|
||||
} else if let ref = inputs.existingAudioRef {
|
||||
audioRef = ref
|
||||
} else {
|
||||
throw CardEditorPayloadError.missingAudio
|
||||
}
|
||||
|
||||
return CardEditorPayload(
|
||||
fields: CardFieldsBuilder.audioFront(audioRef: audioRef, back: inputs.back),
|
||||
mediaRefs: refs
|
||||
)
|
||||
}
|
||||
|
||||
private static func audioMimeType(for url: URL) -> String {
|
||||
switch url.pathExtension.lowercased() {
|
||||
case "mp3": "audio/mpeg"
|
||||
case "wav": "audio/wav"
|
||||
case "m4a", "mp4": "audio/mp4"
|
||||
case "ogg", "oga": "audio/ogg"
|
||||
default: "audio/mpeg"
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue