|
|
|
@ -517,17 +517,37 @@ public class BaseImageService extends BaseResourceService implements ImageServic |
|
|
|
public void inlineImages(Dashboard dashboard) { |
|
|
|
log.trace("Executing inlineImage [{}] [Dashboard] [{}]", dashboard.getTenantId(), dashboard.getId()); |
|
|
|
inlineImage(dashboard); |
|
|
|
inlineIntoJson(dashboard.getTenantId(), dashboard.getConfiguration()); |
|
|
|
inlineIntoJson(dashboard.getTenantId(), dashboard.getConfiguration(), true); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void inlineImages(WidgetTypeDetails widgetTypeDetails) { |
|
|
|
log.trace("Executing inlineImage [{}] [WidgetTypeDetails] [{}]", widgetTypeDetails.getTenantId(), widgetTypeDetails.getId()); |
|
|
|
inlineImage(widgetTypeDetails); |
|
|
|
inlineIntoJson(widgetTypeDetails.getTenantId(), widgetTypeDetails.getDescriptor()); |
|
|
|
inlineIntoJson(widgetTypeDetails.getTenantId(), widgetTypeDetails.getDescriptor(), true); |
|
|
|
} |
|
|
|
|
|
|
|
private void inlineIntoJson(TenantId tenantId, JsonNode root) { |
|
|
|
@Override |
|
|
|
public void inlineImageForEdge(HasImage entity) { |
|
|
|
log.trace("Executing inlineImageForEdge [{}] [{}] [{}]", entity.getTenantId(), entity.getClass().getSimpleName(), entity.getName()); |
|
|
|
entity.setImage(inlineImage(entity.getTenantId(), "image", entity.getImage(), false)); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void inlineImagesForEdge(Dashboard dashboard) { |
|
|
|
log.trace("Executing inlineImagesForEdge [{}] [Dashboard] [{}]", dashboard.getTenantId(), dashboard.getId()); |
|
|
|
inlineImageForEdge(dashboard); |
|
|
|
inlineIntoJson(dashboard.getTenantId(), dashboard.getConfiguration(), false); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void inlineImagesForEdge(WidgetTypeDetails widgetTypeDetails) { |
|
|
|
log.trace("Executing inlineImage [{}] [WidgetTypeDetails] [{}]", widgetTypeDetails.getTenantId(), widgetTypeDetails.getId()); |
|
|
|
inlineImageForEdge(widgetTypeDetails); |
|
|
|
inlineIntoJson(widgetTypeDetails.getTenantId(), widgetTypeDetails.getDescriptor(), false); |
|
|
|
} |
|
|
|
|
|
|
|
private void inlineIntoJson(TenantId tenantId, JsonNode root, boolean addTbImagePrefix) { |
|
|
|
Queue<JsonNodeProcessingTask> tasks = new LinkedList<>(); |
|
|
|
tasks.add(new JsonNodeProcessingTask("", root)); |
|
|
|
while (!tasks.isEmpty()) { |
|
|
|
@ -543,7 +563,7 @@ public class BaseImageService extends BaseResourceService implements ImageServic |
|
|
|
String childName = it.next(); |
|
|
|
JsonNode childValue = on.get(childName); |
|
|
|
if (childValue.isTextual()) { |
|
|
|
on.put(childName, inlineImage(tenantId, currentPath + childName, childValue.asText())); |
|
|
|
on.put(childName, inlineImage(tenantId, currentPath + childName, childValue.asText(), addTbImagePrefix)); |
|
|
|
} else if (childValue.isObject() || childValue.isArray()) { |
|
|
|
tasks.add(new JsonNodeProcessingTask(currentPath + childName, childValue)); |
|
|
|
} |
|
|
|
@ -555,7 +575,7 @@ public class BaseImageService extends BaseResourceService implements ImageServic |
|
|
|
if (element.isObject()) { |
|
|
|
tasks.add(new JsonNodeProcessingTask(currentPath + "." + i, element)); |
|
|
|
} else if (element.isTextual()) { |
|
|
|
childArray.set(i, inlineImage(tenantId, currentPath + "." + i, element.asText())); |
|
|
|
childArray.set(i, inlineImage(tenantId, currentPath + "." + i, element.asText(), addTbImagePrefix)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -563,6 +583,10 @@ public class BaseImageService extends BaseResourceService implements ImageServic |
|
|
|
} |
|
|
|
|
|
|
|
private String inlineImage(TenantId tenantId, String path, String url) { |
|
|
|
return inlineImage(tenantId, path, url, true); |
|
|
|
} |
|
|
|
|
|
|
|
private String inlineImage(TenantId tenantId, String path, String url, boolean addTbImagePrefix) { |
|
|
|
try { |
|
|
|
ImageCacheKey key = getKeyFromUrl(tenantId, url); |
|
|
|
if (key != null) { |
|
|
|
@ -570,8 +594,11 @@ public class BaseImageService extends BaseResourceService implements ImageServic |
|
|
|
if (imageInfo != null) { |
|
|
|
byte[] data = key.isPreview() ? getImagePreview(tenantId, imageInfo.getId()) : getImageData(tenantId, imageInfo.getId()); |
|
|
|
ImageDescriptor descriptor = getImageDescriptor(imageInfo, key.isPreview()); |
|
|
|
String tbImagePrefix = "tb-image:" + Base64Utils.encodeToString(imageInfo.getResourceKey().getBytes(StandardCharsets.UTF_8)) + ":" |
|
|
|
+ Base64Utils.encodeToString(imageInfo.getName().getBytes(StandardCharsets.UTF_8)) + ";"; |
|
|
|
String tbImagePrefix = ""; |
|
|
|
if (addTbImagePrefix) { |
|
|
|
tbImagePrefix = "tb-image:" + Base64Utils.encodeToString(imageInfo.getResourceKey().getBytes(StandardCharsets.UTF_8)) + ":" |
|
|
|
+ Base64Utils.encodeToString(imageInfo.getName().getBytes(StandardCharsets.UTF_8)) + ";"; |
|
|
|
} |
|
|
|
return tbImagePrefix + "data:" + descriptor.getMediaType() + ";base64," + Base64Utils.encodeToString(data); |
|
|
|
} |
|
|
|
} |
|
|
|
|