forked from Qortal/qortal
Added POST /data/file/{hash}/build API, used to join multiple chunks together.
This commit is contained in:
parent
b34066f579
commit
71c247fe56
@ -225,4 +225,59 @@ public class DataResource {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/file/{hash}/build")
|
||||
@Operation(
|
||||
summary = "Join multiple chunks into a single file, using supplied comma separated base58 encoded SHA256 digest strings",
|
||||
requestBody = @RequestBody(
|
||||
required = true,
|
||||
content = @Content(
|
||||
mediaType = MediaType.TEXT_PLAIN,
|
||||
schema = @Schema(
|
||||
type = "string", example = "FZdHKgF5CbN2tKihvop5Ts9vmWmA9ZyyPY6bC1zivjy4,FZdHKgF5CbN2tKihvop5Ts9vmWmA9ZyyPY6bC1zivjy4"
|
||||
)
|
||||
)
|
||||
),
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "true if joined, false if not",
|
||||
content = @Content(
|
||||
mediaType = MediaType.TEXT_PLAIN,
|
||||
schema = @Schema(
|
||||
type = "string"
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
@ApiErrors({ApiError.REPOSITORY_ISSUE, ApiError.INVALID_DATA, ApiError.INVALID_CRITERIA, ApiError.FILE_NOT_FOUND, ApiError.NO_REPLY})
|
||||
public Response joinFiles(String files, @PathParam("combinedHash") String combinedHash) {
|
||||
|
||||
if (combinedHash == null) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_CRITERIA);
|
||||
}
|
||||
|
||||
DataFile dataFile = DataFile.fromBase58Digest(combinedHash);
|
||||
if (dataFile.exists()) {
|
||||
LOGGER.info("We already have the combined file {}, but we'll join the chunks anyway.", combinedHash);
|
||||
}
|
||||
|
||||
String base58DigestList[] = files.split(",");
|
||||
for (String base58Digest : base58DigestList) {
|
||||
if (base58Digest != null) {
|
||||
DataFileChunk chunk = DataFileChunk.fromBase58Digest(base58Digest);
|
||||
dataFile.addChunk(chunk);
|
||||
}
|
||||
}
|
||||
boolean success = dataFile.join();
|
||||
if (success) {
|
||||
if (combinedHash.equals(dataFile.base58Digest())) {
|
||||
LOGGER.info("Valid hash {} after joining {} files", dataFile.base58Digest(), dataFile.chunkCount());
|
||||
return Response.ok("true").build();
|
||||
}
|
||||
}
|
||||
|
||||
return Response.ok("false").build();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user