initial import
This commit is contained in:
16
app/Api/Plugins/ApiPluginInterface.php
Normal file
16
app/Api/Plugins/ApiPluginInterface.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Plugins;
|
||||
|
||||
interface ApiPluginInterface
|
||||
{
|
||||
public function getIdentifier(): string;
|
||||
public function getName(): string;
|
||||
public function isEnabled(): bool;
|
||||
public function enable(): bool;
|
||||
public function disable(): bool;
|
||||
public function getStatus(string $imageUUID): array;
|
||||
public function getProgress(string $imageUUID): array;
|
||||
public function upload(string $imagePath): array;
|
||||
public function styleChangeRequest(string $prompt, string $seedImageUUID): array;
|
||||
}
|
||||
29
app/Api/Plugins/PluginLoader.php
Normal file
29
app/Api/Plugins/PluginLoader.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Plugins;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class PluginLoader
|
||||
{
|
||||
protected static $plugins = [];
|
||||
|
||||
public static function registerPlugin(string $name, string $className)
|
||||
{
|
||||
if (!class_exists($className)) {
|
||||
throw new InvalidArgumentException("Plugin class {$className} not found.");
|
||||
}
|
||||
if (!in_array(ApiPluginInterface::class, class_implements($className))) {
|
||||
throw new InvalidArgumentException("Plugin class {$className} must implement ApiPluginInterface.");
|
||||
}
|
||||
static::$plugins[$name] = $className;
|
||||
}
|
||||
|
||||
public static function getPlugin(string $name): ApiPluginInterface
|
||||
{
|
||||
if (!isset(static::$plugins[$name])) {
|
||||
throw new InvalidArgumentException("Plugin {$name} not registered.");
|
||||
}
|
||||
return new static::$plugins[$name]();
|
||||
}
|
||||
}
|
||||
106
app/Api/Plugins/RunwareAIPlugin.php
Normal file
106
app/Api/Plugins/RunwareAIPlugin.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Plugins;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
||||
class RunwareAIPlugin implements ApiPluginInterface
|
||||
{
|
||||
protected $client;
|
||||
protected $apiUrl;
|
||||
protected $apiKey;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// Hier müssten die API-URL und der API-Schlüssel aus der Datenbank oder Konfiguration geladen werden.
|
||||
// Fürs Erste hardcodiere ich sie als Platzhalter.
|
||||
$this->apiUrl = env('RUNWARE_AI_API_URL', 'https://api.runware.ai/v1');
|
||||
$this->apiKey = env('RUNWARE_AI_API_KEY', 'YOUR_RUNWARE_AI_API_KEY');
|
||||
|
||||
$this->client = new Client([
|
||||
'base_uri' => $this->apiUrl,
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . $this->apiKey,
|
||||
'Accept' => 'application/json',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function getIdentifier(): string
|
||||
{
|
||||
return 'runware-ai';
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return 'Runware AI';
|
||||
}
|
||||
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
// Implementieren Sie hier die Logik, um zu prüfen, ob das Plugin aktiviert ist
|
||||
return true;
|
||||
}
|
||||
|
||||
public function enable(): bool
|
||||
{
|
||||
// Implementieren Sie hier die Logik zum Aktivieren des Plugins
|
||||
return true;
|
||||
}
|
||||
|
||||
public function disable(): bool
|
||||
{
|
||||
// Implementieren Sie hier die Logik zum Deaktivieren des Plugins
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getStatus(string $imageUUID): array
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get("image-inference/status/{$imageUUID}");
|
||||
return json_decode($response->getBody()->getContents(), true);
|
||||
} catch (RequestException $e) {
|
||||
return ['error' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
public function getProgress(string $imageUUID): array
|
||||
{
|
||||
// Runware AI hat keine separate Progress-API, Status enthält den Fortschritt
|
||||
return $this->getStatus($imageUUID);
|
||||
}
|
||||
|
||||
public function upload(string $imagePath): array
|
||||
{
|
||||
try {
|
||||
$response = $this->client->post('image-inference/upload', [
|
||||
'multipart' => [
|
||||
[
|
||||
'name' => 'image',
|
||||
'contents' => fopen($imagePath, 'r'),
|
||||
'filename' => basename($imagePath),
|
||||
],
|
||||
],
|
||||
]);
|
||||
return json_decode($response->getBody()->getContents(), true);
|
||||
} catch (RequestException $e) {
|
||||
return ['error' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
public function styleChangeRequest(string $prompt, string $seedImageUUID): array
|
||||
{
|
||||
try {
|
||||
$response = $this->client->post('image-inference/image-to-image', [
|
||||
'json' => [
|
||||
'prompt' => $prompt,
|
||||
'seed_image_uuid' => $seedImageUUID,
|
||||
],
|
||||
]);
|
||||
return json_decode($response->getBody()->getContents(), true);
|
||||
} catch (RequestException $e) {
|
||||
return ['error' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user