|
7 | 7 |
|
8 | 8 | namespace OCA\ContextChat\Service; |
9 | 9 |
|
| 10 | +use OC\Files\SetupManager; |
10 | 11 | use OCA\ContextChat\Logger; |
11 | 12 | use OCA\ContextChat\Public\ContentManager; |
12 | 13 | use OCA\ContextChat\Public\IContentProvider; |
@@ -166,14 +167,34 @@ public function getEnrichedSources(string $userId, string ...$sources): array { |
166 | 167 | } |
167 | 168 | } |
168 | 169 |
|
169 | | - # for files |
170 | | - foreach ($sources as $source) { |
171 | | - if (!str_starts_with($source, ProviderConfigService::getDefaultProviderKey() . ': ')) { |
172 | | - continue; |
173 | | - } |
174 | | - $enrichedSources[] = $this->getMetadataObjectForId($userId, $source); |
| 170 | + $setupManager = \OCP\Server::get(SetupManager::class); |
| 171 | + $user = $this->userManager->get($userId); |
| 172 | + |
| 173 | + if ($user === null) { |
| 174 | + $this->logger->warning('User not found for enriching sources', ['userId' => $userId]); |
| 175 | + return $enrichedSources; |
175 | 176 | } |
176 | 177 |
|
177 | | - return $enrichedSources; |
| 178 | + try { |
| 179 | + $setupManager->setupForUser($user); |
| 180 | + } catch (\Throwable $e) { |
| 181 | + $this->logger->error('Error setting up filesystem for user ' . $userId . ': ' . $e->getMessage(), ['exception' => $e]); |
| 182 | + return $enrichedSources; |
| 183 | + } |
| 184 | + |
| 185 | + try { |
| 186 | + # for files |
| 187 | + foreach ($sources as $source) { |
| 188 | + if (!str_starts_with($source, ProviderConfigService::getDefaultProviderKey() . ': ')) { |
| 189 | + continue; |
| 190 | + } |
| 191 | + $enrichedSources[] = $this->getMetadataObjectForId($userId, $source); |
| 192 | + } |
| 193 | + } catch (\Throwable $e) { |
| 194 | + $this->logger->error('Error enriching file sources: ' . $e->getMessage(), ['exception' => $e]); |
| 195 | + } finally { |
| 196 | + $setupManager->tearDown(); |
| 197 | + return $enrichedSources; |
| 198 | + } |
178 | 199 | } |
179 | 200 | } |
0 commit comments