Skip to content

Commit

Permalink
added 3 endpoints for external public mentions to work (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
seannian authored Apr 28, 2024
1 parent 7b1eb5a commit a3a264c
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 11 deletions.
44 changes: 34 additions & 10 deletions server/src/main/java/edu/sjsu/moth/generated/Icon.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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")
Expand All @@ -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
Expand All @@ -54,6 +60,18 @@ public String toString() {
sb.append('=');
sb.append(((this.url == null) ? "<null>" : this.url));
sb.append(',');
sb.append("src");
sb.append('=');
sb.append(((this.src == null) ? "<null>" : this.src));
sb.append(',');
sb.append("sizes");
sb.append('=');
sb.append(((this.sizes == null) ? "<null>" : this.sizes));
sb.append(',');
sb.append("purpose");
sb.append('=');
sb.append(((this.purpose == null) ? "<null>" : this.purpose));
sb.append(',');
if (sb.charAt((sb.length() - 1)) == ',') {
sb.setCharAt((sb.length() - 1), ']');
} else {
Expand All @@ -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;
}

Expand All @@ -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)));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public static Mono<Account> convertToAccount(Actor actor) {

@PostMapping("/inbox")
public Mono<ResponseEntity<Object>> inbox(@RequestBody JsonNode inboxNode) {
//handle here
String requestType = inboxNode.get("type").asText();
if (requestType.equals("Delete")) {
return Mono.empty();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -109,4 +113,91 @@ Mono<ResponseEntity<Object>> getProfile(@PathVariable String id) {
return ResponseEntity.ok(profile);
});
}

@GetMapping("/manifest.json")
public Mono<ManifestJSON> manifest() {
String name = MothConfiguration.mothConfiguration.getServerName();
String short_name = MothConfiguration.mothConfiguration.getServerName();

List<Icon> 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<Shortcut> 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<NodeInfo2> 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<NodeInfo> 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<Icon> icons, String theme_color,
String background_color, String display, String start_url, String scope,
ShareTarget share_target, List<Shortcut> shortcuts) {}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "links" })
public record NodeInfo(List<Link> links) {}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "version", "software", "protocols", "services", "usage", "openRegistrations", "metadata" })
public record NodeInfo2(String version, Software software, List<String> 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<String> outbound, List<String> 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) {}
}

0 comments on commit a3a264c

Please sign in to comment.