Skip to content

Commit

Permalink
Merge pull request #6 from nextcloud/fix/noid/thumbnails
Browse files Browse the repository at this point in the history
Fix project thumbnails
  • Loading branch information
julien-nc committed Apr 28, 2023
2 parents dedd648 + f1d45ea commit 6338889
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion lib/Service/CollaboardAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public function getImage(string $url): array {
];
}

/**
* @param string $userId
* @return array|string[]
* @throws Exception
*/
public function getProjects(string $userId): array {
$params = [
'AppVer' => '5.16.520',
Expand All @@ -76,9 +81,15 @@ public function getProjects(string $userId): array {
if (isset($projectsResult['error'])) {
return $projectsResult;
}
$thumbnailRequestOptions = [
'headers' => [
'User-Agent' => Application::INTEGRATION_USER_AGENT,
],
];
$client = $this->client;
if (isset($projectsResult['Results']) && is_array($projectsResult['Results'])) {
$remoteProjects = $projectsResult['Results'];
return array_map(static function(array $remoteProject) {
return array_map(static function(array $remoteProject) use ($thumbnailRequestOptions, $client) {
$remoteProject['trash'] = false;
$remoteProject['name'] = $remoteProject['Project']['Description'];
$remoteProject['id'] = $remoteProject['Project']['ProjectId'];
Expand All @@ -88,6 +99,14 @@ public function getProjects(string $userId): array {
'photoUrl' => $remoteProject['Owner']['PhotoUrl'] ?? null,
];
$remoteProject['updated_at'] = $remoteProject['Project']['LastUpdate'];
if (isset($remoteProject['ThumbnailUrl']) && $remoteProject['ThumbnailUrl']) {
try {
$response = $client->get($remoteProject['ThumbnailUrl'], $thumbnailRequestOptions);
$remoteProject['Project']['Thumbnail'] = base64_encode($response->getBody());
} catch (Exception | Throwable $e) {

}
}
return $remoteProject;
}, $remoteProjects);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProjectItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default {
computed: {
hasImage() {
return this.project.Project.Thumbnail !== null
return !!this.project.Project.Thumbnail
},
imgSrc() {
return 'data:image/png;base64,' + this.project.Project.Thumbnail
Expand Down

0 comments on commit 6338889

Please sign in to comment.