Closed ChrisMBarr closed 4 months ago
Thanks for the tip!
This is really something I should fix internally but this work-around should help everyone in the mean time
Actually, here's a pretty simple fix for it:
function isValidId ( maybeId ) {
const zeroPadded = maybeId.padStart(8, '0') // anything less than 8 chars gets zeros added to the start
const isCorrectLength = zeroPadded.length >= 8
const isAlphanumeric = /^[a-zA-Z0-9_-]+$/i.test( zeroPadded )
return isCorrectLength && isAlphanumeric
}
But given that, you probably don't need the isCorrectLength
check any more since now it will always be at least 8 characters long. So probably just this is sufficient:
function isValidId ( maybeId ) {
const zeroPadded = maybeId.padStart(8, '0') // anything less than 8 chars gets zeros added to the start
const isAlphanumeric = /^[a-zA-Z0-9_-]+$/i.test( zeroPadded )
return isAlphanumeric
}
Hmmm... that fixes the padding issue, but I'd rather fix the underlying issue that makes it have to add the 0s in the first place.
Maybe we could have 2 checks inside isValidId
:
isValidVimeoId
- Check if it's a number more than 2 digitsisValidYouTubeId
- Check if it's just letters and numbers and 11 characters or longer. This will break YouTube thumbnails that only contain numbers, but that will be 1 in 737 Million according to ChatGPT, and we can handle that bridge when it starts to become a problem.
Alright, I added an additional check for Vimeo IDs that checks if every character before the first _
is a digit.
This should support shorter ids, including those you shared above, without adding zeroes(yay!).
Let me know if this fixed the issue for you
Cool, I'll give it a shot. I used this on a PR I submitted to a project forever ago and they never accepted yet. It has merge issues on it so I'll probably for those and remove the need for this patch now. here it is if your curious: https://github.com/MurhafSousli/ngx-gallery/pull/575/files#diff-59d3f3892ed1e6d41d8073a45aef6c2a6c4106f36d536b177626d6500eeb6c75R67-R75
Vimeo IDs less than 8 digits need zeros prefixed to get a valid thumbnail
I have a video at https://vimeo.com/961922 which is a few years old, so it's video ID is shorter than the common video IDs now. Using the ID
961922
fails to get an image: https://vumbnail.com/961922.jpgBut I took a guess and prefixed some zeros to make it 8 characters long and that works! https://vumbnail.com/00961922.jpg
Vimeo video IDs can be any length
(well at least 4 digits from what I can tell)
The one I have above is 6 digits, but here are some older ones (some 18 years old!) that have between 4 and 7 digits.
With my finding above, as expected: https://vumbnail.com/8612.jpg fails but https://vumbnail.com/00008612.jpg will work
My guess at a fix would be to focus on the
isValidId
method and this regex that expects an 8 digit minimum