Skip to content

Commit e225c73

Browse files
authored
Merge pull request #4 from TonloOO/main
refactor: normalize image validation payload after parsing
2 parents 644aa96 + 76798f7 commit e225c73

File tree

1 file changed

+40
-46
lines changed

1 file changed

+40
-46
lines changed

dify-helm-watchdog/src/components/version-explorer.tsx

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ const formatDate = (input?: string | null) => {
140140
}).format(date);
141141
};
142142

143+
import { normalizeValidationPayload } from "@/lib/validation";
144+
143145
const parseValidationPayload = (
144146
raw: string | undefined | null,
145147
): { payload: ImageValidationPayload | null; error: string | null } => {
@@ -149,7 +151,7 @@ const parseValidationPayload = (
149151

150152
try {
151153
const parsed = JSON.parse(raw) as ImageValidationPayload;
152-
return { payload: parsed, error: null };
154+
return { payload: normalizeValidationPayload(parsed), error: null };
153155
} catch (thrown) {
154156
return {
155157
payload: null,
@@ -341,32 +343,32 @@ export function VersionExplorer({ data }: VersionExplorerProps) {
341343
const [valuesText, imagesText, validationText] = await Promise.all([
342344
shouldFetchValues || isReloading
343345
? fetch(version.values.url).then((response) => {
344-
if (!response.ok) {
345-
throw new Error("Failed to download cached YAML artifacts");
346-
}
347-
return response.text();
348-
})
346+
if (!response.ok) {
347+
throw new Error("Failed to download cached YAML artifacts");
348+
}
349+
return response.text();
350+
})
349351
: Promise.resolve(version.values.inline ?? ""),
350352
shouldFetchImages || isReloading
351353
? fetch(version.images.url).then((response) => {
352-
if (!response.ok) {
353-
throw new Error("Failed to download cached YAML artifacts");
354-
}
355-
return response.text();
356-
})
354+
if (!response.ok) {
355+
throw new Error("Failed to download cached YAML artifacts");
356+
}
357+
return response.text();
358+
})
357359
: Promise.resolve(version.images.inline ?? ""),
358360
shouldFetchValidation
359361
? fetch(validationAsset!.url).then((response) => {
360-
if (!response.ok) {
361-
throw new Error("Failed to download image validation payload");
362-
}
363-
return response.text();
364-
})
362+
if (!response.ok) {
363+
throw new Error("Failed to download image validation payload");
364+
}
365+
return response.text();
366+
})
365367
: Promise.resolve(
366-
typeof validationAsset?.inline === "string"
367-
? validationAsset.inline
368-
: null,
369-
),
368+
typeof validationAsset?.inline === "string"
369+
? validationAsset.inline
370+
: null,
371+
),
370372
]);
371373

372374
if (!cancelled) {
@@ -589,9 +591,8 @@ export function VersionExplorer({ data }: VersionExplorerProps) {
589591
href="https://langgenius.github.io/dify-helm/#/"
590592
target="_blank"
591593
rel="noopener noreferrer"
592-
className={`inline-flex items-center gap-1.5 rounded-full border border-primary bg-primary/10 px-3 py-0.5 text-[10px] font-semibold uppercase tracking-[0.3em] transition hover:bg-primary/20 active:bg-primary active:text-primary-foreground ${
593-
resolvedTheme === "dark" ? "text-white" : "text-primary"
594-
}`}
594+
className={`inline-flex items-center gap-1.5 rounded-full border border-primary bg-primary/10 px-3 py-0.5 text-[10px] font-semibold uppercase tracking-[0.3em] transition hover:bg-primary/20 active:bg-primary active:text-primary-foreground ${resolvedTheme === "dark" ? "text-white" : "text-primary"
595+
}`}
595596
>
596597
<ArrowUpRight className="h-2.5 w-2.5" />
597598
Dify Helm
@@ -678,50 +679,44 @@ export function VersionExplorer({ data }: VersionExplorerProps) {
678679
whileHover={{ scale: 1.02 }}
679680
whileTap={{ scale: 0.98 }}
680681
transition={{ type: "spring", stiffness: 400, damping: 25 }}
681-
className={`group flex min-h-[92px] w-full flex-col gap-1 rounded-2xl border px-4 py-3 text-left transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-ring ${
682-
isActive
682+
className={`group flex min-h-[92px] w-full flex-col gap-1 rounded-2xl border px-4 py-3 text-left transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-ring ${isActive
683683
? "border-primary bg-primary text-primary-foreground"
684684
: "border-border bg-transparent text-muted-foreground hover:border-accent hover:bg-accent/10 hover:text-foreground"
685-
}`}
685+
}`}
686686
>
687687
<div className="flex items-start justify-between gap-3">
688688
<span
689-
className={`text-base font-semibold tracking-wide ${
690-
isActive ? "text-primary-foreground" : "text-foreground"
691-
}`}
689+
className={`text-base font-semibold tracking-wide ${isActive ? "text-primary-foreground" : "text-foreground"
690+
}`}
692691
>
693692
v{version.version}
694693
</span>
695694
<span
696-
className={`text-[10px] font-mono uppercase tracking-widest ${
697-
isActive ? "text-primary-foreground/90" : "text-muted-foreground"
698-
}`}
695+
className={`text-[10px] font-mono uppercase tracking-widest ${isActive ? "text-primary-foreground/90" : "text-muted-foreground"
696+
}`}
699697
>
700698
sha256:{version.values.hash.slice(0, 7)}
701699
</span>
702700
</div>
703701
<div
704-
className={`flex flex-wrap items-center gap-3 text-[11px] uppercase tracking-[0.2em] ${
705-
isActive ? "text-primary-foreground/90" : "text-muted-foreground"
706-
}`}
702+
className={`flex flex-wrap items-center gap-3 text-[11px] uppercase tracking-[0.2em] ${isActive ? "text-primary-foreground/90" : "text-muted-foreground"
703+
}`}
707704
>
708705
{version.appVersion && (
709706
<span
710-
className={`rounded-full border px-2 py-0.5 ${
711-
isActive
707+
className={`rounded-full border px-2 py-0.5 ${isActive
712708
? "border-primary-foreground/30 bg-primary-foreground/10 text-primary-foreground"
713709
: "border-border bg-muted text-muted-foreground"
714-
}`}
710+
}`}
715711
>
716712
App {version.appVersion}
717713
</span>
718714
)}
719715
</div>
720716
{version.createTime && (
721717
<span
722-
className={`mt-1 text-[9px] uppercase tracking-[0.05em] ${
723-
isActive ? "text-primary-foreground/80" : "text-muted-foreground/80"
724-
}`}
718+
className={`mt-1 text-[9px] uppercase tracking-[0.05em] ${isActive ? "text-primary-foreground/80" : "text-muted-foreground/80"
719+
}`}
725720
>
726721
{formatDate(version.createTime)}
727722
</span>
@@ -802,16 +797,15 @@ export function VersionExplorer({ data }: VersionExplorerProps) {
802797
key={tab.id}
803798
type="button"
804799
onClick={() => setActiveArtifact(tab.id)}
805-
className={`relative z-10 flex-1 rounded-full px-4 py-2 text-xs font-semibold uppercase tracking-[0.25em] transition-colors ${
806-
isActive
800+
className={`relative z-10 flex-1 rounded-full px-4 py-2 text-xs font-semibold uppercase tracking-[0.25em] transition-colors ${isActive
807801
? "text-primary-foreground"
808802
: "text-muted-foreground hover:text-foreground"
809-
}`}
803+
}`}
810804
whileHover={
811805
!isActive
812806
? {
813-
scale: 1.02,
814-
}
807+
scale: 1.02,
808+
}
815809
: {}
816810
}
817811
whileTap={{

0 commit comments

Comments
 (0)