forked from Qortal/qortal
Return file lists via /arbitrary/metadata/* endpoints, but exclude it from /arbitrary/resources/* endpoints.
This commit is contained in:
parent
328ba48224
commit
1d568fa462
@ -719,7 +719,7 @@ public class ArbitraryResource {
|
||||
try {
|
||||
ArbitraryDataTransactionMetadata transactionMetadata = ArbitraryMetadataManager.getInstance().fetchMetadata(resource, false);
|
||||
if (transactionMetadata != null) {
|
||||
ArbitraryResourceMetadata resourceMetadata = ArbitraryResourceMetadata.fromTransactionMetadata(transactionMetadata);
|
||||
ArbitraryResourceMetadata resourceMetadata = ArbitraryResourceMetadata.fromTransactionMetadata(transactionMetadata, true);
|
||||
if (resourceMetadata != null) {
|
||||
return resourceMetadata;
|
||||
}
|
||||
@ -1288,7 +1288,7 @@ public class ArbitraryResource {
|
||||
ArbitraryDataResource resource = new ArbitraryDataResource(resourceInfo.name, ResourceIdType.NAME,
|
||||
resourceInfo.service, resourceInfo.identifier);
|
||||
ArbitraryDataTransactionMetadata transactionMetadata = resource.getLatestTransactionMetadata();
|
||||
ArbitraryResourceMetadata resourceMetadata = ArbitraryResourceMetadata.fromTransactionMetadata(transactionMetadata);
|
||||
ArbitraryResourceMetadata resourceMetadata = ArbitraryResourceMetadata.fromTransactionMetadata(transactionMetadata, false);
|
||||
if (resourceMetadata != null) {
|
||||
resourceInfo.metadata = resourceMetadata;
|
||||
}
|
||||
|
@ -15,22 +15,24 @@ public class ArbitraryResourceMetadata {
|
||||
private List<String> tags;
|
||||
private Category category;
|
||||
private String categoryName;
|
||||
private List<String> files;
|
||||
|
||||
public ArbitraryResourceMetadata() {
|
||||
}
|
||||
|
||||
public ArbitraryResourceMetadata(String title, String description, List<String> tags, Category category) {
|
||||
public ArbitraryResourceMetadata(String title, String description, List<String> tags, Category category, List<String> files) {
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.tags = tags;
|
||||
this.category = category;
|
||||
this.files = files;
|
||||
|
||||
if (category != null) {
|
||||
this.categoryName = category.getName();
|
||||
}
|
||||
}
|
||||
|
||||
public static ArbitraryResourceMetadata fromTransactionMetadata(ArbitraryDataTransactionMetadata transactionMetadata) {
|
||||
public static ArbitraryResourceMetadata fromTransactionMetadata(ArbitraryDataTransactionMetadata transactionMetadata, boolean includeFileList) {
|
||||
if (transactionMetadata == null) {
|
||||
return null;
|
||||
}
|
||||
@ -39,10 +41,20 @@ public class ArbitraryResourceMetadata {
|
||||
List<String> tags = transactionMetadata.getTags();
|
||||
Category category = transactionMetadata.getCategory();
|
||||
|
||||
if (title == null && description == null && tags == null && category == null) {
|
||||
// We don't always want to include the file list as it can be too verbose
|
||||
List<String> files = null;
|
||||
if (includeFileList) {
|
||||
files = transactionMetadata.getFiles();
|
||||
}
|
||||
|
||||
if (title == null && description == null && tags == null && category == null && files == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ArbitraryResourceMetadata(title, description, tags, category);
|
||||
return new ArbitraryResourceMetadata(title, description, tags, category, files);
|
||||
}
|
||||
|
||||
public List<String> getFiles() {
|
||||
return this.files;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import org.qortal.arbitrary.exception.MissingDataException;
|
||||
import org.qortal.arbitrary.misc.Category;
|
||||
import org.qortal.arbitrary.misc.Service;
|
||||
import org.qortal.controller.arbitrary.ArbitraryDataManager;
|
||||
import org.qortal.data.arbitrary.ArbitraryResourceMetadata;
|
||||
import org.qortal.data.transaction.ArbitraryTransactionData;
|
||||
import org.qortal.data.transaction.RegisterNameTransactionData;
|
||||
import org.qortal.repository.DataException;
|
||||
@ -311,6 +312,15 @@ public class ArbitraryTransactionMetadataTests extends Common {
|
||||
// Check the file list metadata is correct
|
||||
assertEquals(1, arbitraryDataFile.getMetadata().getFiles().size());
|
||||
assertTrue(arbitraryDataFile.getMetadata().getFiles().contains("file.txt"));
|
||||
|
||||
// Ensure the file list can be read back out again, when specified to be included
|
||||
ArbitraryResourceMetadata resourceMetadata = ArbitraryResourceMetadata.fromTransactionMetadata(arbitraryDataFile.getMetadata(), true);
|
||||
assertTrue(resourceMetadata.getFiles().contains("file.txt"));
|
||||
|
||||
// Ensure it's not returned when specified to be excluded
|
||||
// The entire object will be null because there is no metadata
|
||||
ArbitraryResourceMetadata resourceMetadataSimple = ArbitraryResourceMetadata.fromTransactionMetadata(arbitraryDataFile.getMetadata(), false);
|
||||
assertNull(resourceMetadataSimple);
|
||||
}
|
||||
}
|
||||
|
||||
@ -348,6 +358,17 @@ public class ArbitraryTransactionMetadataTests extends Common {
|
||||
assertTrue(arbitraryDataFile.getMetadata().getFiles().contains("file.txt"));
|
||||
assertTrue(arbitraryDataFile.getMetadata().getFiles().contains("image1.jpg"));
|
||||
assertTrue(arbitraryDataFile.getMetadata().getFiles().contains("subdirectory/config.json"));
|
||||
|
||||
// Ensure the file list can be read back out again, when specified to be included
|
||||
ArbitraryResourceMetadata resourceMetadata = ArbitraryResourceMetadata.fromTransactionMetadata(arbitraryDataFile.getMetadata(), true);
|
||||
assertTrue(resourceMetadata.getFiles().contains("file.txt"));
|
||||
assertTrue(resourceMetadata.getFiles().contains("image1.jpg"));
|
||||
assertTrue(resourceMetadata.getFiles().contains("subdirectory/config.json"));
|
||||
|
||||
// Ensure it's not returned when specified to be excluded
|
||||
// The entire object will be null because there is no metadata
|
||||
ArbitraryResourceMetadata resourceMetadataSimple = ArbitraryResourceMetadata.fromTransactionMetadata(arbitraryDataFile.getMetadata(), false);
|
||||
assertNull(resourceMetadataSimple);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user