Skip to content

Commit 01f057f

Browse files
authored
Merge pull request #4743 from guardian/ld/api-endpoint-for-image-crops
Api endpoint for image crops
2 parents 31c745b + b09475a commit 01f057f

4 files changed

Lines changed: 31 additions & 0 deletions

File tree

media-api/app/MediaApiComponents.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class MediaApiComponents(context: Context) extends GridComponents(context, new M
3737
val usageController = new UsageController(auth, config, elasticSearch, usageQuota, controllerComponents)
3838
val elasticSearchHealthCheck = new ElasticSearchHealthCheck(controllerComponents, elasticSearch)
3939
val healthcheckController = new Management(controllerComponents, buildInfo)
40+
val configurationController = new ConfigurationController(controllerComponents)
4041
val InnerServiceStatusCheckController = new InnerServiceStatusCheckController(auth, controllerComponents, config.services, wsClient)
4142

4243
override val router = new Routes(
@@ -45,6 +46,7 @@ class MediaApiComponents(context: Context) extends GridComponents(context, new M
4546
suggestionController,
4647
aggController,
4748
usageController,
49+
configurationController,
4850
elasticSearchHealthCheck,
4951
healthcheckController,
5052
InnerServiceStatusCheckController
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package controllers
2+
3+
import lib.crops.CropOption
4+
import play.api.libs.json.Json
5+
import play.api.mvc.{BaseController, ControllerComponents}
6+
7+
class ConfigurationController(override val controllerComponents: ControllerComponents) extends BaseController {
8+
// The contents of this endpoint is not sensitive, so to avoid unnecessary complexity we have not
9+
// put authentication on this
10+
def cropVariations = Action { _ => Ok(Json.toJson(CropOption.supported)) }
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package lib.crops
2+
3+
import play.api.libs.json.{Json, OFormat}
4+
5+
case class CropOption(key: String, ratio: String, ratioString: String)
6+
7+
object CropOption {
8+
implicit val jf: OFormat[CropOption] = Json.format[CropOption]
9+
val supported = List(
10+
CropOption("landscape", "5 / 4", "5:4"),
11+
CropOption("portrait", "4 / 5", "4:5"),
12+
CropOption("video", "16 / 9", "16:9"),
13+
CropOption("square", "1", "1:1"),
14+
)
15+
}

media-api/conf/routes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ GET /usage/suppliers/:id controllers.
3939
GET /usage/quotas controllers.UsageController.quotas
4040
GET /usage/quotas/:id controllers.UsageController.quotaForImage(id: String)
4141

42+
# configuration
43+
GET /configuration/crop-variations controllers.ConfigurationController.cropVariations
44+
4245
# Management
4346
GET /management/healthcheck com.gu.mediaservice.lib.management.ElasticSearchHealthCheck.healthCheck
4447
GET /management/manifest com.gu.mediaservice.lib.management.Management.manifest

0 commit comments

Comments
 (0)