MCPcopy Create free account
hub / github.com/Rello/analytics / jsonContent

Method jsonContent

lib/Controller/DatasourceController.php:231–263  ·  view source on GitHub ↗

Browse only a JSON source supplied by the authenticated user, never a shared report. */

(int $type, string $options = '{}')

Source from the content-addressed store, hash-verified

229
230 /** Browse only a JSON source supplied by the authenticated user, never a shared report. */
231 #[NoAdminRequired]
232 public function jsonContent(int $type, string $options = '{}'): DataResponse {
233 $user = $this->userSession->getUser();
234 $settings = json_decode($options, true);
235 if ($user === null || !is_array($settings)
236 || !in_array($type, [self::DATASET_TYPE_LOCAL_JSON, self::DATASET_TYPE_EXTERNAL_JSON], true)) {
237 return new DataResponse(['error' => $this->l10n->t('Data source not available anymore')], 400);
238 }
239 try {
240 $this->validateOptions($type, $settings);
241 } catch (\InvalidArgumentException $e) {
242 return new DataResponse(['error' => $e->getMessage()], 400);
243 }
244 // Browsing must work before an extraction path has been chosen.
245 $settings['path'] = '';
246 $settings['timestamp'] = 'false';
247 try {
248 $result = $this->read($type, [
249 'link' => json_encode($settings), 'user_id' => $user->getUID(), 'filteroptions' => '',
250 ], false);
251 if (!empty($result['error']) || !is_string($result['rawdata'] ?? null)) {
252 return new DataResponse(['error' => $this->l10n->t('Could not load JSON data. Check the datasource settings.')], 400);
253 }
254 if (strlen($result['rawdata']) > 2 * 1024 * 1024) {
255 return new DataResponse(['error' => $this->l10n->t('This JSON is too large to browse. Enter the Object path manually.')], 400);
256 }
257 // Do not return request headers, authentication, or other datasource metadata.
258 return new DataResponse(['content' => $result['rawdata']]);
259 } catch (\Throwable $e) {
260 $this->logger->debug('Could not browse JSON data', ['exception' => $e]);
261 return new DataResponse(['error' => $this->l10n->t('Could not load JSON data. Check the datasource settings.')], 400);
262 }
263 }
264
265 /**
266 * Get the data from a data source;

Calls 6

validateOptionsMethod · 0.95
readMethod · 0.95
getUserMethod · 0.80
tMethod · 0.45
getUIDMethod · 0.45
debugMethod · 0.45