-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
72 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
package io.github.robothy.sdwebui.sdk; | ||
|
||
|
||
import io.github.robothy.sdwebui.sdk.models.SdWebuiOptions; | ||
import io.github.robothy.sdwebui.sdk.services.SdWebuiInvocationHandler; | ||
|
||
import java.lang.reflect.Proxy; | ||
|
||
public interface SdWebui extends SystemInfoFetcher, Txt2Image, Image2Image { | ||
|
||
static SdWebui create(String endpoint) { | ||
return (SdWebui) Proxy.newProxyInstance(SdWebui.class.getClassLoader(), new Class[]{SdWebui.class}, new SdWebuiInvocationHandler(endpoint)); | ||
SdWebuiOptions options = new SdWebuiOptions(endpoint); | ||
return (SdWebui) Proxy.newProxyInstance(SdWebui.class.getClassLoader(), new Class[]{SdWebui.class}, new SdWebuiInvocationHandler(options)); | ||
} | ||
|
||
} |
5 changes: 3 additions & 2 deletions
5
src/main/java/io/github/robothy/sdwebui/sdk/SdWebuiBeanContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/io/github/robothy/sdwebui/sdk/models/SdWebuiOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.github.robothy.sdwebui.sdk.models; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class SdWebuiOptions { | ||
|
||
private final String endpoint; | ||
|
||
public SdWebuiOptions(String endpoint) { | ||
this.endpoint = endpoint; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,4 @@ public class SystemInfo { | |
@JsonProperty("Version") | ||
private String sdwebuiVersion; | ||
|
||
private String endpoint; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/io/github/robothy/sdwebui/sdk/services/CommonGetService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.github.robothy.sdwebui.sdk.services; | ||
|
||
import io.github.robothy.sdwebui.sdk.SdWebuiBeanContainer; | ||
import io.github.robothy.sdwebui.sdk.models.SdWebuiOptions; | ||
import io.github.robothy.sdwebui.sdk.utils.SdWebuiResponseUtils; | ||
import java.io.IOException; | ||
import org.apache.hc.client5.http.classic.HttpClient; | ||
import org.apache.hc.client5.http.classic.methods.HttpGet; | ||
|
||
final class CommonGetService { | ||
|
||
private final SdWebuiBeanContainer container; | ||
|
||
public CommonGetService(SdWebuiBeanContainer container) { | ||
this.container = container; | ||
} | ||
|
||
public <T> T getData(String path, Class<T> clazz) { | ||
HttpClient client = this.container.getBean(HttpClient.class); | ||
SdWebuiOptions sdWebuiOptions = this.container.getBean(SdWebuiOptions.class); | ||
try { | ||
return client.execute(new HttpGet(sdWebuiOptions.getEndpoint() + path), | ||
response -> SdWebuiResponseUtils.parseResponse(response, clazz)); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters