🐛 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,104 +79,108 @@ 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">
|
||||||
<p className="rounded-md bg-gray-50 p-2 text-sm text-muted-foreground shadow">
|
<div className="flex flex-col space-y-4 overflow-y-scroll">
|
||||||
<Bell className="h-4 w-4 inline-block mr-2" />
|
<p className="rounded-md bg-gray-50 p-2 text-sm text-muted-foreground shadow">
|
||||||
These settings will be applied to all accounts.
|
<Bell className="mr-2 inline-block h-4 w-4" />
|
||||||
</p>
|
These settings will be applied to all accounts.
|
||||||
<div className="flex w-full flex-col space-y-4 rounded-md border p-4 shadow">
|
|
||||||
<div className="flex items-center space-x-2">
|
|
||||||
<Label htmlFor="unique-only">Unique Only</Label>
|
|
||||||
<Checkbox
|
|
||||||
id="unique-only"
|
|
||||||
checked={settings?.uniqueOnly === "true"}
|
|
||||||
onCheckedChange={(checked) =>
|
|
||||||
void setSetting("uniqueOnly", String(checked))
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<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.
|
|
||||||
</p>
|
</p>
|
||||||
</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">
|
<div className="flex items-center space-x-2">
|
||||||
<div className="flex items-center space-x-2">
|
<Label htmlFor="unique-only">Unique Only</Label>
|
||||||
<Label htmlFor="need-load-preview-images">
|
<Checkbox
|
||||||
Need Load Preview Images
|
id="unique-only"
|
||||||
</Label>
|
checked={settings?.uniqueOnly === "true"}
|
||||||
<Checkbox
|
onCheckedChange={(checked) =>
|
||||||
id="need-load-preview-images"
|
void setSetting("uniqueOnly", String(checked))
|
||||||
checked={settings?.needToLoadImages === "true"}
|
}
|
||||||
onCheckedChange={(checked) => {
|
/>
|
||||||
void setSetting("needToLoadImages", String(checked));
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
{settings?.needToLoadImages === "true" && (
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label htmlFor="image-load-size">Load Size</Label>
|
|
||||||
<Select
|
|
||||||
value={settings.imageLoadSize}
|
|
||||||
onValueChange={(v) => void setSetting("imageLoadSize", v)}
|
|
||||||
>
|
|
||||||
<SelectTrigger id="image-load-size">
|
|
||||||
<SelectValue placeholder="Select Image Load Size" />
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
{imageLoadSizeOptions.map((option) => (
|
|
||||||
<SelectItem key={option.value} value={option.value}>
|
|
||||||
{option.label}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
The size of the image to load in the browser.
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
<p className="text-xs text-muted-foreground">
|
||||||
</div>
|
Show only unique file in the table. If disabled, will show
|
||||||
<div className="flex w-full flex-col space-y-4 rounded-md border p-4 shadow">
|
all. <br />
|
||||||
<div className="flex items-center space-x-2">
|
<strong>Warning:</strong> If enabled, the number of
|
||||||
<Label htmlFor="show-sensitive-content">
|
documents on the form will be inaccurate.
|
||||||
Show Sensitive Content
|
</p>
|
||||||
</Label>
|
|
||||||
<Checkbox
|
|
||||||
id="show-sensitive-content"
|
|
||||||
checked={settings?.showSensitiveContent === "true"}
|
|
||||||
onCheckedChange={(checked) =>
|
|
||||||
void setSetting("showSensitiveContent", String(checked))
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<p className="text-xs text-muted-foreground">
|
<div className="flex w-full flex-col space-y-4 rounded-md border p-4 shadow">
|
||||||
Show sensitive content in the table, Will use a spoiler to
|
<div className="flex items-center space-x-2">
|
||||||
hide sensitive content if disabled.
|
<Label htmlFor="need-load-preview-images">
|
||||||
</p>
|
Need Load Preview Images
|
||||||
</div>
|
</Label>
|
||||||
<div className="flex w-full flex-col space-y-4 rounded-md border p-4 shadow">
|
<Checkbox
|
||||||
<Label>Auto Download Settings</Label>
|
id="need-load-preview-images"
|
||||||
<div className="flex flex-col space-y-2">
|
checked={settings?.needToLoadImages === "true"}
|
||||||
<Label htmlFor="limit">Limit Per Account</Label>
|
onCheckedChange={(checked) => {
|
||||||
<Input
|
void setSetting("needToLoadImages", String(checked));
|
||||||
id="limit"
|
}}
|
||||||
className="w-24"
|
/>
|
||||||
type="number"
|
</div>
|
||||||
min={1}
|
{settings?.needToLoadImages === "true" && (
|
||||||
max={10}
|
<div className="space-y-2">
|
||||||
value={settings?.autoDownloadLimit ?? 5}
|
<Label htmlFor="image-load-size">Load Size</Label>
|
||||||
onChange={(e) => {
|
<Select
|
||||||
void setSetting("autoDownloadLimit", e.target.value);
|
value={settings.imageLoadSize}
|
||||||
}}
|
onValueChange={(v) =>
|
||||||
/>
|
void setSetting("imageLoadSize", v)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<SelectTrigger id="image-load-size">
|
||||||
|
<SelectValue placeholder="Select Image Load Size" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{imageLoadSizeOptions.map((option) => (
|
||||||
|
<SelectItem key={option.value} value={option.value}>
|
||||||
|
{option.label}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
The size of the image to load in the browser.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
<div className="flex w-full flex-col space-y-4 rounded-md border p-4 shadow">
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Label htmlFor="show-sensitive-content">
|
||||||
|
Show Sensitive Content
|
||||||
|
</Label>
|
||||||
|
<Checkbox
|
||||||
|
id="show-sensitive-content"
|
||||||
|
checked={settings?.showSensitiveContent === "true"}
|
||||||
|
onCheckedChange={(checked) =>
|
||||||
|
void setSetting("showSensitiveContent", String(checked))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Show sensitive content in the table, Will use a spoiler to
|
||||||
|
hide sensitive content if disabled.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex w-full flex-col space-y-4 rounded-md border p-4 shadow">
|
||||||
|
<Label>Auto Download Settings</Label>
|
||||||
|
<div className="flex flex-col space-y-2">
|
||||||
|
<Label htmlFor="limit">Limit Per Account</Label>
|
||||||
|
<Input
|
||||||
|
id="limit"
|
||||||
|
className="w-24"
|
||||||
|
type="number"
|
||||||
|
min={1}
|
||||||
|
max={10}
|
||||||
|
value={settings?.autoDownloadLimit ?? 5}
|
||||||
|
onChange={(e) => {
|
||||||
|
void setSetting("autoDownloadLimit", e.target.value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="mt-2 flex flex-1 justify-end">
|
||||||
|
<Button type="submit">Submit</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<div className="mt-2 flex flex-1 justify-end">
|
|
||||||
<Button type="submit">Submit</Button>
|
|
||||||
</div>
|
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
<TabsContent
|
<TabsContent
|
||||||
value="statistics"
|
value="statistics"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue