Skip to content

Commit 1b9b320

Browse files
committed
[YouTube] Latest Video: Prevent unnecessary API requests for invalid channels
Valid channel IDs/users do not contain any spaces, so they're safe to ignore (for now)
1 parent 9afd698 commit 1b9b320

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

app/Http/Controllers/YouTubeController.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ public function latestVideo(Request $request)
4141
$skip = 0;
4242
}
4343

44+
/**
45+
* Channel IDs and old "user" URLs do not have spaces in them.
46+
*
47+
* Some users have specified their display names (example: "My Channel Name")
48+
* as their channel ID, which will just return an error from the YouTube API.
49+
*
50+
* To prevent unnecessary API requests, we're returning an error early as
51+
* this would be an invalid ID/user value anyways.
52+
*/
53+
if (strpos($id, ' ') !== false) {
54+
return Helper::text(__('youtube.invalid_channel_value', [
55+
'type' => $type,
56+
'id' => $id,
57+
]));
58+
}
59+
4460
try {
4561
switch ($type) {
4662
case 'user':

resources/lang/en/youtube.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
/**
4+
* English translation strings for YouTube-related endpoints.
5+
*/
6+
7+
return [
8+
/**
9+
* For /youtube/latest_video when someone specifies an
10+
* invalid channel ID (/channel/ URLs) or user (/user/ URLs).
11+
*/
12+
'invalid_channel_value' => 'Invalid YouTube channel (:type) specified: :id',
13+
];

0 commit comments

Comments
 (0)