-
-
Notifications
You must be signed in to change notification settings - Fork 77
Implement default Photos folder #1189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,3 +18,4 @@ build/ | |
| coverage/ | ||
| vendor | ||
| .php_cs.cache | ||
| .php-cs-fixer.cache | ||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
| /** | ||
| * @copyright Copyright (c) 2022 John Molakvoæ <[email protected]> | ||
| * | ||
| * @author John Molakvoæ <[email protected]> | ||
| * | ||
| * @license AGPL-3.0-or-later | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| namespace OCA\Photos\Service; | ||
|
|
||
| use Exception; | ||
| use OCA\Photos\AppInfo\Application; | ||
| use OCP\Files\IRootFolder; | ||
| use OCP\IConfig; | ||
| use OCP\IUserSession; | ||
|
|
||
| class UserConfigService { | ||
| public const DEFAULT_CONFIGS = [ | ||
| 'croppedLayout' => 'false', | ||
| 'photosLocation' => '/Photos', | ||
| ]; | ||
|
|
||
| private IConfig $config; | ||
| private IUserSession $userSession; | ||
| private IRootFolder $rootFolder; | ||
|
|
||
| public function __construct( | ||
| IConfig $config, | ||
| IUserSession $userSession, | ||
| IRootFolder $rootFolder | ||
| ) { | ||
| $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; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could theoritecally be exposed as a capability and used straight away by the
photos/src/mixins/UserConfig.js
Lines 34 to 39 in 34948e3