fix(fuenfvoacht): confirmPlan überschreibt keine geplanten Artikel mehr
- confirmPlan() speichert jetzt mit der aktuellen Editor-post_time, nicht mit der Ziel-Zeit — verhindert dass ein bestehender approved- Artikel überschrieben wird - api_save bevorzugt drafts gegenüber approved-Artikeln beim Fallback - Getestet: Neuer Artikel einplanen auf morgen lässt id=10 (approved heute 19:45) komplett unberührt Made-with: Cursor
This commit is contained in:
parent
4e26b79cb3
commit
78159d87fe
2 changed files with 8 additions and 5 deletions
|
|
@ -356,7 +356,8 @@ def api_save(date_str):
|
||||||
flog.article_saved(date_str, post_time)
|
flog.article_saved(date_str, post_time)
|
||||||
return jsonify({'success': True, 'article_id': existing['id']})
|
return jsonify({'success': True, 'article_id': existing['id']})
|
||||||
all_today = db.get_articles_by_date(date_str)
|
all_today = db.get_articles_by_date(date_str)
|
||||||
candidate = next((a for a in all_today if a['status'] in ('draft', 'scheduled', 'sent_to_bot', 'approved', 'pending_review')), None)
|
draft = next((a for a in all_today if a['status'] == 'draft'), None)
|
||||||
|
candidate = draft or next((a for a in all_today if a['status'] in ('pending_review', 'scheduled', 'sent_to_bot')), None)
|
||||||
if candidate:
|
if candidate:
|
||||||
old_time = candidate['post_time']
|
old_time = candidate['post_time']
|
||||||
conn = db.get_conn()
|
conn = db.get_conn()
|
||||||
|
|
|
||||||
|
|
@ -715,16 +715,18 @@ async function confirmPlan() {
|
||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 1. Speichern auf selectedDate (dort liegt der generierte Artikel)
|
const currentTime = document.getElementById('post-time-input')?.value || '19:55';
|
||||||
|
|
||||||
|
// 1. Speichern auf selectedDate mit der AKTUELLEN post_time (nicht Ziel-Zeit)
|
||||||
const saveRes = await fetch(`/api/article/${selectedDate}/save`, {
|
const saveRes = await fetch(`/api/article/${selectedDate}/save`, {
|
||||||
method: 'POST', headers: {'Content-Type':'application/json'},
|
method: 'POST', headers: {'Content-Type':'application/json'},
|
||||||
body: JSON.stringify({content, post_time: time})
|
body: JSON.stringify({content, post_time: currentTime})
|
||||||
});
|
});
|
||||||
const saveData = await saveRes.json();
|
const saveData = await saveRes.json();
|
||||||
if (!saveData.success) throw new Error(saveData.error || 'Speichern fehlgeschlagen');
|
if (!saveData.success) throw new Error(saveData.error || 'Speichern fehlgeschlagen');
|
||||||
|
|
||||||
// 2. Falls Zieldatum != Quelldatum: Artikel verschieben
|
// 2. Artikel auf Zieldatum+Zeit verschieben (auch wenn gleiches Datum, andere Zeit)
|
||||||
if (date !== selectedDate && saveData.article_id) {
|
if (saveData.article_id && (date !== selectedDate || time !== currentTime)) {
|
||||||
const reRes = await fetch(`/api/article/${saveData.article_id}/reschedule`, {
|
const reRes = await fetch(`/api/article/${saveData.article_id}/reschedule`, {
|
||||||
method: 'POST', headers: {'Content-Type':'application/json'},
|
method: 'POST', headers: {'Content-Type':'application/json'},
|
||||||
body: JSON.stringify({date, post_time: time})
|
body: JSON.stringify({date, post_time: time})
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue