Skip to content

Commit

Permalink
ProviderClient: request(MediaType.TEXT_PLAIN) in uploadProfilePicture
Browse files Browse the repository at this point in the history
  • Loading branch information
dkovacevic committed May 7, 2024
1 parent 10bfa5c commit 684a5f5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 27 deletions.
13 changes: 6 additions & 7 deletions backend/src/main/java/com/wire/bots/roman/ProviderClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public Response updateServiceURL(NewCookie zprovider, UUID serviceId, String pas
.put(Entity.entity(updateService, MediaType.APPLICATION_JSON));
}

public String uploadProfilePicture(Cookie cookie, byte[] image, String mimeType) throws Exception {
public AssetKey uploadProfilePicture(Cookie cookie, byte[] image, String mimeType) throws Exception {
final boolean isPublic = true;
final String retention = "eternal";
String strMetadata = String.format("{\"public\": %s, \"retention\": \"%s\"}", isPublic, retention);
Expand Down Expand Up @@ -196,18 +196,17 @@ public String uploadProfilePicture(Cookie cookie, byte[] image, String mimeType)
Response response = providerTarget
.path("provider")
.path("assets")
.request(MediaType.APPLICATION_JSON_TYPE)
.request(MediaType.TEXT_PLAIN)
.cookie(cookie)
.post(Entity.entity(os.toByteArray(), "multipart/mixed; boundary=frontier"));

if (response.getStatus() >= 400) {
Logger.warning(response.readEntity(String.class));
return null;
String msg = response.readEntity(String.class);
Logger.warning(msg);
throw new Exception(msg);
}

AssetKey assetKey = response.readEntity(AssetKey.class);

return assetKey.id;
return response.readEntity(AssetKey.class);
}

@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
@Api
@Path("/broadcast")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class BroadcastResource {
private final Sender sender;
private final BotsDAO botsDAO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import io.swagger.annotations.*;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.*;
import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
Expand All @@ -30,6 +27,7 @@
@Api
@Path("/conversation")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class ConversationResource {
private final Sender sender;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
import com.wire.xenon.tools.Logger;
import io.dropwizard.validation.ValidationMethod;
import io.swagger.annotations.*;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import org.hibernate.validator.constraints.Length;
import org.jdbi.v3.core.Jdbi;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.hibernate.validator.constraints.Length;
import org.jdbi.v3.core.Jdbi;

import static com.wire.bots.roman.Tools.generateToken;

@Api
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class ProviderResource {

private final ProviderClient providerClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.wire.bots.roman.model.Provider;
import com.wire.bots.roman.model.Service;
import com.wire.xenon.backend.models.ErrorMessage;
import com.wire.xenon.models.AssetKey;
import com.wire.xenon.tools.Logger;
import io.dropwizard.validation.ValidationMethod;
import io.swagger.annotations.*;
Expand Down Expand Up @@ -39,6 +40,7 @@
@Api
@Path("/service")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class ServiceResource {
private static final String PROFILE_KEY = "3-1-c9262f6f-892f-40d5-9349-fbeb62c8aba4";

Expand Down Expand Up @@ -98,9 +100,9 @@ public Response create(@ApiParam(hidden = true) @CookieParam(Z_ROMAN) String tok
if (image != null) {
String mimeType = "image/png";
Picture mediumImage = ImageProcessor.getMediumImage(new Picture(image, mimeType));
String key = providerClient.uploadProfilePicture(cookie, mediumImage.getImageData(), mimeType);
service.assets.get(0).key = key;
service.assets.get(1).key = key;
AssetKey assetKey = providerClient.uploadProfilePicture(cookie, mediumImage.getImageData(), mimeType);
service.assets.get(0).key = assetKey.id;
service.assets.get(1).key = assetKey.id;
}
}
}
Expand Down Expand Up @@ -213,8 +215,8 @@ public Response update(@Context ContainerRequestContext context,
byte[] image = Base64.getDecoder().decode(payload.avatar);
String mimeType = "image/jpeg";
Picture mediumImage = ImageProcessor.getMediumImage(new Picture(image, mimeType));
String key = providerClient.uploadProfilePicture(cookie, mediumImage.getImageData(), mimeType);
providerClient.updateServiceAvatar(cookie, provider.serviceId, key);
AssetKey assetKey = providerClient.uploadProfilePicture(cookie, mediumImage.getImageData(), mimeType);
providerClient.updateServiceAvatar(cookie, provider.serviceId, assetKey.id);
}

provider = providersDAO.get(providerId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@
import com.wire.xenon.backend.models.User;
import com.wire.xenon.tools.Logger;
import io.swagger.annotations.*;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.*;
import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

import java.util.UUID;

@Api
@Path("/users")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class UsersResource {
private final ClientRepo repo;

Expand Down

0 comments on commit 684a5f5

Please sign in to comment.