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')")
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
|
||||||
@PostMapping("/api/image")
|
@PostMapping("/api/image")
|
||||||
public TbResourceInfo uploadImage(@RequestPart MultipartFile file,
|
public TbResourceInfo uploadImage(@RequestPart MultipartFile file,
|
||||||
@RequestPart(required = false) String title,
|
@RequestPart(required = false) String title) throws Exception {
|
||||||
@RequestPart(required = false) Boolean isPublic) throws Exception {
|
|
||||||
SecurityUser user = getCurrentUser();
|
SecurityUser user = getCurrentUser();
|
||||||
TbResource image = new TbResource();
|
TbResource image = new TbResource();
|
||||||
image.setTenantId(user.getTenantId());
|
image.setTenantId(user.getTenantId());
|
||||||
@ -110,12 +109,12 @@ public class ImageController extends BaseController {
|
|||||||
} else {
|
} else {
|
||||||
image.setTitle(file.getOriginalFilename());
|
image.setTitle(file.getOriginalFilename());
|
||||||
}
|
}
|
||||||
image.setPublic(isPublic != null ? isPublic : true);
|
|
||||||
image.setResourceType(ResourceType.IMAGE);
|
image.setResourceType(ResourceType.IMAGE);
|
||||||
ImageDescriptor descriptor = new ImageDescriptor();
|
ImageDescriptor descriptor = new ImageDescriptor();
|
||||||
descriptor.setMediaType(file.getContentType());
|
descriptor.setMediaType(file.getContentType());
|
||||||
image.setDescriptorValue(descriptor);
|
image.setDescriptorValue(descriptor);
|
||||||
image.setData(file.getBytes());
|
image.setData(file.getBytes());
|
||||||
|
image.setPublic(true);
|
||||||
return tbImageService.save(image, user);
|
return tbImageService.save(image, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -214,7 +214,7 @@ public class ImageControllerTest extends AbstractControllerTest {
|
|||||||
|
|
||||||
assertThat(imageInfo.isPublic()).isTrue();
|
assertThat(imageInfo.isPublic()).isTrue();
|
||||||
assertThat(imageInfo.getPublicResourceKey()).hasSize(32);
|
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);
|
assertThat(downloadImage("tenant", filename)).containsExactly(PNG_IMAGE);
|
||||||
resetTokens();
|
resetTokens();
|
||||||
@ -225,22 +225,25 @@ public class ImageControllerTest extends AbstractControllerTest {
|
|||||||
public void testMakeImagePublic() throws Exception {
|
public void testMakeImagePublic() throws Exception {
|
||||||
String filename = "my_public_image.png";
|
String filename = "my_public_image.png";
|
||||||
TbResourceInfo imageInfo = uploadImage(HttpMethod.POST, "/api/image", filename, "image/png", PNG_IMAGE, false);
|
TbResourceInfo imageInfo = uploadImage(HttpMethod.POST, "/api/image", filename, "image/png", PNG_IMAGE, false);
|
||||||
assertThat(imageInfo.isPublic()).isFalse();
|
|
||||||
String publicKey = imageInfo.getPublicResourceKey();
|
String publicKey = imageInfo.getPublicResourceKey();
|
||||||
assertThat(publicKey).hasSize(32);
|
assertThat(publicKey).hasSize(32);
|
||||||
|
|
||||||
|
updateImagePublicStatus(filename, false);
|
||||||
doGet("/api/images/public/" + publicKey).andExpect(status().isNotFound());
|
doGet("/api/images/public/" + publicKey).andExpect(status().isNotFound());
|
||||||
|
|
||||||
imageInfo.setPublic(true);
|
updateImagePublicStatus(filename, true);
|
||||||
imageInfo = doPut("/api/images/tenant/" + filename + "/public/true", imageInfo, TbResourceInfo.class);
|
|
||||||
resetTokens();
|
resetTokens();
|
||||||
assertThat(downloadPublicImage(publicKey)).containsExactly(PNG_IMAGE);
|
assertThat(downloadPublicImage(publicKey)).containsExactly(PNG_IMAGE);
|
||||||
|
|
||||||
loginTenantAdmin();
|
loginTenantAdmin();
|
||||||
imageInfo.setPublic(false);
|
updateImagePublicStatus(filename, false);
|
||||||
doPut("/api/images/tenant/" + filename + "/public/false", imageInfo, TbResourceInfo.class);
|
|
||||||
doGet("/api/images/public/" + publicKey).andExpect(status().isNotFound());
|
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) {
|
private void checkPngImageDescriptor(ImageDescriptor imageDescriptor) {
|
||||||
assertThat(imageDescriptor.getMediaType()).isEqualTo("image/png");
|
assertThat(imageDescriptor.getMediaType()).isEqualTo("image/png");
|
||||||
assertThat(imageDescriptor.getWidth()).isEqualTo(200);
|
assertThat(imageDescriptor.getWidth()).isEqualTo(200);
|
||||||
@ -277,13 +280,6 @@ public class ImageControllerTest extends AbstractControllerTest {
|
|||||||
assertThat(imageDescriptor.getHeight()).isEqualTo(150);
|
assertThat(imageDescriptor.getHeight()).isEqualTo(150);
|
||||||
assertThat(imageDescriptor.getSize()).isEqualTo(SVG_IMAGE.length);
|
assertThat(imageDescriptor.getSize()).isEqualTo(SVG_IMAGE.length);
|
||||||
assertThat(imageDescriptor.getEtag()).isEqualTo(Hashing.sha256().hashBytes(SVG_IMAGE).toString());
|
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 {
|
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) {
|
if (!config) {
|
||||||
config = {};
|
config = {};
|
||||||
}
|
}
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', file);
|
formData.append('file', file);
|
||||||
formData.append('title', title);
|
formData.append('title', title);
|
||||||
formData.append('isPublic', isPublic ? 'true' : 'false');
|
|
||||||
return this.http.post<ImageResourceInfo>('/api/image', formData,
|
return this.http.post<ImageResourceInfo>('/api/image', formData,
|
||||||
defaultHttpUploadOptions(config.ignoreLoading, config.ignoreErrors, config.resendRequest));
|
defaultHttpUploadOptions(config.ignoreLoading, config.ignoreErrors, config.resendRequest));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user