added enabled/disable to styles
This commit is contained in:
145
app/Api/Plugins/RunwareAi.php
Normal file
145
app/Api/Plugins/RunwareAi.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Plugins;
|
||||
|
||||
use App\Models\ApiProvider;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class RunwareAi implements ApiPluginInterface
|
||||
{
|
||||
use LoggablePlugin;
|
||||
|
||||
protected $apiProvider;
|
||||
|
||||
public function __construct(ApiProvider $apiProvider)
|
||||
{
|
||||
$this->apiProvider = $apiProvider;
|
||||
$this->logInfo('RunwareAi plugin initialized.', ['provider_name' => $apiProvider->name]);
|
||||
}
|
||||
|
||||
public function getIdentifier(): string
|
||||
{
|
||||
return 'runwareai';
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return 'RunwareAI';
|
||||
}
|
||||
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return $this->apiProvider->enabled;
|
||||
}
|
||||
|
||||
public function enable(): bool
|
||||
{
|
||||
$this->apiProvider->enabled = true;
|
||||
$result = $this->apiProvider->save();
|
||||
if ($result) {
|
||||
$this->logInfo('RunwareAi plugin enabled.', ['provider_name' => $this->apiProvider->name]);
|
||||
} else {
|
||||
$this->logError('Failed to enable RunwareAi plugin.', ['provider_name' => $this->apiProvider->name]);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function disable(): bool
|
||||
{
|
||||
$this->apiProvider->enabled = false;
|
||||
$result = $this->apiProvider->save();
|
||||
if ($result) {
|
||||
$this->logInfo('RunwareAi plugin disabled.', ['provider_name' => $this->apiProvider->name]);
|
||||
} else {
|
||||
$this->logError('Failed to disable RunwareAi plugin.', ['provider_name' => $this->apiProvider->name]);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getStatus(string $imageUUID): array
|
||||
{
|
||||
$this->logDebug('Getting status for image.', ['image_uuid' => $imageUUID]);
|
||||
// Implement RunwareAI specific status check
|
||||
return ['status' => 'unknown'];
|
||||
}
|
||||
|
||||
public function getProgress(string $imageUUID): array
|
||||
{
|
||||
$this->logDebug('Getting progress for image.', ['image_uuid' => $imageUUID]);
|
||||
// Implement RunwareAI specific progress check
|
||||
return ['progress' => 0];
|
||||
}
|
||||
|
||||
public function upload(string $imagePath): array
|
||||
{
|
||||
$this->logInfo('Attempting to upload image to RunwareAI.', ['image_path' => $imagePath]);
|
||||
if (!$this->apiProvider->api_url || !$this->apiProvider->token) {
|
||||
$this->logError('RunwareAI API URL or Token not configured for upload.', ['provider_name' => $this->apiProvider->name]);
|
||||
throw new \Exception('RunwareAI API URL or Token not configured.');
|
||||
}
|
||||
|
||||
$apiUrl = rtrim($this->apiProvider->api_url, '/');
|
||||
$token = $this->apiProvider->token;
|
||||
$taskUUID = (string) Str::uuid();
|
||||
|
||||
try {
|
||||
$response = Http::withHeaders([
|
||||
'Authorization' => 'Bearer ' . $token,
|
||||
'Accept' => 'application/json',
|
||||
])->attach(
|
||||
'image', file_get_contents($imagePath), basename($imagePath)
|
||||
)->post($apiUrl, [
|
||||
'taskType' => 'imageUpload',
|
||||
'taskUUID' => $taskUUID,
|
||||
]);
|
||||
|
||||
$response->throw();
|
||||
$this->logInfo('Image uploaded successfully to RunwareAI.', ['task_uuid' => $taskUUID, 'response' => $response->json()]);
|
||||
return $response->json();
|
||||
} catch (\Exception $e) {
|
||||
$this->logError('Image upload to RunwareAI failed.', ['error' => $e->getMessage(), 'image_path' => $imagePath]);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function styleChangeRequest(string $prompt, string $seedImageUUID, ?string $parameters = null): array
|
||||
{
|
||||
$this->logInfo('Attempting style change request to RunwareAI.', ['prompt' => $prompt, 'seed_image_uuid' => $seedImageUUID]);
|
||||
if (!$this->apiProvider->api_url || !$this->apiProvider->token) {
|
||||
$this->logError('RunwareAI API URL or Token not configured for style change.', ['provider_name' => $this->apiProvider->name]);
|
||||
throw new \Exception('RunwareAI API URL or Token not configured.');
|
||||
}
|
||||
|
||||
$apiUrl = rtrim($this->apiProvider->api_url, '/');
|
||||
$token = $this->apiProvider->token;
|
||||
$taskUUID = (string) Str::uuid();
|
||||
|
||||
$data = [
|
||||
'taskType' => 'imageInference',
|
||||
'taskUUID' => $taskUUID,
|
||||
'positivePrompt' => $prompt,
|
||||
'seedImage' => $seedImageUUID,
|
||||
'outputType' => 'base64Data',
|
||||
];
|
||||
|
||||
$decodedParameters = json_decode($parameters, true) ?? [];
|
||||
foreach ($decodedParameters as $key => $value) {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Http::withHeaders([
|
||||
'Authorization' => 'Bearer ' . $token,
|
||||
'Accept' => 'application/json',
|
||||
])->post($apiUrl, $data);
|
||||
|
||||
$response->throw();
|
||||
$this->logInfo('Style change request successful to RunwareAI.', ['task_uuid' => $taskUUID, 'response' => $response->json()]);
|
||||
return $response->json();
|
||||
} catch (\Exception $e) {
|
||||
$this->logError('Style change request to RunwareAI failed.', ['error' => $e->getMessage(), 'task_uuid' => $taskUUID]);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user