fixed invalidUrl in license

This commit is contained in:
Jake Potrebic 2021-03-25 20:06:52 -07:00
parent c2a76f819e
commit bf0ff3c020
No known key found for this signature in database
GPG Key ID: 7C58557EC9C421F8
6 changed files with 10 additions and 8 deletions

View File

@ -612,6 +612,7 @@ const msgs: LocaleMessageObject = {
maxLength: 'Maximum length is {0}',
minLength: 'Minimum length is {0}',
invalidFormat: '{0} is invalid',
invalidUrl: 'Invalid URL format',
},
error: {
userLocked: 'Your account is locked.',

View File

@ -248,7 +248,7 @@ const createUtil = ({ store, error, app: { i18n } }: Context) => {
);
},
requireNonEmptyArray: (name: TranslateResult = 'Field') => (v: any[]) => v.length > 0 || i18n.t('validation.required', [name]),
url: (v: string) => !v || new RegExp((store.state as RootState).validations.urlRegex).test(v) || i18n.t('general.error.invalidUrl'),
url: (v: string) => !v || new RegExp((store.state as RootState).validations.urlRegex).test(v) || i18n.t('validation.invalidUrl'),
regex: (name: TranslateResult = 'Field', regexp: string) => (v: string) => {
return !v || new RegExp(regexp).test(v) || i18n.t('validation.invalidFormat', [name]);
},

View File

@ -1,6 +1,7 @@
package io.papermc.hangar.controller.extras;
import io.papermc.hangar.config.hangar.HangarConfig;
import io.papermc.hangar.exceptions.HangarApiException;
import io.papermc.hangar.util.StaticContextAccessor;
import org.jetbrains.annotations.Nullable;
import org.springframework.http.HttpStatus;
@ -18,7 +19,7 @@ public class ApiUtils {
* @return actual limit
*/
public static long limitOrDefault(@Nullable Long limit) {
if (limit != null && limit < 1) throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Limit should be greater than 0");
if (limit != null && limit < 1) throw new HangarApiException(HttpStatus.BAD_REQUEST, "Limit should be greater than 0");
return Math.min(limit == null ? hangarConfig.projects.getInitLoad() : limit, hangarConfig.projects.getInitLoad());
}

View File

@ -11,7 +11,7 @@ import java.util.Map;
public class ProjectLicense {
private final String name;
@Validate(SpEL = "@validate.regex(#root, @hangarConfig.urlRegex)", message = "general.error.invalidUrl")
@Validate(SpEL = "@validate.optionalRegex(#root, @hangarConfig.urlRegex)", message = "validation.invalidUrl")
private final String url;
@JdbiConstructor

View File

@ -11,13 +11,13 @@ import java.util.Collection;
public class ProjectSettings {
@Validate(SpEL = "@validate.optionalRegex(#root, @hangarConfig.urlRegex)", message = "general.error.invalidUrl")
@Validate(SpEL = "@validate.optionalRegex(#root, @hangarConfig.urlRegex)", message = "validation.invalidUrl")
private final String homepage;
@Validate(SpEL = "@validate.optionalRegex(#root, @hangarConfig.urlRegex)", message = "general.error.invalidUrl")
@Validate(SpEL = "@validate.optionalRegex(#root, @hangarConfig.urlRegex)", message = "validation.invalidUrl")
private final String issues;
@Validate(SpEL = "@validate.optionalRegex(#root, @hangarConfig.urlRegex)", message = "general.error.invalidUrl")
@Validate(SpEL = "@validate.optionalRegex(#root, @hangarConfig.urlRegex)", message = "validation.invalidUrl")
private final String source;
@Validate(SpEL = "@validate.optionalRegex(#root, @hangarConfig.urlRegex)", message = "general.error.invalidUrl")
@Validate(SpEL = "@validate.optionalRegex(#root, @hangarConfig.urlRegex)", message = "validation.invalidUrl")
private final String support;
@Valid
private final ProjectLicense license;

View File

@ -33,7 +33,7 @@ public class PendingVersion {
@NotBlank(message = "version.new.error.noDescription")
private final String description;
private final FileInfo fileInfo;
@Validate(SpEL = "@validate.optionalRegex(#root, @hangarConfig.urlRegex)", message = "general.error.invalidUrl")
@Validate(SpEL = "@validate.optionalRegex(#root, @hangarConfig.urlRegex)", message = "validation.invalidUrl")
private final String externalUrl;
@NotBlank(message = "version.new.error.channel.noName")
@Validate(SpEL = "@validate.regex(#root, @hangarConfig.channels.nameRegex)", message = "channel.modal.error.invalidName")