Skip to content

Commit

Permalink
Update StopModReposts API
Browse files Browse the repository at this point in the history
Courtesy of @HRudyPlayZ
  • Loading branch information
ACGaming committed Mar 5, 2023
1 parent 0c34bd6 commit ef6d2a3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,47 +31,43 @@ public static void check(ModDirector director, URL url) throws ModDirectorExcept
}

director.getLogger().log(ModDirectorSeverityLevel.DEBUG, "StopModReposts", "CORE",
"Checking %s against StopModReposts database", url.toExternalForm());
"Checking %s against StopModReposts database", url.toExternalForm());
for(StopModRepostsEntry entry : ENTRIES) {
if(entry.pattern().matcher(url.toExternalForm()).matches()) {
if(url.toExternalForm().contains(entry.domain()) ) {
director.getLogger().log(ModDirectorSeverityLevel.ERROR, "StopModReposts", "CORE",
"STOP! Download URL %s is flagged in StopModReposts database, ABORTING!",
url.toExternalForm());
"STOP! Download URL %s is flagged in StopModReposts database, ABORTING!",
url.toExternalForm());
director.getLogger().log(ModDirectorSeverityLevel.ERROR, "StopModReposts", "CORE",
"Domain %s is flagged", entry.domain());
"Domain %s is flagged", entry.domain());
director.getLogger().log(ModDirectorSeverityLevel.ERROR, "StopModReposts", "CORE",
"Advertising score: %d", entry.advertising());
director.getLogger().log(ModDirectorSeverityLevel.ERROR, "StopModReposts", "CORE",
"Redistribution score: %d", entry.redistribution());
director.getLogger().log(ModDirectorSeverityLevel.ERROR, "StopModReposts", "CORE",
"Miscellaneous: ", entry.miscellaneous());
"Reason: ", entry.reason());
if(!entry.notes().isEmpty()) {
director.getLogger().log(ModDirectorSeverityLevel.ERROR, "StopModReposts", "CORE",
"Notes: ", entry.notes());
"Notes: ", entry.notes());
}
director.addError(new ModDirectorError(ModDirectorSeverityLevel.ERROR,
"Found URL " + url.toExternalForm() + " on domain " + entry.domain() + " flagged " +
"in the StopModReposts database! Please use legal download pages, " +
"ModDirector has aborted the launch."));
"Found URL " + url.toExternalForm() + " on domain " + entry.domain() + " flagged " +
"in the StopModReposts database! Please use legal download pages, " +
"ModDirector has aborted the launch."));
throw new ModDirectorException("Found flagged URL " + url.toExternalForm() +
" in StopModReposts database");
" in StopModReposts database");
}
}
}

private static void initialize(ModDirector director) throws ModDirectorException {
director.getLogger().log(ModDirectorSeverityLevel.DEBUG, "StopModReposts", "CORE",
"Initializing StopModReposts module");
"Initializing StopModReposts module");

try(WebGetResponse response =
WebClient.get(new URL("https://api.varden.info/smr/sitelist.php?format=json"))) {
WebClient.get(new URL("https://api.stopmodreposts.org/sites.json"))) {
JavaType targetType = ConfigurationController.OBJECT_MAPPER.getTypeFactory().
constructCollectionType(List.class, StopModRepostsEntry.class);
constructCollectionType(List.class, StopModRepostsEntry.class);

ENTRIES.addAll(ConfigurationController.OBJECT_MAPPER.readValue(response.getInputStream(), targetType));
} catch(MalformedURLException e) {
throw new RuntimeException(
"https://api.varden.info/smr/sitelist.php?format=json seems to be an invalid URL?", e);
"https://api.stopmodreposts.org/sites.json seems to be an invalid URL?", e);
} catch(IOException e) {
throw new ModDirectorException("Failed to retrieve StopModReposts database", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,22 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.regex.Pattern;

public class StopModRepostsEntry {
private final String domain;
private final String path;
private final Pattern pattern;
private final int advertising;
private final int redistribution;
private final int miscellaneous;
private final String reason;
private final String notes;

@JsonCreator
public StopModRepostsEntry(
@JsonProperty(value = "domain", required = true) String domain,
@JsonProperty(value = "path", required = true) String path,
@JsonProperty(value = "pattern", required = true) Pattern pattern,
@JsonProperty(value = "advertising", required = true) int advertising,
@JsonProperty(value = "redistribution", required = true) int redistribution,
@JsonProperty(value = "miscellaneous", required = true) int miscellaneous,
@JsonProperty(value = "notes", required = true) String notes
@JsonProperty(value = "domain", required = true) String domain,
@JsonProperty(value = "path", required = true) String path,
@JsonProperty(value = "reason", required = true) String reason,
@JsonProperty(value = "notes", required = true) String notes
) {
this.domain = domain;
this.path = path;
this.pattern = pattern;
this.advertising = advertising;
this.redistribution = redistribution;
this.miscellaneous = miscellaneous;
this.reason = reason;
this.notes = notes;
}

Expand All @@ -41,20 +30,8 @@ public String path() {
return path;
}

public Pattern pattern() {
return pattern;
}

public int advertising() {
return advertising;
}

public int redistribution() {
return redistribution;
}

public int miscellaneous() {
return miscellaneous;
public String reason() {
return reason;
}

public String notes() {
Expand Down

1 comment on commit ef6d2a3

@ACGaming
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closes Janrupf#24

Please sign in to comment.