Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions apps/dashboard/lib/Service/BackgroundService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
use OCP\IConfig;
use OCP\Lock\LockedException;
use OCP\PreConditionNotMetException;
use Safe\Exceptions\FilesystemException;
use function Safe\rewind;

class BackgroundService {
// true when the background is bright and need dark icons
Expand Down Expand Up @@ -144,17 +146,20 @@ public function setDefaultBackground(): void {
* @throws LockedException
* @throws PreConditionNotMetException
* @throws NoUserException
* @throws FilesystemException
*/
public function setFileBackground($path): void {
$this->config->setUserValue($this->userId, 'dashboard', 'background', 'custom');
$userFolder = $this->rootFolder->getUserFolder($this->userId);
/** @var File $file */
$file = $userFolder->get($path);
$image = new \OCP\Image();
if ($image->loadFromFileHandle($file->fopen('r')) === false) {
$stream = $file->fopen('r');
if ($image->loadFromFileHandle($stream) === false) {
throw new InvalidArgumentException('Invalid image file');
}
$this->getAppDataFolder()->newFile('background.jpg', $file->fopen('r'));
rewind($stream);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be tested with object store, rewind might not work on all stream types (not sure if a http stream can be rewinded)

now thinking again, I see that this endpoint is only for setting a background image, something that will not happen repeatedly, so having a little performance impact here for validation is probably ok

feel free to revert back to the former solution and sorry for the noise

$this->getAppDataFolder()->newFile('background.jpg', $stream);
}

public function setShippedBackground($fileName): void {
Expand Down