Remove isPublic request part when uploading image
This commit is contained in:
parent
8e95b6ef9b
commit
b011906273
@ -96,8 +96,7 @@ public class ImageController extends BaseController {
|
||||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
|
||||
@PostMapping("/api/image")
|
||||
public TbResourceInfo uploadImage(@RequestPart MultipartFile file,
|
||||
@RequestPart(required = false) String title,
|
||||
@RequestPart(required = false) Boolean isPublic) throws Exception {
|
||||
@RequestPart(required = false) String title) throws Exception {
|
||||
SecurityUser user = getCurrentUser();
|
||||
TbResource image = new TbResource();
|
||||
image.setTenantId(user.getTenantId());
|
||||
@ -110,12 +109,12 @@ public class ImageController extends BaseController {
|
||||
} else {
|
||||
image.setTitle(file.getOriginalFilename());
|
||||
}
|
||||
image.setPublic(isPublic != null ? isPublic : true);
|
||||
image.setResourceType(ResourceType.IMAGE);
|
||||
ImageDescriptor descriptor = new ImageDescriptor();
|
||||
descriptor.setMediaType(file.getContentType());
|
||||
image.setDescriptorValue(descriptor);
|
||||
image.setData(file.getBytes());
|
||||
image.setPublic(true);
|
||||
return tbImageService.save(image, user);
|
||||
}
|
||||
|
||||
|
||||
@ -214,7 +214,7 @@ public class ImageControllerTest extends AbstractControllerTest {
|
||||
|
||||
assertThat(imageInfo.isPublic()).isTrue();
|
||||
assertThat(imageInfo.getPublicResourceKey()).hasSize(32);
|
||||
assertThat(imageInfo.getLink()).isEqualTo("/api/images/public/" + imageInfo.getPublicResourceKey());
|
||||
assertThat(imageInfo.getPublicLink()).isEqualTo("/api/images/public/" + imageInfo.getPublicResourceKey());
|
||||
|
||||
assertThat(downloadImage("tenant", filename)).containsExactly(PNG_IMAGE);
|
||||
resetTokens();
|
||||
@ -225,22 +225,25 @@ public class ImageControllerTest extends AbstractControllerTest {
|
||||
public void testMakeImagePublic() throws Exception {
|
||||
String filename = "my_public_image.png";
|
||||
TbResourceInfo imageInfo = uploadImage(HttpMethod.POST, "/api/image", filename, "image/png", PNG_IMAGE, false);
|
||||
assertThat(imageInfo.isPublic()).isFalse();
|
||||
String publicKey = imageInfo.getPublicResourceKey();
|
||||
assertThat(publicKey).hasSize(32);
|
||||
|
||||
updateImagePublicStatus(filename, false);
|
||||
doGet("/api/images/public/" + publicKey).andExpect(status().isNotFound());
|
||||
|
||||
imageInfo.setPublic(true);
|
||||
imageInfo = doPut("/api/images/tenant/" + filename + "/public/true", imageInfo, TbResourceInfo.class);
|
||||
updateImagePublicStatus(filename, true);
|
||||
resetTokens();
|
||||
assertThat(downloadPublicImage(publicKey)).containsExactly(PNG_IMAGE);
|
||||
|
||||
loginTenantAdmin();
|
||||
imageInfo.setPublic(false);
|
||||
doPut("/api/images/tenant/" + filename + "/public/false", imageInfo, TbResourceInfo.class);
|
||||
updateImagePublicStatus(filename, false);
|
||||
doGet("/api/images/public/" + publicKey).andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
private TbResourceInfo updateImagePublicStatus(String filename, boolean isPublic) throws Exception {
|
||||
return doPut("/api/images/tenant/" + filename + "/public/" + isPublic, "", TbResourceInfo.class);
|
||||
}
|
||||
|
||||
private void checkPngImageDescriptor(ImageDescriptor imageDescriptor) {
|
||||
assertThat(imageDescriptor.getMediaType()).isEqualTo("image/png");
|
||||
assertThat(imageDescriptor.getWidth()).isEqualTo(200);
|
||||
@ -277,13 +280,6 @@ public class ImageControllerTest extends AbstractControllerTest {
|
||||
assertThat(imageDescriptor.getHeight()).isEqualTo(150);
|
||||
assertThat(imageDescriptor.getSize()).isEqualTo(SVG_IMAGE.length);
|
||||
assertThat(imageDescriptor.getEtag()).isEqualTo(Hashing.sha256().hashBytes(SVG_IMAGE).toString());
|
||||
|
||||
ImageDescriptor previewDescriptor = imageDescriptor.getPreviewDescriptor();
|
||||
assertThat(previewDescriptor.getMediaType()).isEqualTo("image/png");
|
||||
assertThat(previewDescriptor.getWidth()).isEqualTo(250);
|
||||
assertThat(previewDescriptor.getHeight()).isEqualTo(250);
|
||||
assertThat(previewDescriptor.getSize()).isEqualTo(13247);
|
||||
assertThat(previewDescriptor.getEtag()).isEqualTo("f02db84f2c6ed7ea0606ae1145986a16a534cb0fd70436b3b5ca585569d48e46");
|
||||
}
|
||||
|
||||
private List<TbResourceInfo> getImages(String searchText, boolean includeSystemImages, int limit) throws Exception {
|
||||
|
||||
@ -41,14 +41,13 @@ export class ImageService {
|
||||
) {
|
||||
}
|
||||
|
||||
public uploadImage(file: File, title: string, isPublic = true, config?: RequestConfig): Observable<ImageResourceInfo> {
|
||||
public uploadImage(file: File, title: string, config?: RequestConfig): Observable<ImageResourceInfo> {
|
||||
if (!config) {
|
||||
config = {};
|
||||
}
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('title', title);
|
||||
formData.append('isPublic', isPublic ? 'true' : 'false');
|
||||
return this.http.post<ImageResourceInfo>('/api/image', formData,
|
||||
defaultHttpUploadOptions(config.ignoreLoading, config.ignoreErrors, config.resendRequest));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user