Skip to content

Commit

Permalink
SettingsService remove confusing JSON encoding step. All settings are…
Browse files Browse the repository at this point in the history
… strings, period.

fixes #922

Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Jul 26, 2023
1 parent 03374ee commit a33803b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 36 deletions.
7 changes: 5 additions & 2 deletions lib/Controller/AdminController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright (c) 2022 The Recognize contributors.
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
Expand Down Expand Up @@ -272,7 +275,7 @@ public function cron(): JSONResponse {
return new JSONResponse(['cron' => $cron]);
}

public function setSetting(string $setting, $value): JSONResponse {
public function setSetting(string $setting, string $value): JSONResponse {
try {
$this->settingsService->setSetting($setting, $value);
return new JSONResponse([], Http::STATUS_OK);
Expand All @@ -281,7 +284,7 @@ public function setSetting(string $setting, $value): JSONResponse {
}
}

public function getSetting(string $setting):JSONResponse {
public function getSetting(string $setting): JSONResponse {
return new JSONResponse(['value' => $this->settingsService->getSetting($setting)]);
}
}
73 changes: 39 additions & 34 deletions lib/Service/SettingsService.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright (c) 2022 The Recognize contributors.
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
Expand All @@ -17,44 +20,46 @@
use OCP\IConfig;

class SettingsService {
/** @var array<string,string> */
private const DEFAULTS = [
'tensorflow.cores' => 0,
'tensorflow.gpu' => false,
'tensorflow.purejs' => false,
'geo.enabled' => false,
'imagenet.enabled' => false,
'landmarks.enabled' => false,
'faces.enabled' => false,
'musicnn.enabled' => false,
'movinet.enabled' => false,
'tensorflow.cores' => '0',
'tensorflow.gpu' => 'false',
'tensorflow.purejs' => 'false',
'geo.enabled' => 'false',
'imagenet.enabled' => 'false',
'landmarks.enabled' => 'false',
'faces.enabled' => 'false',
'musicnn.enabled' => 'false',
'movinet.enabled' => 'false',
'node_binary' => '',
'clusterFaces.status' => null,
'faces.status' => null,
'imagenet.status' => null,
'landmarks.status' => null,
'movinet.status' => null,
'musicnn.status' => null,
'clusterFaces.lastRun' => 0,
'faces.lastFile' => 0,
'imagenet.lastFile' => 0,
'landmarks.lastFile' => 0,
'movinet.lastFile' => 0,
'musicnn.lastFile' => 0,
'faces.batchSize' => 500,
'imagenet.batchSize' => 100,
'landmarks.batchSize' => 100,
'movinet.batchSize' => 20,
'musicnn.batchSize' => 100,
'clusterFaces.status' => 'null',
'faces.status' => 'null',
'imagenet.status' => 'null',
'landmarks.status' => 'null',
'movinet.status' => 'null',
'musicnn.status' => 'null',
'clusterFaces.lastRun' => '0',
'faces.lastFile' => '0',
'imagenet.lastFile' => '0',
'landmarks.lastFile' => '0',
'movinet.lastFile' => '0',
'musicnn.lastFile' => '0',
'faces.batchSize' => '500',
'imagenet.batchSize' => '100',
'landmarks.batchSize' => '100',
'movinet.batchSize' => '20',
'musicnn.batchSize' => '100',
'nice_binary' => '',
'nice_value' => 0,
'nice_value' => '0',
];

/** @var array<string,string> */
private const PUREJS_DEFAULTS = [
'faces.batchSize' => 50,
'imagenet.batchSize' => 20,
'landmarks.batchSize' => 20,
'movinet.batchSize' => 5,
'musicnn.batchSize' => 20,
'faces.batchSize' => '50',
'imagenet.batchSize' => '20',
'landmarks.batchSize' => '20',
'movinet.batchSize' => '5',
'musicnn.batchSize' => '20',
];

private IConfig $config;
Expand All @@ -71,9 +76,9 @@ public function __construct(IConfig $config, IJobList $jobList) {
*/
public function getSetting(string $key): string {
if (strpos($key, 'batchSize') !== false) {
return $this->config->getAppValue('recognize', $key, $this->getSetting('tensorflow.purejs') === 'false' ? json_encode(self::DEFAULTS[$key]) : json_encode(self::PUREJS_DEFAULTS[$key]));
return $this->config->getAppValue('recognize', $key, $this->getSetting('tensorflow.purejs') === 'false' ? self::DEFAULTS[$key] : self::PUREJS_DEFAULTS[$key]);
}
return $this->config->getAppValue('recognize', $key, json_encode(self::DEFAULTS[$key]));
return $this->config->getAppValue('recognize', $key, self::DEFAULTS[$key]);
}

/**
Expand Down

0 comments on commit a33803b

Please sign in to comment.