Deploy Ladill Hosting / deploy (push) Failing after 17s
Shared web hosting extracted from the platform monolith, with CI deploy to /var/www/ladill-hosting matching Bird/Domains/Email. Co-authored-by: Cursor <cursoragent@cursor.com>
96 lines
3.2 KiB
PHP
96 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Mailbox;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
/**
|
|
* Client for the platform Mailbox API (§4). Mail provisioning (Postfix/Dovecot
|
|
* via the mail DB + pools) stays on the platform; the Email app creates/manages
|
|
* mailboxes through here. Mailboxes are scoped to the user (public_id).
|
|
* Summary: {id, address, local_part, domain, quota_mb, status, is_paid, ...}.
|
|
*/
|
|
class MailboxClient
|
|
{
|
|
private function base(): string
|
|
{
|
|
return rtrim((string) config('mailbox.api_url'), '/');
|
|
}
|
|
|
|
private function http()
|
|
{
|
|
return Http::withToken((string) (config('mailbox.api_key') ?? ''))->acceptJson()->timeout(15);
|
|
}
|
|
|
|
/** All mailboxes for the user (optionally scoped to one email domain). */
|
|
public function forUser(string $publicId, ?int $emailDomainId = null): array
|
|
{
|
|
$q = ['user' => $publicId];
|
|
if ($emailDomainId) {
|
|
$q['email_domain_id'] = $emailDomainId;
|
|
}
|
|
|
|
return $this->data($this->http()->get($this->base(), $q));
|
|
}
|
|
|
|
public function show(string $publicId, int $id): array
|
|
{
|
|
return $this->data($this->http()->get($this->base().'/'.$id, ['user' => $publicId]));
|
|
}
|
|
|
|
/**
|
|
* Create a mailbox. The Email app does its own wallet billing (§4-A) before
|
|
* calling and passes is_paid + payment_reference. Returns the mailbox detail.
|
|
*/
|
|
public function create(string $publicId, int $emailDomainId, string $localPart, string $displayName, string $password, ?int $quotaMb = null, bool $isPaid = false, ?string $paymentReference = null): array
|
|
{
|
|
$res = $this->http()->post($this->base(), array_filter([
|
|
'user' => $publicId,
|
|
'email_domain_id' => $emailDomainId,
|
|
'local_part' => $localPart,
|
|
'display_name' => $displayName,
|
|
'password' => $password,
|
|
'quota_mb' => $quotaMb,
|
|
'is_paid' => $isPaid,
|
|
'payment_reference' => $paymentReference,
|
|
], fn ($v) => $v !== null));
|
|
$res->throw();
|
|
|
|
return (array) $res->json('data');
|
|
}
|
|
|
|
public function resetPassword(string $publicId, int $id, string $password): array
|
|
{
|
|
$res = $this->http()->patch($this->base().'/'.$id.'/password', ['user' => $publicId, 'password' => $password]);
|
|
$res->throw();
|
|
|
|
return (array) $res->json('data');
|
|
}
|
|
|
|
/** Change a mailbox's storage plan (quota). Billing is done before this call. */
|
|
public function updateQuota(string $publicId, int $id, int $quotaMb, bool $isPaid = false, ?string $paymentReference = null): array
|
|
{
|
|
$res = $this->http()->patch($this->base().'/'.$id.'/quota', array_filter([
|
|
'user' => $publicId,
|
|
'quota_mb' => $quotaMb,
|
|
'is_paid' => $isPaid,
|
|
'payment_reference' => $paymentReference,
|
|
], fn ($v) => $v !== null));
|
|
$res->throw();
|
|
|
|
return (array) $res->json('data');
|
|
}
|
|
|
|
public function delete(string $publicId, int $id): void
|
|
{
|
|
$this->http()->delete($this->base().'/'.$id, ['user' => $publicId])->throw();
|
|
}
|
|
|
|
private function data($res): array
|
|
{
|
|
$res->throw();
|
|
|
|
return (array) ($res->json('data') ?? $res->json());
|
|
}
|
|
}
|