Skip to content

Commit 578fa28

Browse files
Merge pull request #474 from community-scripts/fix/404
fix: allow domain names for APT Cacher in container creation UI
2 parents d29f71a + 9e6154b commit 578fa28

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/app/_components/ConfigurationModal.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ export function ConfigurationModal({
199199
return !isNaN(num) && num > 0;
200200
};
201201

202+
const validateHostname = (hostname: string): boolean => {
203+
if (!hostname || hostname.length > 253) return false;
204+
const label = /^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$/;
205+
const labels = hostname.split('.');
206+
return labels.length >= 1 && labels.every(l => l.length >= 1 && l.length <= 63 && label.test(l));
207+
};
208+
209+
const validateAptCacherAddress = (value: string): boolean => {
210+
return validateIPv4(value) || validateHostname(value);
211+
};
212+
202213
const validateForm = (): boolean => {
203214
const newErrors: Record<string, string> = {};
204215

@@ -216,8 +227,8 @@ export function ConfigurationModal({
216227
if (advancedVars.var_ns && !validateIPv4(advancedVars.var_ns as string)) {
217228
newErrors.var_ns = 'Invalid IPv4 address';
218229
}
219-
if (advancedVars.var_apt_cacher_ip && !validateIPv4(advancedVars.var_apt_cacher_ip as string)) {
220-
newErrors.var_apt_cacher_ip = 'Invalid IPv4 address';
230+
if (advancedVars.var_apt_cacher_ip && !validateAptCacherAddress(advancedVars.var_apt_cacher_ip as string)) {
231+
newErrors.var_apt_cacher_ip = 'Invalid IPv4 address or hostname';
221232
}
222233
// Validate IPv4 CIDR if network mode is static
223234
const netValue = advancedVars.var_net;
@@ -904,13 +915,13 @@ export function ConfigurationModal({
904915
</div>
905916
<div>
906917
<label className="block text-sm font-medium text-foreground mb-2">
907-
APT Cacher IP
918+
APT Cacher host or IP
908919
</label>
909920
<Input
910921
type="text"
911922
value={typeof advancedVars.var_apt_cacher_ip === 'boolean' ? '' : String(advancedVars.var_apt_cacher_ip ?? '')}
912923
onChange={(e) => updateAdvancedVar('var_apt_cacher_ip', e.target.value)}
913-
placeholder="192.168.1.10"
924+
placeholder="192.168.1.10 or apt-cacher.internal"
914925
className={errors.var_apt_cacher_ip ? 'border-destructive' : ''}
915926
/>
916927
{errors.var_apt_cacher_ip && (

0 commit comments

Comments
 (0)