diff --git a/server/src/main/java/edu/sjsu/moth/generated/Icon.java b/server/src/main/java/edu/sjsu/moth/generated/Icon.java index 636724a2..c3e05a57 100644 --- a/server/src/main/java/edu/sjsu/moth/generated/Icon.java +++ b/server/src/main/java/edu/sjsu/moth/generated/Icon.java @@ -1,7 +1,7 @@ // THIS FILE WAS GENERATED BY JSON2JAVA // IT HAS NOT BEEN CHANGED. (IF IT HAS REMOVE THIS LINE) // CHANGES MADE: -// * NONE SO FAR +// * ADDED MORE FIELDS: PURPOSE, SIZES, SRC package edu.sjsu.moth.generated; @@ -12,7 +12,7 @@ import java.util.Objects; @JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({ "type", "mediaType", "url" }) +@JsonPropertyOrder({ "type", "mediaType", "url", "src", "sizes", "purpose" }) public class Icon { @JsonProperty("type") @@ -21,18 +21,24 @@ public class Icon { public String mediaType; @JsonProperty("url") public String url; + @JsonProperty("src") + public String src; + @JsonProperty("sizes") + public String sizes; + @JsonProperty("purpose") + public String purpose; - /** - * No args constructor for use in serialization - */ public Icon() { } - public Icon(String type, String mediaType, String url) { + public Icon(String type, String mediaType, String url, String src, String sizes, String purpose) { super(); this.type = type; this.mediaType = mediaType; this.url = url; + this.src = src; + this.sizes = sizes; + this.purpose = purpose; } @Override @@ -54,6 +60,18 @@ public String toString() { sb.append('='); sb.append(((this.url == null) ? "" : this.url)); sb.append(','); + sb.append("src"); + sb.append('='); + sb.append(((this.src == null) ? "" : this.src)); + sb.append(','); + sb.append("sizes"); + sb.append('='); + sb.append(((this.sizes == null) ? "" : this.sizes)); + sb.append(','); + sb.append("purpose"); + sb.append('='); + sb.append(((this.purpose == null) ? "" : this.purpose)); + sb.append(','); if (sb.charAt((sb.length() - 1)) == ',') { sb.setCharAt((sb.length() - 1), ']'); } else { @@ -68,6 +86,9 @@ public int hashCode() { result = ((result * 31) + ((this.mediaType == null) ? 0 : this.mediaType.hashCode())); result = ((result * 31) + ((this.type == null) ? 0 : this.type.hashCode())); result = ((result * 31) + ((this.url == null) ? 0 : this.url.hashCode())); + result = ((result * 31) + ((this.src == null) ? 0 : this.src.hashCode())); + result = ((result * 31) + ((this.sizes == null) ? 0 : this.sizes.hashCode())); + result = ((result * 31) + ((this.purpose == null) ? 0 : this.purpose.hashCode())); return result; } @@ -76,11 +97,14 @@ public boolean equals(Object other) { if (other == this) { return true; } - if (!(other instanceof Icon)) { + if (!(other instanceof Icon rhs)) { return false; } - Icon rhs = ((Icon) other); - return (((Objects.equals(this.mediaType, rhs.mediaType)) && (Objects.equals(this.type, rhs.type))) && (Objects.equals(this.url, rhs.url))); + return (((Objects.equals(this.mediaType, rhs.mediaType)) && (Objects.equals(this.type, + rhs.type))) && (Objects.equals( + this.url, rhs.url)) && (Objects.equals(this.src, rhs.src)) && (Objects.equals(this.sizes, + rhs.sizes)) && (Objects.equals( + this.purpose, rhs.purpose))); } -} \ No newline at end of file +} diff --git a/server/src/main/java/edu/sjsu/moth/server/controller/InboxController.java b/server/src/main/java/edu/sjsu/moth/server/controller/InboxController.java index 0ca8e2f6..40c98ae1 100644 --- a/server/src/main/java/edu/sjsu/moth/server/controller/InboxController.java +++ b/server/src/main/java/edu/sjsu/moth/server/controller/InboxController.java @@ -110,7 +110,6 @@ public static Mono convertToAccount(Actor actor) { @PostMapping("/inbox") public Mono> inbox(@RequestBody JsonNode inboxNode) { - //handle here String requestType = inboxNode.get("type").asText(); if (requestType.equals("Delete")) { return Mono.empty(); diff --git a/server/src/main/java/edu/sjsu/moth/server/controller/MothController.java b/server/src/main/java/edu/sjsu/moth/server/controller/MothController.java index e58f9456..9fc838e7 100644 --- a/server/src/main/java/edu/sjsu/moth/server/controller/MothController.java +++ b/server/src/main/java/edu/sjsu/moth/server/controller/MothController.java @@ -1,5 +1,8 @@ package edu.sjsu.moth.server.controller; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import edu.sjsu.moth.generated.Icon; import edu.sjsu.moth.server.db.WebfingerRepository; import edu.sjsu.moth.server.service.AccountService; import edu.sjsu.moth.server.util.MothConfiguration; @@ -19,6 +22,7 @@ import reactor.core.publisher.Mono; import java.security.Principal; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.logging.Logger; @@ -109,4 +113,91 @@ Mono> getProfile(@PathVariable String id) { return ResponseEntity.ok(profile); }); } + + @GetMapping("/manifest.json") + public Mono manifest() { + String name = MothConfiguration.mothConfiguration.getServerName(); + String short_name = MothConfiguration.mothConfiguration.getServerName(); + + List icons = new ArrayList<>(); + Icon x32 = new Icon("image/png", null, null, "moth/icons/cyber-moth-32.png", "32x32", "any maskable"); + Icon x48 = new Icon("image/png", null, null, "moth/icons/cyber-moth-48.png", "48x48", "any maskable"); + Icon x144 = new Icon("image/png", null, null, "moth/icons/cyber-moth-144.png", "144x144", "any maskable"); + Icon x256 = new Icon("image/png", null, null, "moth/icons/cyber-moth-256.png", "256x256", "any maskable"); + Icon x512 = new Icon("image/png", null, null, "moth/icons/cyber-moth-512x512.png", "512x512", "any maskable"); + icons.add(x32); + icons.add(x48); + icons.add(x144); + icons.add(x256); + icons.add(x512); + + String theme_color = "#FFFFFF"; + String background_color = "#FFFFFF"; + String display = "standalone"; + String start_url = "/home"; + String scope = "/"; + + // unsure + ShareTarget share_target = new ShareTarget("share?title={title}&text={text}&url={url}", "share", "GET", + "application/x-www-form-urlencoded", + new Params("title", "text", "url")); + + List shortcuts = new ArrayList<>(); //may need to change to null + shortcuts.add(new Shortcut("name", "url")); + + return Mono.just( + new ManifestJSON(name, short_name, icons, theme_color, background_color, display, start_url, scope, + share_target, shortcuts)); + } + + // TODO: add data in Usage + // TODO: to grab from account DB + @GetMapping("/nodeinfo/2.0") + public Mono nodeInfo2Mono() { + return Mono.just(new NodeInfo2("2.0", new Software("mastodon", "4.2.8"), List.of("activitypub"), + new Services(List.of(""), List.of("")), new Usage(new Users(0, 0, 0), 0), true, + new Metadata())); + } + + @GetMapping("/.well-known/nodeinfo") + public Mono nodeInfoMono() { + return Mono.just(new NodeInfo( + List.of(new Link("http://nodeinfo.diaspora.software/ns/schema/2.0", "https://" + MothConfiguration.mothConfiguration.getServerName() + "/nodeinfo/2.0")))); + // added placeholders, hardcoded + } + + @JsonInclude(JsonInclude.Include.NON_NULL) + @JsonPropertyOrder({ "name", "short_name", "icons", "theme_color", "background_color", "display", "start_url", + "scope", "share_target", "shortcuts" }) + public record ManifestJSON(String name, String short_name, List icons, String theme_color, + String background_color, String display, String start_url, String scope, + ShareTarget share_target, List shortcuts) {} + + @JsonInclude(JsonInclude.Include.NON_NULL) + @JsonPropertyOrder({ "links" }) + public record NodeInfo(List links) {} + + @JsonInclude(JsonInclude.Include.NON_NULL) + @JsonPropertyOrder({ "version", "software", "protocols", "services", "usage", "openRegistrations", "metadata" }) + public record NodeInfo2(String version, Software software, List protocols, Services services, Usage usage, + boolean openRegistrations, Metadata metadata) {} + + public record Software(String name, String version) {} + + // Unsure if it is List of Strings. + public record Services(List outbound, List inbound) {} + + public record Usage(Users user, int localPosts) {} + + public record Users(int total, int activeMonth, int activeHalfyear) {} + + public record Metadata() {} + + public record Shortcut(String name, String url) {} + + public record Params(String title, String text, String url) {} + + public record ShareTarget(String url_template, String action, String method, String enctype, Params params) {} + + public record Link(String rel, String href) {} }