new deployer command

This commit is contained in:
Mark Gregory
2026-09-16 12:28:01 +01:00
parent 5d58e35275
commit 856038c762
13 changed files with 246 additions and 197 deletions
@@ -26,40 +26,37 @@ class DeleteOpenAiFilesCommand extends Command
return self::FAILURE;
}
$service = new OpenAiFileService((string) $setting->api_key);
try {
if ((bool) $this->option('dry-run')) {
$files = $service->listFiles();
$this->info('Found ' . count($files) . ' OpenAI API file(s).');
foreach ($files as $file) {
$this->line(sprintf(
'- %s %s',
(string) ($file['id'] ?? 'unknown'),
(string) ($file['filename'] ?? 'unnamed'),
));
}
return self::SUCCESS;
}
$result = $service->deleteAllFiles();
$this->info("Listed: {$result['listed']}");
$this->info("Deleted: {$result['deleted']}");
$this->info("Failed: {$result['failed']}");
foreach ($result['failures'] as $failure) {
$this->error($failure['file_id'] . ': ' . $failure['error']);
}
return $result['failed'] === 0 ? self::SUCCESS : self::FAILURE;
return $this->executeFor(new OpenAiFileService((string) $setting->api_key));
} catch (Throwable $exception) {
$this->error($exception->getMessage());
return self::FAILURE;
}
}
private function executeFor(OpenAiFileService $service): int
{
if ((bool) $this->option('dry-run')) {
$files = $service->listFiles();
$this->info('Found ' . count($files) . ' OpenAI API file(s).');
foreach ($files as $file) {
$this->line(sprintf('- %s %s', (string) ($file['id'] ?? 'unknown'), (string) ($file['filename'] ?? 'unnamed')));
}
return self::SUCCESS;
}
$result = $service->deleteAllFiles();
$this->info("Listed: {$result['listed']}");
$this->info("Deleted: {$result['deleted']}");
$this->info("Failed: {$result['failed']}");
foreach ($result['failures'] as $failure) {
$this->error($failure['file_id'] . ': ' . $failure['error']);
}
return $result['failed'] === 0 ? self::SUCCESS : self::FAILURE;
}
}
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Modules\ChatGPT\Exceptions;
use RuntimeException;
final class OpenAiFileException extends RuntimeException {}
@@ -4,7 +4,7 @@ namespace Modules\ChatGPT\Services;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
use RuntimeException;
use Modules\ChatGPT\Exceptions\OpenAiFileException;
class OpenAiFileService
{
@@ -33,7 +33,7 @@ class OpenAiFileService
->get(self::BASE_URL . '/files', $query);
if ($response->failed()) {
throw new RuntimeException('OpenAI file list request failed: ' . $response->body());
throw new OpenAiFileException('OpenAI file list request failed: ' . $response->body());
}
$payload = $response->json();
@@ -63,7 +63,7 @@ class OpenAiFileService
->delete(self::BASE_URL . '/files/' . rawurlencode($fileId));
if ($response->failed()) {
throw new RuntimeException("OpenAI file delete request failed for {$fileId}: " . $response->body());
throw new OpenAiFileException("OpenAI file delete request failed for {$fileId}: " . $response->body());
}
return $response->json() ?? [];
@@ -90,7 +90,7 @@ class OpenAiFileService
try {
$this->deleteFile($fileId);
$deleted++;
} catch (RuntimeException $exception) {
} catch (OpenAiFileException $exception) {
$failures[] = [
'file_id' => $fileId,
'error' => $exception->getMessage(),