feat: Speichern veröffentlicht direkt, mehrere Karten auf einmal hochladen und veröffentlichen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4e9659ca85
commit
1cdebb7102
10 files changed
+281
-19
No files matched your search
@@ -0,0 +1,43 @@
|
||||
// Direkt veröffentlichen: nach dem Speichern (Editor) und beim Mehrfach-Upload („Meine Karten“) ohne Dialog.
|
||||
// Titel = Name der Karte. Ist die Karte schon veröffentlicht, wird die alte Veröffentlichung zurückgezogen und die neue Fassung
|
||||
// veröffentlicht, damit die Galerie immer den gespeicherten Stand zeigt. Fehlt der Benutzername, fragt der Namensdialog einmal nach.
|
||||
import type { SavedCard } from '../account/cards';
|
||||
import { requireUserId } from '../account/cards';
|
||||
import { usernameDialog } from '../account/username-dialog';
|
||||
import { withLogin } from '../account/with-login';
|
||||
import { isAlreadyPublished, isUsernameRequired, withdrawCard } from './api';
|
||||
import { myPublications } from './gallery';
|
||||
import { publishSavedCard, type PublishForm } from './publish';
|
||||
|
||||
const TITLE_MAX = 60;
|
||||
|
||||
export function autoPublishForm(name: string): PublishForm {
|
||||
const title = name.trim().slice(0, TITLE_MAX).trim();
|
||||
return { title: title === '' ? 'AirCard' : title, issuer: '', tags: '' };
|
||||
}
|
||||
|
||||
export async function autoPublish(card: SavedCard, signal?: AbortSignal): Promise<{ id: string }> {
|
||||
const form = autoPublishForm(card.name);
|
||||
const publish = () => withLogin(() => publishSavedCard(card, form));
|
||||
let askedName = false;
|
||||
let replaced = false;
|
||||
for (;;) {
|
||||
try {
|
||||
return await publish();
|
||||
} catch (err) {
|
||||
if (isUsernameRequired(err) && !askedName) {
|
||||
askedName = true;
|
||||
if ((await usernameDialog({ mode: 'required', signal })) === null) throw err;
|
||||
continue;
|
||||
}
|
||||
if (isAlreadyPublished(err) && !replaced) {
|
||||
replaced = true;
|
||||
const old = (await myPublications(requireUserId())).get(card.id);
|
||||
if (!old) throw err;
|
||||
await withLogin(() => withdrawCard(old.id));
|
||||
continue;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user