Skip to content

Commit

Permalink
Server: Move the WiiMC routes into a dedicated service.
Browse files Browse the repository at this point in the history
  • Loading branch information
e3ndr committed Oct 2, 2023
1 parent 0ad6547 commit e924fbf
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 8 deletions.
9 changes: 8 additions & 1 deletion server/src/main/java/xyz/e3ndr/athena/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static class ServiceConfig {
public HttpServiceConfig http = new HttpServiceConfig();
public FtpServiceConfig ftp = new FtpServiceConfig();
public @JsonField("simple_ui") SimpleUIConfig simpleUI = new SimpleUIConfig();
public @JsonField("wii_mc") WiiMCServiceConfig wiimc = new WiiMCServiceConfig();
public @JsonField("special") SpecialServiceConfig special = new SpecialServiceConfig();

@ToString
@JsonClass(exposeAll = true)
Expand All @@ -48,6 +48,13 @@ public static class SimpleUIConfig {
public int port = 8127;
}

@ToString
@JsonClass(exposeAll = true)
public static class SpecialServiceConfig {
public boolean enable = false;
public int port = 8128;
}

}

@ToString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ public void init() {
}
}

public static class AthenaSoraAdapter extends SoraPlugin {
static class AthenaSoraAdapter extends SoraPlugin {

@Override
public void onInit(Sora sora) {
sora.addProvider(this, new MetaRoutes());
sora.addProvider(this, new MediaRoutes());
sora.addProvider(this, new StreamRoutes());
sora.addProvider(this, new SessionRoutes());
sora.addProvider(this, new WiiMCRoutes());
sora.addProvider(this, new IngestApiRoutes());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void init() {
}
}

public static class AthenaSoraAdapter extends SoraPlugin {
static class AthenaSoraAdapter extends SoraPlugin {

@Override
public void onInit(Sora sora) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package xyz.e3ndr.athena.service.special;

import org.jetbrains.annotations.Nullable;

import co.casterlabs.sora.Sora;
import co.casterlabs.sora.SoraFramework;
import co.casterlabs.sora.SoraLauncher;
import co.casterlabs.sora.api.SoraPlugin;
import lombok.NonNull;
import xyz.e3ndr.athena.Athena;
import xyz.e3ndr.athena.service.AthenaService;
import xyz.e3ndr.fastloggingframework.logging.FastLogger;
import xyz.e3ndr.fastloggingframework.logging.LogLevel;

public class AthenaSpecialServer implements AthenaService {

@Override
public void init() {
try {
int port = Athena.config.services.http.port;

SoraFramework framework = new SoraLauncher()
.setPort(port)
.buildWithoutPluginLoader();

framework
.getSora()
.register(new AthenaSoraAdapter());

framework
.getServer()
.getLogger()
.setCurrentLevel(LogLevel.WARNING);

framework.startHttpServer();

FastLogger.logStatic("Started special server on %d!", port);
} catch (Exception e) {
FastLogger.logStatic(LogLevel.SEVERE, "Unable to start special server:\n%s", e);
}
}

static class AthenaSoraAdapter extends SoraPlugin {

@Override
public void onInit(Sora sora) {
sora.addProvider(this, new WiiMCRoutes());
sora.addProvider(this, new InternalRoutes());
}

@Override
public void onClose() {}

@Override
public @Nullable String getVersion() {
return null;
}

@Override
public @Nullable String getAuthor() {
return null;
}

@Override
public @NonNull String getName() {
return "Athena";
}

@Override
public @NonNull String getId() {
return "athena";
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package xyz.e3ndr.athena.service.special;

import co.casterlabs.rakurai.io.http.server.HttpResponse;
import co.casterlabs.sora.api.http.HttpProvider;
import co.casterlabs.sora.api.http.SoraHttpSession;
import co.casterlabs.sora.api.http.annotations.HttpEndpoint;
import xyz.e3ndr.athena.service.http.StreamRoutes;

class InternalRoutes implements HttpProvider {
private StreamRoutes streamRoutes = new StreamRoutes();

@HttpEndpoint(uri = "/_internal/media/:mediaId/stream")
public HttpResponse onStreamRAW(SoraHttpSession session) {
return this.streamRoutes.onStreamRAW(session);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xyz.e3ndr.athena.service.http;
package xyz.e3ndr.athena.service.special;

import java.util.List;

Expand All @@ -12,7 +12,7 @@

class WiiMCRoutes implements HttpProvider {

@HttpEndpoint(uri = "/api/wiimc/list")
@HttpEndpoint(uri = "/wiimc/list")
public HttpResponse onList(SoraHttpSession session) {
List<Media> mediaList = Athena.listMedia(0, Integer.MAX_VALUE);

Expand All @@ -25,7 +25,7 @@ public HttpResponse onList(SoraHttpSession session) {
.setMimeType("text/plain");
}

@HttpEndpoint(uri = "/api/wiimc/search")
@HttpEndpoint(uri = "/wiimc/search")
public HttpResponse onSearch(SoraHttpSession session) {
String query = session.getQueryParameters().getOrDefault("q", "");
List<Media> mediaList = Athena.searchMedia(query);
Expand All @@ -46,7 +46,7 @@ private static String generatePlaylistForMedia(String host, List<Media> mediaLis
int idx = 1;
for (Media media : mediaList) {
String url = String.format(
"http://%s/api/media/%s/stream/raw?quality=SD&format=MKV&videoCodec=H264&audioCodec=AAC",
"http://%s/_internal/media/%s/stream/raw?quality=SD&format=MKV&videoCodec=H264&audioCodec=AAC",
host, media.getId()
);

Expand Down

0 comments on commit e924fbf

Please sign in to comment.