Update cache when image info is updated
This commit is contained in:
parent
562838cfdb
commit
8e95b6ef9b
@ -145,10 +145,11 @@ public class ImageController extends BaseController {
|
|||||||
@PathVariable String type,
|
@PathVariable String type,
|
||||||
@ApiParam(value = IMAGE_KEY_PARAM_DESCRIPTION, required = true)
|
@ApiParam(value = IMAGE_KEY_PARAM_DESCRIPTION, required = true)
|
||||||
@PathVariable String key,
|
@PathVariable String key,
|
||||||
@RequestBody TbResourceInfo newImageInfo) throws ThingsboardException {
|
@RequestBody TbResourceInfo request) throws ThingsboardException {
|
||||||
TbResourceInfo imageInfo = checkImageInfo(type, key, Operation.WRITE);
|
TbResourceInfo imageInfo = checkImageInfo(type, key, Operation.WRITE);
|
||||||
imageInfo.setTitle(newImageInfo.getTitle());
|
TbResourceInfo newImageInfo = new TbResourceInfo(imageInfo);
|
||||||
return tbImageService.save(imageInfo, getCurrentUser());
|
newImageInfo.setTitle(request.getTitle());
|
||||||
|
return tbImageService.save(newImageInfo, imageInfo, getCurrentUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
|
||||||
@ -159,8 +160,9 @@ public class ImageController extends BaseController {
|
|||||||
@PathVariable String key,
|
@PathVariable String key,
|
||||||
@PathVariable boolean isPublic) throws ThingsboardException {
|
@PathVariable boolean isPublic) throws ThingsboardException {
|
||||||
TbResourceInfo imageInfo = checkImageInfo(type, key, Operation.WRITE);
|
TbResourceInfo imageInfo = checkImageInfo(type, key, Operation.WRITE);
|
||||||
imageInfo.setPublic(isPublic);
|
TbResourceInfo newImageInfo = new TbResourceInfo(imageInfo);
|
||||||
return tbImageService.save(imageInfo, getCurrentUser());
|
newImageInfo.setPublic(isPublic);
|
||||||
|
return tbImageService.save(newImageInfo, imageInfo, getCurrentUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
@ -310,8 +312,8 @@ public class ImageController extends BaseController {
|
|||||||
.eTag(descriptor.getEtag());
|
.eTag(descriptor.getEtag());
|
||||||
if (!cacheKey.isPublic()) {
|
if (!cacheKey.isPublic()) {
|
||||||
result
|
result
|
||||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + fileName)
|
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + fileName)
|
||||||
.header("x-filename", fileName);
|
.header("x-filename", fileName);
|
||||||
}
|
}
|
||||||
if (systemImagesBrowserTtlInMinutes > 0 && imageInfo.getTenantId().isSysTenantId()) {
|
if (systemImagesBrowserTtlInMinutes > 0 && imageInfo.getTenantId().isSysTenantId()) {
|
||||||
result.cacheControl(CacheControl.maxAge(systemImagesBrowserTtlInMinutes, TimeUnit.MINUTES));
|
result.cacheControl(CacheControl.maxAge(systemImagesBrowserTtlInMinutes, TimeUnit.MINUTES));
|
||||||
|
|||||||
@ -134,12 +134,16 @@ public class DefaultTbImageService extends AbstractTbEntityService implements Tb
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbResourceInfo save(TbResourceInfo imageInfo, User user) {
|
public TbResourceInfo save(TbResourceInfo imageInfo, TbResourceInfo oldImageInfo, User user) {
|
||||||
TenantId tenantId = imageInfo.getTenantId();
|
TenantId tenantId = imageInfo.getTenantId();
|
||||||
TbResourceId imageId = imageInfo.getId();
|
TbResourceId imageId = imageInfo.getId();
|
||||||
try {
|
try {
|
||||||
imageInfo = imageService.saveImageInfo(imageInfo);
|
imageInfo = imageService.saveImageInfo(imageInfo);
|
||||||
notificationEntityService.logEntityAction(tenantId, imageId, imageInfo, ActionType.UPDATED, user);
|
notificationEntityService.logEntityAction(tenantId, imageId, imageInfo, ActionType.UPDATED, user);
|
||||||
|
|
||||||
|
if (imageInfo.isPublic() != oldImageInfo.isPublic()) {
|
||||||
|
evictFromCache(tenantId, List.of(ImageCacheKey.forPublicImage(imageInfo.getPublicResourceKey())));
|
||||||
|
}
|
||||||
return imageInfo;
|
return imageInfo;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
notificationEntityService.logEntityAction(tenantId, imageId, imageInfo, ActionType.UPDATED, user, e);
|
notificationEntityService.logEntityAction(tenantId, imageId, imageInfo, ActionType.UPDATED, user, e);
|
||||||
|
|||||||
@ -25,7 +25,7 @@ public interface TbImageService {
|
|||||||
|
|
||||||
TbResourceInfo save(TbResource image, User user) throws Exception;
|
TbResourceInfo save(TbResource image, User user) throws Exception;
|
||||||
|
|
||||||
TbResourceInfo save(TbResourceInfo imageInfo, User user);
|
TbResourceInfo save(TbResourceInfo imageInfo, TbResourceInfo oldImageInfo, User user);
|
||||||
|
|
||||||
TbImageDeleteResult delete(TbResourceInfo imageInfo, User user, boolean force);
|
TbImageDeleteResult delete(TbResourceInfo imageInfo, User user, boolean force);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user