directus / v8-archive

Directus Database API — Wraps Custom SQL Databases with a REST/GraphQL API
https://docs.directus.io/api/reference.html
505 stars 204 forks source link

Video Embed Error Handling! #1969

Open philleepflorence opened 4 years ago

philleepflorence commented 4 years ago

When trying to embed a Youtube URL

In the file and function: Directus\Filesystem\Files->getLink(), if you have a Youtube API Key that is not valid for any reason (domain mismatch, expired, et al) the function automatically tries to search for an image file which then throws a fatal error, as there is no file.

Right now, the user will never know that the API key is failing or is invalid, but digging through the code, I noticed there is an exception thrown: Bad YouTube API Key, which should be shown to the Admin User, instead of bypassing and trying to locate a file.

Also, in the same file on line 377, there seems to be a mismatch or a property missing:

$thumbnailData = $this->saveData($fileInfo['data'], $fileName, $fileInfo['fileId']);

I cannot find any reference for $fileInfo['fileId'], and the third argument for public function saveData expects a boolean.

everyx commented 4 years ago

same problem, related https://github.com/directus/api/issues/1881 https://github.com/directus/api/issues/1904

philleepflorence commented 4 years ago

@everyx ... this is the cause of the error for #1881 and #1904!

I fixed it on my end but wanted to be sure or find out what the fileId is for.

Most likely, the issue is: Bad YouTube API Key

everyx commented 4 years ago

@philleepflorence Can you share your patch here, I want't patch it on my end :)

emrahtoy commented 3 years ago

Line 377 has potential of error due to undefined array index. It should be like

$thumbnailData = $this->saveData($fileInfo['data'], $fileName, !empty($fileInfo['fileId']));