xuang7 commented on code in PR #4117:
URL: https://github.com/apache/texera/pull/4117#discussion_r2666486985
##########
file-service/src/main/scala/org/apache/texera/service/resource/DatasetResource.scala:
##########
@@ -1742,4 +1747,106 @@ class DatasetResource {
Response.ok(Map("message" -> "Multipart upload aborted
successfully")).build()
}
}
+
+ /**
+ * Updates the cover image for a dataset.
+ *
+ * @param did Dataset ID
+ * @param request Cover image request containing the relative file path
+ * @param sessionUser Authenticated user session
+ * @return Response with updated cover image path
+ *
+ * Expected coverImage format: "version/folder/image.jpg" (relative to
dataset root)
+ */
+ @POST
+ @RolesAllowed(Array("REGULAR", "ADMIN"))
+ @Path("/{did}/update/cover")
+ @Consumes(Array(MediaType.APPLICATION_JSON))
+ def updateDatasetCoverImage(
+ @PathParam("did") did: Integer,
+ request: CoverImageRequest,
+ @Auth sessionUser: SessionUser
+ ): Response = {
+ withTransaction(context) { ctx =>
+ val uid = sessionUser.getUid
+ val dataset = getDatasetByID(ctx, did)
+ if (!userHasWriteAccess(ctx, did, uid)) {
+ throw new ForbiddenException(ERR_USER_HAS_NO_ACCESS_TO_DATASET_MESSAGE)
+ }
+
+ if (request == null || request.coverImage == null ||
request.coverImage.trim.isEmpty) {
+ throw new BadRequestException("Cover image path is required")
+ }
+
+ val normalized = Paths.get(request.coverImage).normalize().toString
+ if (normalized.startsWith("..") || normalized.startsWith("/")) {
+ throw new BadRequestException("Invalid file path")
+ }
+
+ if (!ALLOWED_IMAGE_EXTENSIONS.exists(ext =>
normalized.toLowerCase.endsWith(ext))) {
+ throw new BadRequestException("Invalid file type")
+ }
+
+ val owner = getOwner(ctx, did)
+ val document = DocumentFactory
+ .openReadonlyDocument(
+
FileResolver.resolve(s"${owner.getEmail}/${dataset.getName}/$normalized")
+ )
+ .asInstanceOf[OnDataset]
+
+ val file = LakeFSStorageClient.getFileFromRepo(
+ document.getRepositoryName(),
+ document.getVersionHash(),
+ document.getFileRelativePath()
+ )
+
+ if (file.length() > COVER_IMAGE_SIZE_LIMIT_BYTES) {
+ throw new BadRequestException(
+ s"Cover image must be less than ${COVER_IMAGE_SIZE_LIMIT_BYTES /
(1024 * 1024)} MB"
+ )
+ }
+
+ dataset.setCoverImage(normalized)
+ new DatasetDao(ctx.configuration()).update(dataset)
+ Response.ok(Map("coverImage" -> normalized)).build()
+ }
+ }
+
+ /**
+ * Get the cover image for a public dataset.
+ * Returns a 307 redirect to the presigned S3 URL.
+ *
+ * @param did Dataset ID
+ * @return 307 Temporary Redirect to cover image
+ */
+ @GET
+ @Path("/{did}/cover")
+ def getDatasetCover(@PathParam("did") did: Integer): Response = {
+ withTransaction(context) { ctx =>
+ val dataset = getDatasetByID(ctx, did)
+
+ if (!dataset.getIsPublic) {
Review Comment:
Fixed. Updated the authorization to: public accessible; private requires
login + READ.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]