Changeset bd7f10d in Klonkt


Ignore:
Timestamp:
06/15/2026 01:18:56 AM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
e6888ca
Parents:
f45fc82
Message:

fix: playlist cover upload now works on create too (not only edit)

The upload button was edit-only (id-bound route /admin/playlists/api/:id/cover).
Now uploads to the generic /posts/upload-image (no id needed) -> /media/ URL
in the cover field -> sent along on Create. Button + handler always active.

Co-Authored-By: Claude <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/views/partials/playlist-editor.ejs

    rf45fc82 rbd7f10d  
    387387                    <input type="text" id="pli-cover" placeholder="https://… of upload" value="${esc(initial.cover)}" style="flex:1">
    388388                  </div>
    389                   ${isEdit ? `
    390389                  <div class="pl-cover-upload-row">
    391390                    <input type="file" id="pli-cover-file" accept="image/jpeg,image/png,image/webp,image/gif" hidden>
    392391                    <button type="button" class="pl-btn-small" id="pli-cover-pick">📷 Foto kiezen…</button>
    393392                    <span class="pl-cover-status" id="pli-cover-status"></span>
    394                   </div>` : `
    395                   <small class="pl-cover-note">Upload van een afbeelding kan na het aanmaken van de playlist.</small>`}
     393                  </div>
    396394                </div>
    397395              </div>
     
    448446    });
    449447
    450     // ── Cover file upload (edit mode only) ────────────────────
    451     // The upload widget only exists once a playlist has an id to attach to.
    452     // In create mode the user types/pastes a URL, saves the playlist, then
    453     // re-opens for upload. The route is the same as for tracks: returns
    454     // { ok, url, cover_url }.
     448    // ── Cover file upload (werkt in create ÉN edit) ───────────
     449    // We uploaden naar het generieke image-endpoint (/posts/upload-image,
     450    // requireAuth) dat een /media/-URL teruggeeft — dat heeft GEEN playlist-id
     451    // nodig, dus uploaden kan ook al vóór het aanmaken. De URL belandt in het
     452    // cover-veld en wordt bij 'Aanmaken'/'Opslaan' met de playlist meegestuurd.
    455453    const coverFileInput = $('#pli-cover-file');
    456454    const coverPickBtn   = $('#pli-cover-pick');
     
    470468        coverStatus.className = 'pl-cover-status';
    471469        const fd = new FormData();
    472         fd.append('cover', file);
     470        fd.append('image', file);
    473471        try {
    474           const r = await fetch(
    475             `/admin/playlists/api/${encodeURIComponent(opts.id)}/cover`,
     472          const r = await fetch('/posts/upload-image',
    476473            { method: 'POST', body: fd, credentials: 'same-origin' }
    477474          );
    478475          const j = await r.json();
    479           if (!r.ok || !j.ok) throw new Error(j.error || 'Upload mislukt');
    480           const url = j.cover_url || j.url || '';
     476          if (!r.ok || !j.url) throw new Error(j.error || 'Upload mislukt');
     477          const url = j.url || '';
    481478          coverEl.value = url;
    482479          coverThumb.innerHTML = url
Note: See TracChangeset for help on using the changeset viewer.