🐛 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;
|
return;
|
||||||
}
|
}
|
||||||
Throwable throwable = ctx.failure();
|
Throwable throwable = ctx.failure();
|
||||||
log.error("route: %s statusCode: %d Error: %s".formatted(
|
log.error("route: %s statusCode: %d".formatted(
|
||||||
ctx.currentRoute().getName(),
|
ctx.currentRoute().getName(),
|
||||||
statusCode,
|
statusCode), throwable);
|
||||||
throwable == null ? "" : throwable.getMessage()));
|
|
||||||
HttpServerResponse response = ctx.response();
|
HttpServerResponse response = ctx.response();
|
||||||
response.setStatusCode(statusCode)
|
response.setStatusCode(statusCode)
|
||||||
.putHeader("Content-Type", "application/json")
|
.putHeader("Content-Type", "application/json")
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@ import io.vertx.core.json.JsonObject;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public enum SettingKey {
|
public enum SettingKey {
|
||||||
uniqueOnly(Convert::toBool),
|
uniqueOnly(Convert::toBool, false),
|
||||||
needToLoadImages(Convert::toBool),
|
needToLoadImages(Convert::toBool, false),
|
||||||
imageLoadSize,
|
imageLoadSize,
|
||||||
showSensitiveContent(Convert::toBool),
|
showSensitiveContent(Convert::toBool, false),
|
||||||
autoDownload(value -> new JsonObject(value).mapTo(SettingAutoRecords.class)),
|
autoDownload(value -> new JsonObject(value).mapTo(SettingAutoRecords.class)),
|
||||||
/**
|
/**
|
||||||
* Auto download limit for each telegram account
|
* Auto download limit for each telegram account
|
||||||
|
|
@ -19,11 +19,18 @@ public enum SettingKey {
|
||||||
|
|
||||||
public final Function<String, ?> converter;
|
public final Function<String, ?> converter;
|
||||||
|
|
||||||
|
public final Object defaultValue;
|
||||||
|
|
||||||
SettingKey() {
|
SettingKey() {
|
||||||
this.converter = Function.identity();
|
this(Function.identity(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingKey(Function<String, ?> converter) {
|
SettingKey(Function<String, ?> converter) {
|
||||||
|
this(converter, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
SettingKey(Function<String, ?> converter, Object defaultValue) {
|
||||||
this.converter = converter;
|
this.converter = converter;
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ public class SettingRepositoryImpl implements SettingRepository {
|
||||||
if (rs.size() == 1) {
|
if (rs.size() == 1) {
|
||||||
return (T) key.converter.apply(rs.iterator().next());
|
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))
|
.onSuccess(r -> log.debug("Successfully fetched setting record for key: " + key))
|
||||||
.onFailure(
|
.onFailure(
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import {
|
||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select";
|
} from "@/components/ui/select";
|
||||||
import {Bell, Settings} from "lucide-react";
|
import { Bell, Settings } from "lucide-react";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import { VisuallyHidden } from "@radix-ui/react-visually-hidden";
|
import { VisuallyHidden } from "@radix-ui/react-visually-hidden";
|
||||||
|
|
@ -79,8 +79,9 @@ export const SettingsDialog: React.FC = () => {
|
||||||
className="flex flex-col overflow-hidden"
|
className="flex flex-col overflow-hidden"
|
||||||
>
|
>
|
||||||
<form onSubmit={handleSave} className="flex flex-col space-y-4 overflow-y-scroll">
|
<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">
|
<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.
|
These settings will be applied to all accounts.
|
||||||
</p>
|
</p>
|
||||||
<div className="flex w-full flex-col space-y-4 rounded-md border p-4 shadow">
|
<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">
|
<p className="text-xs text-muted-foreground">
|
||||||
Show only unique file in the table. If disabled, will show
|
Show only unique file in the table. If disabled, will show
|
||||||
all. <br />
|
all. <br />
|
||||||
<strong>Warning:</strong> If enabled, the number of documents
|
<strong>Warning:</strong> If enabled, the number of
|
||||||
on the form will be inaccurate.
|
documents on the form will be inaccurate.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex w-full flex-col space-y-4 rounded-md border p-4 shadow">
|
<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>
|
<Label htmlFor="image-load-size">Load Size</Label>
|
||||||
<Select
|
<Select
|
||||||
value={settings.imageLoadSize}
|
value={settings.imageLoadSize}
|
||||||
onValueChange={(v) => void setSetting("imageLoadSize", v)}
|
onValueChange={(v) =>
|
||||||
|
void setSetting("imageLoadSize", v)
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<SelectTrigger id="image-load-size">
|
<SelectTrigger id="image-load-size">
|
||||||
<SelectValue placeholder="Select Image Load Size" />
|
<SelectValue placeholder="Select Image Load Size" />
|
||||||
|
|
@ -173,10 +176,11 @@ export const SettingsDialog: React.FC = () => {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</div>
|
||||||
<div className="mt-2 flex flex-1 justify-end">
|
<div className="mt-2 flex flex-1 justify-end">
|
||||||
<Button type="submit">Submit</Button>
|
<Button type="submit">Submit</Button>
|
||||||
</div>
|
</div>
|
||||||
|
</form>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
<TabsContent
|
<TabsContent
|
||||||
value="statistics"
|
value="statistics"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue