feat: Add publish and mark-published endpoints with validation

- Add /api/posts/{id}/publish endpoint for API-based publishing
- Add /api/posts/{id}/mark-published endpoint for manual workflow
- Add content length validation before publishing
- Update modal with "Ya lo publiqué" and "Publicar (API)" buttons
- Fix retry_count handling for None values

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-03 23:01:28 +00:00
parent 855e765417
commit 29520a00f6
4 changed files with 122 additions and 8 deletions

View File

@@ -184,10 +184,13 @@
${platformContents}
<div class="flex gap-2 mt-6 pt-4 border-t border-dark-700">
${post.status === 'draft' || post.status === 'pending_approval' ?
`<button onclick="closePostModal(); publishPost(${post.id})" class="flex-1 bg-green-500/20 text-green-400 px-4 py-2 rounded-lg hover:bg-green-500/30 transition-colors">
Publicar ahora
<div class="flex flex-wrap gap-2 mt-6 pt-4 border-t border-dark-700">
${post.status === 'draft' || post.status === 'pending_approval' || post.status === 'failed' ?
`<button onclick="markAsPublished(${post.id})" class="flex-1 bg-green-500/20 text-green-400 px-4 py-2 rounded-lg hover:bg-green-500/30 transition-colors">
✓ Ya lo publiqué
</button>
<button onclick="closePostModal(); publishPost(${post.id})" class="flex-1 bg-blue-500/20 text-blue-400 px-4 py-2 rounded-lg hover:bg-blue-500/30 transition-colors">
🚀 Publicar (API)
</button>` : ''}
<button onclick="closePostModal(); deletePost(${post.id})" class="flex-1 bg-red-500/20 text-red-400 px-4 py-2 rounded-lg hover:bg-red-500/30 transition-colors">
Eliminar
@@ -263,6 +266,23 @@
modal.classList.remove('flex');
}
async function markAsPublished(id) {
try {
const response = await fetch(`/api/posts/${id}/mark-published`, { method: 'POST' });
const data = await response.json();
if (data.success) {
closePostModal();
showModal('<div class="text-center"><span class="text-4xl mb-4 block">✅</span><p>Marcado como publicado</p></div>');
setTimeout(() => { closeModal(); location.reload(); }, 1500);
} else {
showModal(`<div class="text-center"><span class="text-4xl mb-4 block">❌</span><p>${data.detail || 'Error'}</p></div>`);
}
} catch (error) {
showModal('<div class="text-center"><span class="text-4xl mb-4 block">❌</span><p>Error de conexión</p></div>');
}
}
function escapeHtml(text) {
if (!text) return '';
const div = document.createElement('div');