Skip to content

Commit 8f2cfe5

Browse files
refactor(recent-files): drop frontend changes, move configs to instance level
Signed-off-by: Cristian Scheid <cristianscheid@gmail.com>
1 parent ba26768 commit 8f2cfe5

11 files changed

Lines changed: 52 additions & 554 deletions

File tree

apps/files/lib/ConfigLexicon.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
class ConfigLexicon implements ILexicon {
2424
public const OVERWRITES_HOME_FOLDERS = 'overwrites_home_folders';
2525
public const RECENT_LIMIT = 'recent_limit';
26+
public const GROUP_RECENT_FILES = 'group_recent_files';
27+
public const RECENT_FILES_GROUP_MIME_TYPES = 'recent_files_group_mime_types';
28+
public const RECENT_FILES_GROUP_TIMESPAN_MINUTES = 'recent_files_group_timespan_minutes';
2629

2730
public function getStrictness(): Strictness {
2831
return Strictness::IGNORE;
@@ -45,6 +48,27 @@ public function getAppConfigs(): array {
4548
definition: 'Maximum number of files to display on recent files view',
4649
lazy: false,
4750
),
51+
new Entry(
52+
self::GROUP_RECENT_FILES,
53+
ValueType::BOOL,
54+
defaultRaw: false,
55+
definition: 'Whether to group recent files by MIME type or not',
56+
lazy: false,
57+
),
58+
new Entry(
59+
self::RECENT_FILES_GROUP_MIME_TYPES,
60+
ValueType::ARRAY,
61+
defaultRaw: [],
62+
definition: 'Which MIME types to group in the recent files list',
63+
lazy: false,
64+
),
65+
new Entry(
66+
self::RECENT_FILES_GROUP_TIMESPAN_MINUTES,
67+
ValueType::INT,
68+
defaultRaw: 2,
69+
definition: 'Time window in minutes to group files uploaded close together in the recent files list',
70+
lazy: false,
71+
),
4872
];
4973
}
5074

apps/files/lib/Controller/ViewController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ public function index($dir = '', $view = '', $fileid = null) {
178178
$this->initialState->provideInitialState('config', $this->userConfig->getConfigs());
179179
$this->initialState->provideInitialState('viewConfigs', $this->viewConfig->getConfigs());
180180
$this->initialState->provideInitialState('recent_limit', $this->appConfig->getAppValueInt(ConfigLexicon::RECENT_LIMIT, 100));
181+
// Not yet consumed by the frontend, provided for future implementation
182+
$this->initialState->provideInitialState('group_recent_files', $this->appConfig->getAppValueBool(ConfigLexicon::GROUP_RECENT_FILES, false));
183+
$this->initialState->provideInitialState('recent_files_group_mime_types', $this->appConfig->getAppValueArray(ConfigLexicon::RECENT_FILES_GROUP_MIME_TYPES, []));
184+
$this->initialState->provideInitialState('recent_files_group_timespan_minutes', $this->appConfig->getAppValueInt(ConfigLexicon::RECENT_FILES_GROUP_TIMESPAN_MINUTES, 2));
181185

182186
// File sorting user config
183187
$filesSortingConfig = json_decode($this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'), true);

apps/files/lib/Service/UserConfig.php

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -79,33 +79,6 @@ class UserConfig {
7979
'default' => true,
8080
'allowed' => [true, false],
8181
],
82-
[
83-
// Whether to group images on recent files list or not
84-
'key' => 'group_recent_files_images',
85-
'default' => false,
86-
'allowed' => [true, false],
87-
],
88-
[
89-
// Which image mime types to group in the recent files list
90-
'key' => 'recent_files_group_mimetypes',
91-
'default' => '',
92-
'allowed' => [
93-
'image/png',
94-
'image/jpeg',
95-
'image/gif',
96-
'image/webp',
97-
'image/avif',
98-
'image/heic',
99-
'image/heif',
100-
]
101-
],
102-
[
103-
// Time window in minutes to group files uploaded close together in the recent files list
104-
'key' => 'recent_files_group_timespan_minutes',
105-
'default' => 2,
106-
'min' => 1,
107-
'max' => 999,
108-
],
10982
];
11083
protected ?IUser $user = null;
11184

@@ -145,7 +118,7 @@ private function getAllowedConfigValues(string $key): array {
145118
* Get the default config value for a given key
146119
*
147120
* @param string $key a valid config key
148-
* @return string|bool|int
121+
* @return string|bool
149122
*/
150123
private function getDefaultConfigValue(string $key) {
151124
foreach (self::ALLOWED_CONFIGS as $config) {
@@ -173,25 +146,7 @@ public function setConfig(string $key, $value): void {
173146
throw new \InvalidArgumentException('Unknown config key');
174147
}
175148

176-
if (is_string($value) && str_starts_with($value, '[') && str_ends_with($value, ']')) {
177-
$value = json_decode($value, true) ?? $value;
178-
}
179-
180-
$config = $this->getConfigDefinition($key);
181-
182-
if (isset($config['min'], $config['max'])) {
183-
if ((int)$value < $config['min'] || (int)$value > $config['max']) {
184-
throw new \InvalidArgumentException('Invalid config value');
185-
}
186-
} elseif (is_array($value)) {
187-
$allowedValues = $this->getAllowedConfigValues($key);
188-
foreach ($value as $v) {
189-
if (!in_array($v, $allowedValues)) {
190-
throw new \InvalidArgumentException('Invalid config value');
191-
}
192-
}
193-
$value = json_encode($value);
194-
} elseif (!in_array($value, $this->getAllowedConfigValues($key))) {
149+
if (!in_array($value, $this->getAllowedConfigValues($key))) {
195150
throw new \InvalidArgumentException('Invalid config value');
196151
}
197152

@@ -219,27 +174,9 @@ public function getConfigs(): array {
219174
if (is_bool($this->getDefaultConfigValue($key)) && is_string($value)) {
220175
return $value === '1';
221176
}
222-
if (is_string($value) && str_starts_with($value, '[') && str_ends_with($value, ']')) {
223-
$value = json_decode($value, true) ?? $value;
224-
}
225177
return $value;
226178
}, $this->getAllowedConfigKeys());
227179

228180
return array_combine($this->getAllowedConfigKeys(), $userConfigs);
229181
}
230-
231-
/**
232-
* Get the config definition for a given key
233-
*
234-
* @param string $key
235-
* @return array
236-
*/
237-
private function getConfigDefinition(string $key): array {
238-
foreach (self::ALLOWED_CONFIGS as $config) {
239-
if ($config['key'] === $key) {
240-
return $config;
241-
}
242-
}
243-
return [];
244-
}
245182
}

apps/files/src/components/FileEntryImageGroup.vue

Lines changed: 0 additions & 113 deletions
This file was deleted.

apps/files/src/components/FileEntryWrapper.vue

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)