dobromir-hristov / vue-vimeo-player

Vue.js wrapper for Vimeo player
MIT License
111 stars 56 forks source link

videoId and videoUrl properties should not be required (both) #77

Closed gabrielmedeirossouza closed 3 years ago

gabrielmedeirossouza commented 3 years ago

According to the official @vimeo/player documentation, the video id or the url of the video must be required, but it does not specify that it is solely and exclusively the video id.

I'm going through a bug where my url id is composed by the junction of two IDs (e.g 3817734932/32429420) and if I use the videoId property passing my id with a slash, it falls into a validation checking if the ID is an integer and the request is not made.

@vimeo/player - functions.js

export function getVimeoUrl(oEmbedParameters = {}) {
    const id = oEmbedParameters.id;
    const url = oEmbedParameters.url;
    const idOrUrl = id || url;

    if (!idOrUrl) {
        throw new Error('An id or url must be passed, either in an options object or as a data-vimeo-id or data-vimeo-url attribute.');
    }

    if (isInteger(idOrUrl)) {
        return `https://vimeo.com/${idOrUrl}`;
    }

    if (isVimeoUrl(idOrUrl)) {
        return idOrUrl.replace('http:', 'https:');
    }

    if (id) {
        throw new TypeError(`“${id}” is not a valid video id.`);
    }

    throw new TypeError(`“${idOrUrl}” is not a vimeo.com url.`);
}

As you can see, id takes precedence over url.

const idOrUrl = id || url; // 3817734932/32429420 is not a URL nor an integer...

if (isInteger(idOrUrl)) {
    return `https://vimeo.com/${idOrUrl}`;
}

if (isVimeoUrl(idOrUrl)) {
    return idOrUrl.replace('http:', 'https:');
}

To work around this problem, I only need to use the videoUrl property, but I won't be able to use the videoId property because of the priority order described in the code above.

I will create a Pull Request to make this correction.