Add service API for Ladill Mail large attachment uploads.
Deploy Ladill Transfer / deploy (push) Successful in 39s
Deploy Ladill Transfer / deploy (push) Successful in 39s
Webmail can POST /api/v1/transfers with a mailbox address to create share links for files above 25 MB. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Identity;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use RuntimeException;
|
||||
|
||||
/** Resolves a Ladill Transfer user mirror for a mailbox address (webmail integration). */
|
||||
class MailboxUserResolver
|
||||
{
|
||||
public function resolve(string $mailbox): User
|
||||
{
|
||||
$mailbox = strtolower(trim($mailbox));
|
||||
if ($mailbox === '' || ! str_contains($mailbox, '@')) {
|
||||
throw new RuntimeException('Invalid mailbox address.');
|
||||
}
|
||||
|
||||
$existing = User::query()->where('email', $mailbox)->first();
|
||||
if ($existing) {
|
||||
return $existing;
|
||||
}
|
||||
|
||||
$base = rtrim((string) config('identity.api_url'), '/');
|
||||
$key = (string) config('identity.api_key');
|
||||
if ($base === '' || $key === '') {
|
||||
throw new RuntimeException('Identity API is not configured.');
|
||||
}
|
||||
|
||||
$res = Http::withToken($key)
|
||||
->acceptJson()
|
||||
->timeout(10)
|
||||
->get("{$base}/identity/profile", ['mailbox' => $mailbox]);
|
||||
|
||||
if ($res->failed()) {
|
||||
throw new RuntimeException('Could not resolve the Ladill account for this mailbox.');
|
||||
}
|
||||
|
||||
$data = $res->json('data');
|
||||
if (! is_array($data)) {
|
||||
throw new RuntimeException('Could not resolve the Ladill account for this mailbox.');
|
||||
}
|
||||
|
||||
$publicId = trim((string) ($data['public_id'] ?? ''));
|
||||
if ($publicId === '') {
|
||||
throw new RuntimeException('No Ladill account is linked to this mailbox.');
|
||||
}
|
||||
|
||||
return User::updateOrCreate(
|
||||
['public_id' => $publicId],
|
||||
[
|
||||
'name' => trim((string) ($data['name'] ?? '')) ?: $mailbox,
|
||||
'email' => $mailbox,
|
||||
'avatar_url' => ($picture = trim((string) ($data['picture'] ?? ''))) !== '' ? $picture : null,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user