mirror of
https://github.com/HangarMC/Hangar.git
synced 2025-02-17 15:01:42 +08:00
Some response/validation changes
Fixes HANGAR-1E Fixes HANGAR-1F Fixes HANGAR-S Fixes HANGAR-T Fixes HANGAR-1B Fixes HANGAR-1N
This commit is contained in:
parent
e2ab2bea25
commit
de6b54b69a
@ -1,5 +1,6 @@
|
||||
package io.papermc.hangar.controller.extras.pagination;
|
||||
|
||||
import io.papermc.hangar.exceptions.HangarApiException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -28,6 +29,6 @@ public class FilterRegistry {
|
||||
if (this.filters.containsKey(filterClass)) {
|
||||
return (T) this.filters.get(filterClass);
|
||||
}
|
||||
throw new IllegalArgumentException(filterClass + " is not a registered filter");
|
||||
throw new HangarApiException(filterClass + " is not a registered filter");
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.papermc.hangar.controller.extras.pagination;
|
||||
|
||||
import io.papermc.hangar.exceptions.HangarApiException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -55,7 +56,7 @@ public enum SorterRegistry implements Sorter {
|
||||
if (SORTERS.containsKey(name)) {
|
||||
return SORTERS.get(name);
|
||||
}
|
||||
throw new IllegalArgumentException(name + " is not a registered sorter");
|
||||
throw new HangarApiException(name + " is not a registered sorter");
|
||||
}
|
||||
|
||||
public enum SortDirection {
|
||||
|
@ -90,8 +90,8 @@ public class RequestPaginationResolver implements HandlerMethodArgumentResolver
|
||||
@Override
|
||||
public RequestPagination resolveArgument(final @NotNull MethodParameter parameter, final ModelAndViewContainer mavContainer, final @NotNull NativeWebRequest webRequest, final WebDataBinderFactory binderFactory) {
|
||||
final RequestPagination pagination = this.create(
|
||||
ApiUtils.mapParameter(webRequest, "offset", Long::parseLong),
|
||||
ApiUtils.mapParameter(webRequest, "limit", Long::parseLong),
|
||||
ApiUtils.mapParameter(webRequest, "offset", this::parseLong),
|
||||
ApiUtils.mapParameter(webRequest, "limit", this::parseLong),
|
||||
parameter.getParameterAnnotation(ConfigurePagination.class)
|
||||
);
|
||||
|
||||
@ -147,4 +147,12 @@ public class RequestPaginationResolver implements HandlerMethodArgumentResolver
|
||||
|
||||
return pagination;
|
||||
}
|
||||
|
||||
private long parseLong(final String s) {
|
||||
try {
|
||||
return Long.parseLong(s);
|
||||
} catch (final NumberFormatException e) {
|
||||
throw new HangarApiException(s + " is not a valid long");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
@ -60,6 +61,10 @@ public class DownloadService extends HangarComponent {
|
||||
|
||||
public ResponseEntity<?> downloadVersion(final String user, final String project, final String versionString, final Platform platform) {
|
||||
final ProjectVersionDownloadTable download = this.downloadsDAO.getDownloadByPlatform(user, project, versionString, platform);
|
||||
if (download == null) {
|
||||
throw new HangarApiException(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(download.getExternalUrl())) {
|
||||
return ResponseEntity.status(301).header("Location", download.getExternalUrl()).build();
|
||||
} else if (this.fileService instanceof S3FileService){
|
||||
|
@ -177,9 +177,11 @@ public class VersionFactory extends HangarComponent {
|
||||
// load meta
|
||||
pluginDataFile = this.pluginDataService.loadMeta(pluginFileName, bytes, this.getHangarPrincipal().getUserId());
|
||||
} catch (final ConfigurateException configurateException) {
|
||||
this.logger.error("Error while reading file metadata while uploading {} for {}", pluginFileName, this.getHangarPrincipal().getName(), configurateException);
|
||||
this.fileService.deleteDirectory(userTempDir);
|
||||
throw new HangarApiException(HttpStatus.BAD_REQUEST, "version.new.error.metaNotFound");
|
||||
} catch (final HangarApiException apiException) {
|
||||
this.fileService.deleteDirectory(userTempDir);
|
||||
throw apiException;
|
||||
} catch (final Exception e) {
|
||||
this.logger.error("Error while uploading {} for {}", pluginFileName, this.getHangarPrincipal().getName(), e);
|
||||
this.fileService.deleteDirectory(userTempDir);
|
||||
|
Loading…
Reference in New Issue
Block a user