/**
 * Shared SSE completion handler for download/extraction streams.
 *
 * Returns true if the stream is complete (error or success), false otherwise.
 * The caller should reset its own controller reference when true is returned.
 *
 * @param {Object} data - Parsed SSE event data
 * @param {Function} onSuccess - Called (with data) on successful completion
 * @returns {boolean} Whether the stream completed
 */
function handleSSECompletion(data, onSuccess) {
    if (!data.complete) return false;

    if (data.error) {
        setTimeout(() => {
            closeProgressModal();
            alert(data.error);
        }, 1000);
    } else {
        setTimeout(() => {
            closeProgressModal();
            onSuccess(data);
        }, 2000);
    }
    return true;
}
