🐛 fix: Update the settings repository to support default values.
This commit is contained in:
parent
2f1a61da47
commit
727100d53c
4 changed files with 111 additions and 101 deletions
|
|
@ -145,10 +145,9 @@ public class HttpVerticle extends AbstractVerticle {
|
|||
return;
|
||||
}
|
||||
Throwable throwable = ctx.failure();
|
||||
log.error("route: %s statusCode: %d Error: %s".formatted(
|
||||
log.error("route: %s statusCode: %d".formatted(
|
||||
ctx.currentRoute().getName(),
|
||||
statusCode,
|
||||
throwable == null ? "" : throwable.getMessage()));
|
||||
statusCode), throwable);
|
||||
HttpServerResponse response = ctx.response();
|
||||
response.setStatusCode(statusCode)
|
||||
.putHeader("Content-Type", "application/json")
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ import io.vertx.core.json.JsonObject;
|
|||
import java.util.function.Function;
|
||||
|
||||
public enum SettingKey {
|
||||
uniqueOnly(Convert::toBool),
|
||||
needToLoadImages(Convert::toBool),
|
||||
uniqueOnly(Convert::toBool, false),
|
||||
needToLoadImages(Convert::toBool, false),
|
||||
imageLoadSize,
|
||||
showSensitiveContent(Convert::toBool),
|
||||
showSensitiveContent(Convert::toBool, false),
|
||||
autoDownload(value -> new JsonObject(value).mapTo(SettingAutoRecords.class)),
|
||||
/**
|
||||
* Auto download limit for each telegram account
|
||||
|
|
@ -19,11 +19,18 @@ public enum SettingKey {
|
|||
|
||||
public final Function<String, ?> converter;
|
||||
|
||||
public final Object defaultValue;
|
||||
|
||||
SettingKey() {
|
||||
this.converter = Function.identity();
|
||||
this(Function.identity(), null);
|
||||
}
|
||||
|
||||
SettingKey(Function<String, ?> converter) {
|
||||
this(converter, null);
|
||||
}
|
||||
|
||||
SettingKey(Function<String, ?> converter, Object defaultValue) {
|
||||
this.converter = converter;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ public class SettingRepositoryImpl implements SettingRepository {
|
|||
if (rs.size() == 1) {
|
||||
return (T) key.converter.apply(rs.iterator().next());
|
||||
}
|
||||
return null;
|
||||
return key.defaultValue == null ? null : (T) key.defaultValue;
|
||||
})
|
||||
.onSuccess(r -> log.debug("Successfully fetched setting record for key: " + key))
|
||||
.onFailure(
|
||||
|
|
|
|||
|
|
@ -79,8 +79,9 @@ export const SettingsDialog: React.FC = () => {
|
|||
className="flex flex-col overflow-hidden"
|
||||
>
|
||||
<form onSubmit={handleSave} className="flex flex-col space-y-4 overflow-y-scroll">
|
||||
<div className="flex flex-col space-y-4 overflow-y-scroll">
|
||||
<p className="rounded-md bg-gray-50 p-2 text-sm text-muted-foreground shadow">
|
||||
<Bell className="h-4 w-4 inline-block mr-2" />
|
||||
<Bell className="mr-2 inline-block h-4 w-4" />
|
||||
These settings will be applied to all accounts.
|
||||
</p>
|
||||
<div className="flex w-full flex-col space-y-4 rounded-md border p-4 shadow">
|
||||
|
|
@ -97,8 +98,8 @@ export const SettingsDialog: React.FC = () => {
|
|||
<p className="text-xs text-muted-foreground">
|
||||
Show only unique file in the table. If disabled, will show
|
||||
all. <br />
|
||||
<strong>Warning:</strong> If enabled, the number of documents
|
||||
on the form will be inaccurate.
|
||||
<strong>Warning:</strong> If enabled, the number of
|
||||
documents on the form will be inaccurate.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex w-full flex-col space-y-4 rounded-md border p-4 shadow">
|
||||
|
|
@ -119,7 +120,9 @@ export const SettingsDialog: React.FC = () => {
|
|||
<Label htmlFor="image-load-size">Load Size</Label>
|
||||
<Select
|
||||
value={settings.imageLoadSize}
|
||||
onValueChange={(v) => void setSetting("imageLoadSize", v)}
|
||||
onValueChange={(v) =>
|
||||
void setSetting("imageLoadSize", v)
|
||||
}
|
||||
>
|
||||
<SelectTrigger id="image-load-size">
|
||||
<SelectValue placeholder="Select Image Load Size" />
|
||||
|
|
@ -173,10 +176,11 @@ export const SettingsDialog: React.FC = () => {
|
|||
/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div className="mt-2 flex flex-1 justify-end">
|
||||
<Button type="submit">Submit</Button>
|
||||
</div>
|
||||
</form>
|
||||
</TabsContent>
|
||||
<TabsContent
|
||||
value="statistics"
|
||||
|
|
|
|||
Loading…
Reference in a new issue