Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions lib/Sabre/Album/AlbumRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,16 @@ public function setName($name) {
*/
public function createFile($name, $data = null) {
try {
// userConfigService->getUserConfig handle the path creation if missing
$photosLocation = $this->userConfigService->getUserConfig('photosLocation');

$photosFolder = $this->userFolder->get($photosLocation);
try {
$photosFolder = $this->userFolder->get($photosLocation);
} catch (NotFoundException $e) {
// If the folder does not exists, create it
$photosFolder = $this->userFolder->newFolder($photosLocation);
}

// If the node is not a folder, we throw
if (!($photosFolder instanceof Folder)) {
throw new Conflict('The destination exists and is not a folder');
}
Expand Down
16 changes: 2 additions & 14 deletions lib/Service/UserConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

use Exception;
use OCA\Photos\AppInfo\Application;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IUserSession;

Expand All @@ -39,35 +38,24 @@ class UserConfigService {

private IConfig $config;
private IUserSession $userSession;
private IRootFolder $rootFolder;

public function __construct(
IConfig $config,
IUserSession $userSession,
IRootFolder $rootFolder
IUserSession $userSession
) {
$this->config = $config;
$this->userSession = $userSession;
$this->rootFolder = $rootFolder;
}

public function getUserConfig(string $key) {
if (!in_array($key, array_keys(self::DEFAULT_CONFIGS))) {
throw new Exception('Unknown user config key');
}

$user = $this->userSession->getUser();
$default = self::DEFAULT_CONFIGS[$key];
$value = $this->config->getUserValue($user->getUid(), Application::APP_ID, $key, $default);

// If the config is a path, make sure it exists
if (str_starts_with($default, '/')) {
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
// If the folder does not exists, create it
if (!$userFolder->nodeExists($value)) {
$userFolder->newFolder($value);
}
}

return $value;
}
}