Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sg_vimeo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TYPO3
sg_vimeo
Commits
1eb77a55
Commit
1eb77a55
authored
2 years ago
by
Stefan Galinski
Browse files
Options
Downloads
Patches
Plain Diff
[BUGFIX] Fix the broken error handling
parent
0a8ffe39
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Classes/Controller/VimeoController.php
+19
-10
19 additions, 10 deletions
Classes/Controller/VimeoController.php
Classes/Service/VimeoService.php
+7
-5
7 additions, 5 deletions
Classes/Service/VimeoService.php
README.md
+1
-1
1 addition, 1 deletion
README.md
with
27 additions
and
16 deletions
Classes/Controller/VimeoController.php
+
19
−
10
View file @
1eb77a55
...
...
@@ -20,6 +20,7 @@ namespace SGalinski\SgVimeo\Controller;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use
http\Exception\RuntimeException
;
use
SGalinski\SgVimeo\Service\VimeoService
;
use
TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection
;
use
TYPO3\CMS\Core\Resource\FileReference
;
...
...
@@ -64,21 +65,21 @@ class VimeoController extends ActionController {
$clientSecret
,
$personalAccessToken
);
$response
=
$vimeoService
->
getVimeoData
(
$id
,
$maxResultsWithFilters
);
$response
=
$this
->
mapVimeoApiResponseWithPossibleCustomThumbnails
(
$response
);
if
(
$response
===
NULL
)
{
try
{
$response
=
$vimeoService
->
getVimeoData
(
$id
,
$maxResultsWithFilters
);
$response
=
$this
->
mapVimeoApiResponseWithPossibleCustomThumbnails
(
$response
);
if
(
$response
===
NULL
)
{
return
;
}
}
catch
(
\Exception
$exception
)
{
$this
->
view
->
assign
(
'error'
,
$exception
->
getMessage
());
return
;
}
if
(
is_array
(
$response
[
'items'
]))
{
$response
[
'items'
]
=
array_filter
(
$response
[
'items'
],
function
(
$item
)
use
(
$filterIds
)
{
$videoId
=
(
string
)
$item
[
'videoId'
];
foreach
(
$filterIds
as
$filterId
)
{
if
(
$videoId
===
$filterId
)
{
return
FALSE
;
}
}
return
TRUE
;
return
!
in_array
(
$videoId
,
$filterIds
,
TRUE
);
});
// Fix the array indexes from previous filtering
...
...
@@ -89,7 +90,6 @@ class VimeoController extends ActionController {
}
foreach
(
$response
[
'items'
]
as
&
$item
)
{
/*
* Check if link is of the form "https://vimeo.com/123456789", not "https://vimeo.com/username/videoname".
* Just checks if the end of `link` is the same as `videoId`, and if not, it replaces `link`.
...
...
@@ -131,6 +131,15 @@ class VimeoController extends ActionController {
return
NULL
;
}
if
(
isset
(
$response
[
'items'
][
0
][
'error'
]))
{
$message
=
$response
[
'items'
][
0
][
'error'
];
if
(
isset
(
$response
[
'items'
][
0
][
'developer_message'
]))
{
$message
.
=
' ('
.
$response
[
'items'
][
0
][
'developer_message'
]
.
')'
;
}
throw
new
\RuntimeException
(
$message
);
}
$contentElementUid
=
(
int
)
$this
->
configurationManager
->
getContentObject
()
->
data
[
'uid'
];
if
(
$contentElementUid
<=
0
)
{
return
$response
;
...
...
This diff is collapsed.
Click to expand it.
Classes/Service/VimeoService.php
+
7
−
5
View file @
1eb77a55
...
...
@@ -124,7 +124,7 @@ class VimeoService implements LoggerAwareInterface {
$response
[
'items'
]
=
$this
->
addVideoIdsToResponse
(
$this
->
getChannelVideos
(
$channelId
));
$response
[
'kind'
]
=
'channel'
;
}
else
{
$response
[
'items'
]
=
$this
->
addVideoIdsToResponse
(
$this
->
getVideo
(
(
int
)
$vimeoId
));
$response
[
'items'
]
=
$this
->
addVideoIdsToResponse
(
$this
->
getVideo
(
$vimeoId
));
$response
[
'kind'
]
=
'video'
;
}
...
...
@@ -188,11 +188,10 @@ class VimeoService implements LoggerAwareInterface {
// log error & return here, since the response was not OK
if
(
$response
[
'status'
]
!==
200
)
{
$this
->
logger
->
error
(
'sg_vimeo API Request failed, got the following response:'
,
$response
);
return
NULL
;
return
[
$response
[
'body'
]]
;
}
// @TODO: we could check $response['headers‘]['X-RateLimit-Remaining'] here for remaining quota
if
(
array_key_exists
(
'paging'
,
$response
[
'body'
]))
{
$amountOfVideosInResponse
=
is_countable
(
$response
[
'body'
][
'data'
])
?
count
(
$response
[
'body'
][
'data'
])
:
0
;
$this
->
amountOfVideosFetched
+=
$amountOfVideosInResponse
;
...
...
@@ -228,16 +227,17 @@ class VimeoService implements LoggerAwareInterface {
* Returns a single video for the given $videoId
*
* @see https://developer.vimeo.com/api/reference/videos#get_video
* @param in
t
$videoId
* @param
str
in
g
$videoId
* @return array|null
*/
public
function
getVideo
(
in
t
$videoId
):
?array
{
public
function
getVideo
(
str
in
g
$videoId
):
?array
{
// use field filtering, to save on quota, see: https://developer.vimeo.com/guidelines/rate-limiting
$fieldsToSelect
=
'uri,name,description,link,embed,pictures,release_time,width,height'
;
try
{
$response
=
$this
->
vimeoApiClient
->
request
(
self
::
API_VIDEO
.
$videoId
.
'?fields='
.
$fieldsToSelect
);
}
catch
(
VimeoRequestException
$e
)
{
$response
=
NULL
;
throw
$e
;
}
return
$this
->
preprocessApiResponse
(
$response
);
...
...
@@ -259,6 +259,7 @@ class VimeoService implements LoggerAwareInterface {
);
}
catch
(
VimeoRequestException
$e
)
{
$response
=
NULL
;
throw
$e
;
}
return
$this
->
preprocessApiResponse
(
$response
);
...
...
@@ -280,6 +281,7 @@ class VimeoService implements LoggerAwareInterface {
);
}
catch
(
VimeoRequestException
$e
)
{
$response
=
NULL
;
throw
$e
;
}
return
$this
->
preprocessApiResponse
(
$response
);
...
...
This diff is collapsed.
Click to expand it.
README.md
+
1
−
1
View file @
1eb77a55
...
...
@@ -41,7 +41,7 @@ plugin.tx_sgvimeo {
If you have a video which is not available to the public, but you want to show it on your website, you need an
authenticated personal access token. You can find a guide, on how to generate such a token here:
https://vimeo.zendesk.com/hc/en-us/articles/360042445032-How-do-I-generate-a-personal-access-token-
.
https://vimeo.zendesk.com/hc/en-us/articles/360042445032-How-do-I-generate-a-personal-access-token-
The following requirements have to be met, for the private video to show up:
*
the video has to be hosted on the same vimeo account, that was used to configure the clientSecret & clientId (vimeo app)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment