mirror of
https://github.com/Qortal/qortal.git
synced 2025-07-27 12:11:23 +00:00
Added initial (unfinished) category list, as well as the GET /arbitrary/categories API, and converted the category field from a string to an enum
This commit is contained in:
@@ -33,10 +33,12 @@ import org.qortal.api.resource.TransactionsResource.ConfirmationStatus;
|
||||
import org.qortal.arbitrary.*;
|
||||
import org.qortal.arbitrary.ArbitraryDataFile.ResourceIdType;
|
||||
import org.qortal.arbitrary.exception.MissingDataException;
|
||||
import org.qortal.arbitrary.misc.Category;
|
||||
import org.qortal.arbitrary.misc.Service;
|
||||
import org.qortal.controller.Controller;
|
||||
import org.qortal.controller.arbitrary.ArbitraryDataStorageManager;
|
||||
import org.qortal.data.account.AccountData;
|
||||
import org.qortal.data.arbitrary.ArbitraryCategoryInfo;
|
||||
import org.qortal.data.arbitrary.ArbitraryResourceInfo;
|
||||
import org.qortal.data.arbitrary.ArbitraryResourceNameInfo;
|
||||
import org.qortal.data.arbitrary.ArbitraryResourceStatus;
|
||||
@@ -388,6 +390,28 @@ public class ArbitraryResource {
|
||||
return Settings.getInstance().isRelayModeEnabled();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/categories")
|
||||
@Operation(
|
||||
summary = "List arbitrary transaction categories",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ArbitraryCategoryInfo.class))
|
||||
)
|
||||
}
|
||||
)
|
||||
@ApiErrors({ApiError.REPOSITORY_ISSUE})
|
||||
public List<ArbitraryCategoryInfo> getCategories() {
|
||||
List<ArbitraryCategoryInfo> categories = new ArrayList<>();
|
||||
for (Category category : Category.values()) {
|
||||
ArbitraryCategoryInfo arbitraryCategory = new ArbitraryCategoryInfo();
|
||||
arbitraryCategory.id = category.toString();
|
||||
arbitraryCategory.name = category.getName();
|
||||
categories.add(arbitraryCategory);
|
||||
}
|
||||
return categories;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/hosted/transactions")
|
||||
@Operation(
|
||||
@@ -645,7 +669,7 @@ public class ArbitraryResource {
|
||||
@QueryParam("title") String title,
|
||||
@QueryParam("description") String description,
|
||||
@QueryParam("tags") String tags,
|
||||
@QueryParam("category") String category,
|
||||
@QueryParam("category") Category category,
|
||||
String path) {
|
||||
Security.checkApiCallAllowed(request);
|
||||
|
||||
@@ -690,7 +714,7 @@ public class ArbitraryResource {
|
||||
@QueryParam("title") String title,
|
||||
@QueryParam("description") String description,
|
||||
@QueryParam("tags") String tags,
|
||||
@QueryParam("category") String category,
|
||||
@QueryParam("category") Category category,
|
||||
String path) {
|
||||
Security.checkApiCallAllowed(request);
|
||||
|
||||
@@ -736,7 +760,7 @@ public class ArbitraryResource {
|
||||
@QueryParam("title") String title,
|
||||
@QueryParam("description") String description,
|
||||
@QueryParam("tags") String tags,
|
||||
@QueryParam("category") String category,
|
||||
@QueryParam("category") Category category,
|
||||
String base64) {
|
||||
Security.checkApiCallAllowed(request);
|
||||
|
||||
@@ -779,7 +803,7 @@ public class ArbitraryResource {
|
||||
@QueryParam("title") String title,
|
||||
@QueryParam("description") String description,
|
||||
@QueryParam("tags") String tags,
|
||||
@QueryParam("category") String category,
|
||||
@QueryParam("category") Category category,
|
||||
String base64) {
|
||||
Security.checkApiCallAllowed(request);
|
||||
|
||||
@@ -824,7 +848,7 @@ public class ArbitraryResource {
|
||||
@QueryParam("title") String title,
|
||||
@QueryParam("description") String description,
|
||||
@QueryParam("tags") String tags,
|
||||
@QueryParam("category") String category,
|
||||
@QueryParam("category") Category category,
|
||||
String base64Zip) {
|
||||
Security.checkApiCallAllowed(request);
|
||||
|
||||
@@ -867,7 +891,7 @@ public class ArbitraryResource {
|
||||
@QueryParam("title") String title,
|
||||
@QueryParam("description") String description,
|
||||
@QueryParam("tags") String tags,
|
||||
@QueryParam("category") String category,
|
||||
@QueryParam("category") Category category,
|
||||
String base64Zip) {
|
||||
Security.checkApiCallAllowed(request);
|
||||
|
||||
@@ -915,7 +939,7 @@ public class ArbitraryResource {
|
||||
@QueryParam("title") String title,
|
||||
@QueryParam("description") String description,
|
||||
@QueryParam("tags") String tags,
|
||||
@QueryParam("category") String category,
|
||||
@QueryParam("category") Category category,
|
||||
String string) {
|
||||
Security.checkApiCallAllowed(request);
|
||||
|
||||
@@ -960,7 +984,7 @@ public class ArbitraryResource {
|
||||
@QueryParam("title") String title,
|
||||
@QueryParam("description") String description,
|
||||
@QueryParam("tags") String tags,
|
||||
@QueryParam("category") String category,
|
||||
@QueryParam("category") Category category,
|
||||
String string) {
|
||||
Security.checkApiCallAllowed(request);
|
||||
|
||||
@@ -977,7 +1001,7 @@ public class ArbitraryResource {
|
||||
|
||||
private String upload(Service service, String name, String identifier,
|
||||
String path, String string, String base64, boolean zipped,
|
||||
String title, String description, String tags, String category) {
|
||||
String title, String description, String tags, Category category) {
|
||||
// Fetch public key from registered name
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
NameData nameData = repository.getNameRepository().fromName(name);
|
||||
|
@@ -6,6 +6,7 @@ import org.qortal.arbitrary.exception.MissingDataException;
|
||||
import org.qortal.arbitrary.ArbitraryDataFile.ResourceIdType;
|
||||
import org.qortal.arbitrary.ArbitraryDataDiff.*;
|
||||
import org.qortal.arbitrary.metadata.ArbitraryDataMetadataPatch;
|
||||
import org.qortal.arbitrary.misc.Category;
|
||||
import org.qortal.arbitrary.misc.Service;
|
||||
import org.qortal.block.BlockChain;
|
||||
import org.qortal.crypto.Crypto;
|
||||
@@ -55,7 +56,7 @@ public class ArbitraryDataTransactionBuilder {
|
||||
private final String title;
|
||||
private final String description;
|
||||
private final String tags;
|
||||
private final String category;
|
||||
private final Category category;
|
||||
|
||||
private int chunkSize = ArbitraryDataFile.CHUNK_SIZE;
|
||||
|
||||
@@ -64,7 +65,7 @@ public class ArbitraryDataTransactionBuilder {
|
||||
|
||||
public ArbitraryDataTransactionBuilder(Repository repository, String publicKey58, Path path, String name,
|
||||
Method method, Service service, String identifier,
|
||||
String title, String description, String tags, String category) {
|
||||
String title, String description, String tags, Category category) {
|
||||
this.repository = repository;
|
||||
this.publicKey58 = publicKey58;
|
||||
this.path = path;
|
||||
|
@@ -5,6 +5,7 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.qortal.arbitrary.exception.MissingDataException;
|
||||
import org.qortal.arbitrary.metadata.ArbitraryDataTransactionMetadata;
|
||||
import org.qortal.arbitrary.misc.Category;
|
||||
import org.qortal.arbitrary.misc.Service;
|
||||
import org.qortal.crypto.Crypto;
|
||||
import org.qortal.data.transaction.ArbitraryTransactionData.*;
|
||||
@@ -45,12 +46,11 @@ public class ArbitraryDataWriter {
|
||||
private final String title;
|
||||
private final String description;
|
||||
private final String tags;
|
||||
private final String category;
|
||||
private final Category category;
|
||||
|
||||
private static int MAX_TITLE_LENGTH = 80;
|
||||
private static int MAX_DESCRIPTION_LENGTH = 500;
|
||||
private static int MAX_TAGS_LENGTH = 80;
|
||||
private static int MAX_CATEGORY_LENGTH = 40;
|
||||
|
||||
private int chunkSize = ArbitraryDataFile.CHUNK_SIZE;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class ArbitraryDataWriter {
|
||||
private Path encryptedPath;
|
||||
|
||||
public ArbitraryDataWriter(Path filePath, String name, Service service, String identifier, Method method, Compression compression,
|
||||
String title, String description, String tags, String category) {
|
||||
String title, String description, String tags, Category category) {
|
||||
this.filePath = filePath;
|
||||
this.name = name;
|
||||
this.service = service;
|
||||
@@ -77,10 +77,10 @@ public class ArbitraryDataWriter {
|
||||
this.identifier = identifier;
|
||||
|
||||
// Metadata (optional)
|
||||
this.title = title.substring(0, MAX_TITLE_LENGTH);;
|
||||
this.description = description.substring(0, MAX_DESCRIPTION_LENGTH);
|
||||
this.tags = tags.substring(0, MAX_TAGS_LENGTH);
|
||||
this.category = category.substring(0, MAX_CATEGORY_LENGTH);
|
||||
this.title = title != null ? title.substring(0, Math.min(title.length(), MAX_TITLE_LENGTH)) : null;
|
||||
this.description = description != null ? description.substring(0, Math.min(description.length(), MAX_DESCRIPTION_LENGTH)) : null;
|
||||
this.tags = tags != null ? tags.substring(0, Math.min(tags.length(), MAX_TAGS_LENGTH)) : null;
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public void save() throws IOException, DataException, InterruptedException, MissingDataException {
|
||||
|
@@ -2,6 +2,7 @@ package org.qortal.arbitrary.metadata;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.qortal.arbitrary.misc.Category;
|
||||
import org.qortal.repository.DataException;
|
||||
import org.qortal.utils.Base58;
|
||||
|
||||
@@ -16,7 +17,7 @@ public class ArbitraryDataTransactionMetadata extends ArbitraryDataMetadata {
|
||||
private String title;
|
||||
private String description;
|
||||
private String tags;
|
||||
private String category;
|
||||
private Category category;
|
||||
|
||||
public ArbitraryDataTransactionMetadata(Path filePath) {
|
||||
super(filePath);
|
||||
@@ -41,7 +42,7 @@ public class ArbitraryDataTransactionMetadata extends ArbitraryDataMetadata {
|
||||
this.tags = metadata.getString("tags");
|
||||
}
|
||||
if (metadata.has("category")) {
|
||||
this.category = metadata.getString("category");
|
||||
this.category = Category.valueOf(metadata.getString("category"));
|
||||
}
|
||||
|
||||
List<byte[]> chunksList = new ArrayList<>();
|
||||
@@ -72,8 +73,8 @@ public class ArbitraryDataTransactionMetadata extends ArbitraryDataMetadata {
|
||||
if (this.tags != null && !this.tags.isEmpty()) {
|
||||
outer.put("tags", this.tags);
|
||||
}
|
||||
if (this.category != null && !this.category.isEmpty()) {
|
||||
outer.put("category", this.category);
|
||||
if (this.category != null) {
|
||||
outer.put("category", this.category.toString());
|
||||
}
|
||||
|
||||
JSONArray chunks = new JSONArray();
|
||||
@@ -121,11 +122,11 @@ public class ArbitraryDataTransactionMetadata extends ArbitraryDataMetadata {
|
||||
return this.tags;
|
||||
}
|
||||
|
||||
public void setCategory(String category) {
|
||||
public void setCategory(Category category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
public Category getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
|
||||
|
62
src/main/java/org/qortal/arbitrary/misc/Category.java
Normal file
62
src/main/java/org/qortal/arbitrary/misc/Category.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package org.qortal.arbitrary.misc;
|
||||
|
||||
public enum Category {
|
||||
ART_AND_DESIGN("Art and Design"),
|
||||
AUTOMOTIVE("Automotive"),
|
||||
BEAUTY("Beauty"),
|
||||
BOOKS("Books and Reference"),
|
||||
BUSINESS("Business"),
|
||||
COMMUNICATIONS("Communications"),
|
||||
CRYPTOCURRENCY("Cryptocurrency and Blockchain"),
|
||||
DATING("Dating"),
|
||||
ENTERTAINMENT("Entertainment"),
|
||||
EVENTS("Events"),
|
||||
FASHION("Fashion"),
|
||||
FINANCE("Finance"),
|
||||
FOOD("Food and Drink"),
|
||||
GAMING("Gaming"),
|
||||
GEOGRAPHY("Geography"),
|
||||
HEALTH("Health"),
|
||||
HISTORY("History"),
|
||||
HOME("Home"),
|
||||
KNOWLEDGE("Knowledge Share"),
|
||||
LANGUAGE("Language"),
|
||||
LIFESTYLE("Lifestyle"),
|
||||
MANUFACTURING("Manufacturing"),
|
||||
MAPS("Maps and Navigation"),
|
||||
MEDICAL("Medical"),
|
||||
MUSIC("Music"),
|
||||
NEWS("News"),
|
||||
OTHER("Other"),
|
||||
PERSONALIZATION("Personalization"),
|
||||
PETS("Pets"),
|
||||
PHILOSOPHY("Philosophy"),
|
||||
PHOTOGRAPHY("Photography"),
|
||||
POLITICS("Politics"),
|
||||
PRODUCTIVITY("Productivity"),
|
||||
PSYCHOLOGY("Psychology"),
|
||||
QORTAL("Qortal"),
|
||||
RELIGION("Religion"),
|
||||
SCIENCE("Science"),
|
||||
SERVICES("Services"),
|
||||
SHOPPING("Shopping"),
|
||||
SOCIAL("Social"),
|
||||
SOFTWARE("Software"),
|
||||
SPORTS("Sports"),
|
||||
TECHNOLOGY("Technology"),
|
||||
TOOLS("Tools"),
|
||||
TRAVEL("Travel"),
|
||||
VIDEO("Video"),
|
||||
WEATHER("Weather");
|
||||
|
||||
private final String name;
|
||||
|
||||
Category(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
package org.qortal.data.arbitrary;
|
||||
|
||||
public class ArbitraryCategoryInfo {
|
||||
|
||||
public String id;
|
||||
public String name;
|
||||
|
||||
public ArbitraryCategoryInfo() {
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user