Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement BuiltByBit Platform Support #185

Merged
merged 10 commits into from Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
10 changes: 5 additions & 5 deletions gradlew
@@ -1,7 +1,7 @@
#!/bin/sh

#
# Copyright © 2015-2021 the original authors.
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,10 +32,10 @@
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
Expand Down
Expand Up @@ -14,6 +14,7 @@ public enum BannerSprite {
DEFAULT_CURSEFORGE_RES_LOGO,
DEFAULT_MODRINTH_RES_LOGO,
DEFAULT_POLYMART_RES_LOGO,
DEFAULT_BUILTBYBIT_RES_LOGO,
DEFAULT_AUTHOR_LOGO,
DEFAULT_SERVER_LOGO;

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/mcbanners/bannerapi/banner/BannerType.java
Expand Up @@ -10,7 +10,9 @@ public enum BannerType {
CURSEFORGE_RESOURCE,
MODRINTH_AUTHOR,
MODRINTH_RESOURCE,

BUILTBYBIT_AUTHOR,
BUILTBYBIT_RESOURCE,
BUILTBYBIT_MEMBER,
POLYMART_AUTHOR,
POLYMART_RESOURCE
}
@@ -0,0 +1,69 @@
package com.mcbanners.bannerapi.banner.param;

import com.mcbanners.bannerapi.banner.BannerFontFace;
import com.mcbanners.bannerapi.banner.BannerTextAlign;
import com.mcbanners.bannerapi.util.ParamUtil;

import java.util.Map;

public enum MemberParameter implements BannerParameter<Object> {
MEMBER_NAME_X("member_name__x", 104, int.class),
MEMBER_NAME_Y("member_name__y", 22, int.class),
MEMBER_NAME_FONT_SIZE("member_name__font_size", 18, int.class),
MEMBER_NAME_BOLD("member_name__bold", true, boolean.class),
MEMBER_NAME_TEXT_ALIGN("member_name__text_align", BannerTextAlign.LEFT, BannerTextAlign.class),
MEMBER_NAME_FONT_FACE("member_name__font_face", BannerFontFace.SOURCE_SANS_PRO, BannerFontFace.class),
RANK_X("rank__x", 104, int.class),
RANK_Y("rank__y", 37, int.class),
RANK_FONT_SIZE("rank__font_size", 14, int.class),
RANK_BOLD("rank__bold", false, boolean.class),
RANK_TEXT_ALIGN("rank__text_align", BannerTextAlign.LEFT, BannerTextAlign.class),
RANK_FONT_FACE("rank__font_face", BannerFontFace.SOURCE_SANS_PRO, BannerFontFace.class),
JOINED_X("joined__x", 104, int.class),
JOINED_Y("joined__y", 55, int.class),
JOINED_FONT_SIZE("joined__font_size", 14, int.class),
JOINED_BOLD("joined__bold", false, boolean.class),
JOINED_TEXT_ALIGN("joined__text_align", BannerTextAlign.LEFT, BannerTextAlign.class),
JOINED_FONT_FACE("joined__font_face", BannerFontFace.SOURCE_SANS_PRO, BannerFontFace.class),
POSTS_X("posts__x", 104, int.class),
POSTS_Y("posts__y", 72, int.class),
POSTS_FONT_SIZE("posts__font_size", 14, int.class),
POSTS_BOLD("posts__bold", false, boolean.class),
POSTS_TEXT_ALIGN("posts__text_align", BannerTextAlign.LEFT, BannerTextAlign.class),
POSTS_FONT_FACE("posts__font_face", BannerFontFace.SOURCE_SANS_PRO, BannerFontFace.class),
LIKES_X("likes__x", 104, int.class),
LIKES_Y("likes__y", 89, int.class),
LIKES_FONT_SIZE("likes__font_size", 14, int.class),
LIKES_BOLD("likes__bold", false, boolean.class),
LIKES_TEXT_ALIGN("likes__text_align", BannerTextAlign.LEFT, BannerTextAlign.class),
LIKES_FONT_FACE("likes__font_face", BannerFontFace.SOURCE_SANS_PRO, BannerFontFace.class);

private final String key;
private final Object def;
private final Class<?> type;

MemberParameter(String key, Object def, Class<?> type) {
this.key = key;
this.def = def;
this.type = type;
}

public static Map<MemberParameter, Object> parse(Map<String, String> rawParams) {
return ParamUtil.parse(MemberParameter.class, rawParams);
}

@Override
public String getKey() {
return key;
}

@Override
public Object getDefault() {
return def;
}

@Override
public Class<?> getType() {
return type;
}
}
Expand Up @@ -64,6 +64,12 @@ public ResponseEntity<Map<String, Boolean>> getIsValidPolyMart(@PathVariable int
return new ResponseEntity<>(Collections.singletonMap("valid", author != null), HttpStatus.OK);
}

@GetMapping(value = "/builtbybit/{id}/isValid", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Boolean>> getIsValidBuiltByBit(@PathVariable int id) {
Author author = this.authors.getAuthor(id, ServiceBackend.BUILTBYBIT);
return new ResponseEntity<>(Collections.singletonMap("valid", author != null), HttpStatus.OK);
}

@GetMapping(value = "/spigot/{id}/banner.{outputType}", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<byte[]> getBanner(@PathVariable int id, @PathVariable BannerOutputType outputType, @RequestParam Map<String, String> raw) {
Author author = this.authors.getAuthor(id, ServiceBackend.SPIGOT);
Expand Down Expand Up @@ -109,7 +115,6 @@ public ResponseEntity<byte[]> getBannerModrinth(@PathVariable String id, @PathVa

return draw(author, raw, ServiceBackend.MODRINTH, outputType);
}

@GetMapping(value = "/polymart/{id}/banner.{outputType}", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<byte[]> getBannerPolyMart(@PathVariable int id, @PathVariable BannerOutputType outputType, @RequestParam Map<String, String> raw) {
Author author = this.authors.getAuthor(id, ServiceBackend.POLYMART);
Expand All @@ -120,6 +125,15 @@ public ResponseEntity<byte[]> getBannerPolyMart(@PathVariable int id, @PathVaria
return draw(author, raw, ServiceBackend.POLYMART, outputType);
}

@GetMapping(value = "/builtbybit/{id}/banner.{outputType}", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<byte[]> getBannerBuiltByBit(@PathVariable int id, @PathVariable BannerOutputType outputType, @RequestParam Map<String, String> raw) {
Author author = this.authors.getAuthor(id, ServiceBackend.BUILTBYBIT);
if (author == null) {
return new ResponseEntity<>(null, HttpStatus.NOT_FOUND);
}

return draw(author, raw, ServiceBackend.BUILTBYBIT, outputType);
}

private ResponseEntity<byte[]> draw(Author author, Map<String, String> raw, ServiceBackend backend, BannerOutputType outputType) {
return BannerImageWriter.write(new AuthorLayout(author, raw, backend).draw(outputType), outputType);
Expand Down
@@ -0,0 +1,51 @@
package com.mcbanners.bannerapi.controller;

import com.mcbanners.bannerapi.banner.BannerOutputType;
import com.mcbanners.bannerapi.image.BannerImageWriter;
import com.mcbanners.bannerapi.image.layout.MemberLayout;
import com.mcbanners.bannerapi.obj.generic.Member;
import com.mcbanners.bannerapi.service.ServiceBackend;
import com.mcbanners.bannerapi.service.api.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.Map;

@RestController
@RequestMapping("member")
public class MemberController {
private final MemberService members;

@Autowired
public MemberController(MemberService members) {
this.members = members;
}

@GetMapping(value = "/builtbybit/{id}/isValid", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Boolean>> getIsValid(@PathVariable int id) {
Member member = this.members.getMember(id, ServiceBackend.BUILTBYBIT);
return new ResponseEntity<>(Collections.singletonMap("valid", member != null), HttpStatus.OK);
}

@GetMapping(value = "/builtbybit/{id}/banner.{outputType}", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<byte[]> getBanner(@PathVariable int id, @PathVariable BannerOutputType outputType, @RequestParam Map<String, String> raw) {
Member member = this.members.getMember(id, ServiceBackend.BUILTBYBIT);
if (member == null) {
return new ResponseEntity<>(null, HttpStatus.NOT_FOUND);
}

return draw(member, raw, ServiceBackend.BUILTBYBIT, outputType);
}

private ResponseEntity<byte[]> draw(Member member, Map<String, String> raw, ServiceBackend backend, BannerOutputType outputType) {
return BannerImageWriter.write(new MemberLayout(member, raw, backend).draw(outputType), outputType);
}
}
Expand Up @@ -57,6 +57,12 @@ public ResponseEntity<Map<String, Boolean>> getIsValidModrinth(@PathVariable Str
return new ResponseEntity<>(Collections.singletonMap("valid", resource != null), HttpStatus.OK);
}

@GetMapping(value = "/builtbybit/{id}/isValid", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Boolean>> getIsValidBuiltByBit(@PathVariable int id) {
Resource resource = this.resources.getResource(id, ServiceBackend.BUILTBYBIT);
return new ResponseEntity<>(Collections.singletonMap("valid", resource != null), HttpStatus.OK);
}

@GetMapping(value = "/polymart/{id}/isValid", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Boolean>> getIsValidPolyMart(@PathVariable int id) {
Resource resource = this.resources.getResource(id, ServiceBackend.POLYMART);
Expand Down Expand Up @@ -108,6 +114,21 @@ public ResponseEntity<byte[]> getBannerModrinth(@PathVariable String id, @PathVa
return draw(resource, author, raw, ServiceBackend.MODRINTH, outputType);
}

@GetMapping(value = "/builtbybit/{id}/banner.{outputType}", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<byte[]> getBannerBuiltByBit(@PathVariable int id, @PathVariable BannerOutputType outputType, @RequestParam Map<String, String> raw) {
Resource resource = this.resources.getResource(id, ServiceBackend.BUILTBYBIT);
if (resource == null) {
return null;
}

Author author = this.authors.getAuthor(resource.getAuthorId(), ServiceBackend.BUILTBYBIT);
if (author == null) {
return null;
}

return draw(resource, author, raw, ServiceBackend.BUILTBYBIT, outputType);
}

@GetMapping(value = "/sponge/{id}/banner.{outputType}", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<byte[]> getBanner(@PathVariable String id, @PathVariable BannerOutputType outputType, @RequestParam Map<String, String> raw) {
Resource resource = this.resources.getResource(id, ServiceBackend.ORE);
Expand Down
Expand Up @@ -5,16 +5,19 @@
import com.mcbanners.bannerapi.image.BannerImageWriter;
import com.mcbanners.bannerapi.image.layout.AuthorLayout;
import com.mcbanners.bannerapi.image.layout.Layout;
import com.mcbanners.bannerapi.image.layout.MemberLayout;
import com.mcbanners.bannerapi.image.layout.ResourceLayout;
import com.mcbanners.bannerapi.image.layout.ServerLayout;
import com.mcbanners.bannerapi.obj.backend.mcapi.MinecraftServer;
import com.mcbanners.bannerapi.obj.generic.Author;
import com.mcbanners.bannerapi.obj.generic.Member;
import com.mcbanners.bannerapi.obj.generic.Resource;
import com.mcbanners.bannerapi.persistence.SavedBanner;
import com.mcbanners.bannerapi.persistence.SavedBannerRepository;
import com.mcbanners.bannerapi.security.AuthedUserInformation;
import com.mcbanners.bannerapi.service.ServiceBackend;
import com.mcbanners.bannerapi.service.api.AuthorService;
import com.mcbanners.bannerapi.service.api.MemberService;
import com.mcbanners.bannerapi.service.api.MinecraftServerService;
import com.mcbanners.bannerapi.service.api.ResourceService;
import com.mcbanners.bannerapi.util.StringUtil;
Expand All @@ -38,14 +41,16 @@ public class SavedController {
private final ResourceService resources;
private final AuthorService authors;
private final MinecraftServerService servers;
private final MemberService members;
private final SavedBannerRepository repository;

@Autowired
public SavedController(ResourceService resources, SavedBannerRepository repository, AuthorService authors, MinecraftServerService servers) {
public SavedController(ResourceService resources, SavedBannerRepository repository, AuthorService authors, MinecraftServerService servers, MemberService members) {
this.resources = resources;
this.repository = repository;
this.authors = authors;
this.servers = servers;
this.members = members;
}

@PostMapping(value = "save/{type}", produces = MediaType.APPLICATION_JSON_VALUE)
Expand Down Expand Up @@ -86,6 +91,7 @@ public ResponseEntity<byte[]> recall(@PathVariable String mnemonic, @PathVariabl
case SPONGE_AUTHOR:
case CURSEFORGE_AUTHOR:
case MODRINTH_AUTHOR:
case BUILTBYBIT_AUTHOR:
case POLYMART_AUTHOR:
Author author = null;
switch (banner.getBannerType()) {
Expand All @@ -105,9 +111,13 @@ public ResponseEntity<byte[]> recall(@PathVariable String mnemonic, @PathVariabl
backend = ServiceBackend.MODRINTH;
author = authors.getAuthor(settings.get("_author_id"), backend);
break;
case BUILTBYBIT_AUTHOR:
backend = ServiceBackend.BUILTBYBIT;
author = authors.getAuthor(Integer.parseInt(settings.get("_author_id")), backend);
break;
case POLYMART_AUTHOR:
backend = ServiceBackend.POLYMART;
author = authors.getAuthor(settings.get("_author_id"), backend);
author = authors.getAuthor(Integer.parseInt(settings.get("_author_id")), backend);
break;
}

Expand All @@ -127,6 +137,7 @@ public ResponseEntity<byte[]> recall(@PathVariable String mnemonic, @PathVariabl
case SPONGE_RESOURCE:
case CURSEFORGE_RESOURCE:
case MODRINTH_RESOURCE:
case BUILTBYBIT_RESOURCE:
case POLYMART_RESOURCE:
Resource resource = null;
author = null;
Expand All @@ -151,6 +162,11 @@ public ResponseEntity<byte[]> recall(@PathVariable String mnemonic, @PathVariabl
resource = resources.getResource(settings.get("_resource_id"), backend);
author = authors.getAuthor(resource.getAuthorName(), backend);
break;
case BUILTBYBIT_RESOURCE:
backend = ServiceBackend.BUILTBYBIT;
resource = resources.getResource(Integer.parseInt(settings.get("_resource_id")), backend);
author = authors.getAuthor(resource.getAuthorId(), backend);
break;
case POLYMART_RESOURCE:
backend = ServiceBackend.POLYMART;
resource = resources.getResource(Integer.parseInt(settings.get("_resource_id")), backend);
Expand Down Expand Up @@ -191,6 +207,26 @@ public ResponseEntity<byte[]> recall(@PathVariable String mnemonic, @PathVariabl
settings.remove("_server_port");

layout = new ServerLayout(server, settings);
break;
case BUILTBYBIT_MEMBER:
Member member = null;
if (banner.getBannerType() == BannerType.BUILTBYBIT_MEMBER) {
backend = ServiceBackend.BUILTBYBIT;
member = members.getMember(Integer.parseInt(settings.get("_member_id")), backend);
}

settings.remove("_member_id");

if (backend == null) {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Backend not set");
}

if (member == null) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "The stored author could not be found!");
}

layout = new MemberLayout(member, settings, backend);
break;
}

return BannerImageWriter.write(layout.draw(outputType), outputType);
Expand Down
Expand Up @@ -6,6 +6,7 @@
import com.mcbanners.bannerapi.banner.param.AuthorParameter;
import com.mcbanners.bannerapi.banner.param.BannerParameter;
import com.mcbanners.bannerapi.banner.param.GeneralParameter;
import com.mcbanners.bannerapi.banner.param.MemberParameter;
import com.mcbanners.bannerapi.banner.param.ResourceParameter;
import com.mcbanners.bannerapi.banner.param.ServerParameter;
import com.mcbanners.bannerapi.util.ParamUtil;
Expand Down Expand Up @@ -49,6 +50,7 @@ public ResponseEntity<Object> getDefaults(@PathVariable String type) {

if (bypass || type.equals("author")) toSerialize.put("author", AuthorParameter.class);
if (bypass || type.equals("resource")) toSerialize.put("resource", ResourceParameter.class);
if (bypass || type.equals("member")) toSerialize.put("member", MemberParameter.class);
if (bypass || type.equals("server")) toSerialize.put("server", ServerParameter.class);

Object out;
Expand Down