Browse Source

Endpoint for updating image public status

pull/9846/head
ViacheslavKlimov 3 years ago
parent
commit
9b92a753ac
  1. 21
      application/src/main/java/org/thingsboard/server/controller/ImageController.java
  2. 2
      common/dao-api/src/main/java/org/thingsboard/server/dao/resource/ImageService.java
  3. 4
      dao/src/main/java/org/thingsboard/server/dao/resource/BaseImageService.java

21
application/src/main/java/org/thingsboard/server/controller/ImageController.java

@ -16,8 +16,6 @@
package org.thingsboard.server.controller;
import io.swagger.annotations.ApiParam;
import lombok.Builder;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@ -142,7 +140,16 @@ public class ImageController extends BaseController {
@RequestBody TbResourceInfo newImageInfo) throws ThingsboardException {
TbResourceInfo imageInfo = checkImageInfo(type, key, Operation.WRITE);
imageInfo.setTitle(newImageInfo.getTitle());
imageInfo.setPublic(newImageInfo.isPublic());
return tbImageService.save(imageInfo, getCurrentUser());
}
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@PutMapping(IMAGE_URL + "/public/{isPublic}")
public TbResourceInfo updateImagePublicStatus(@PathVariable String type,
@PathVariable String key,
@PathVariable boolean isPublic) throws ThingsboardException {
TbResourceInfo imageInfo = checkImageInfo(type, key, Operation.WRITE);
imageInfo.setPublic(isPublic);
return tbImageService.save(imageInfo, getCurrentUser());
}
@ -154,11 +161,11 @@ public class ImageController extends BaseController {
return downloadIfChanged(type, key, etag, false);
}
@GetMapping(value = "/api/images/public/{publicKey}", produces = "image/*")
public ResponseEntity<ByteArrayResource> downloadPublicImage(@PathVariable String publicKey,
@GetMapping(value = "/api/images/public/{publicResourceKey}", produces = "image/*")
public ResponseEntity<ByteArrayResource> downloadPublicImage(@PathVariable String publicResourceKey,
@RequestHeader(name = HttpHeaders.IF_NONE_MATCH, required = false) String etag) throws Exception {
ImageCacheKey cacheKey = ImageCacheKey.forPublicImage(publicKey);
return downloadIfChanged(cacheKey, etag, () -> imageService.getPublicImageInfoByPublicKey(publicKey));
ImageCacheKey cacheKey = ImageCacheKey.forPublicImage(publicResourceKey);
return downloadIfChanged(cacheKey, etag, () -> imageService.getPublicImageInfoByKey(publicResourceKey));
}
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")

2
common/dao-api/src/main/java/org/thingsboard/server/dao/resource/ImageService.java

@ -34,7 +34,7 @@ public interface ImageService {
TbResourceInfo getImageInfoByTenantIdAndKey(TenantId tenantId, String key);
TbResourceInfo getPublicImageInfoByPublicKey(String publicKey);
TbResourceInfo getPublicImageInfoByKey(String publicResourceKey);
PageData<TbResourceInfo> getImagesByTenantId(TenantId tenantId, PageLink pageLink);

4
dao/src/main/java/org/thingsboard/server/dao/resource/BaseImageService.java

@ -221,8 +221,8 @@ public class BaseImageService extends BaseResourceService implements ImageServic
}
@Override
public TbResourceInfo getPublicImageInfoByPublicKey(String publicKey) {
return resourceInfoDao.findPublicResourceByKey(ResourceType.IMAGE, publicKey);
public TbResourceInfo getPublicImageInfoByKey(String publicResourceKey) {
return resourceInfoDao.findPublicResourceByKey(ResourceType.IMAGE, publicResourceKey);
}
@Override

Loading…
Cancel
Save