static
This commit is contained in:
@@ -132,10 +132,10 @@ readonly class AuthService
|
||||
/**
|
||||
* @throws LucentException
|
||||
*/
|
||||
public function updateName(string $userId, string $name): void
|
||||
public function updateName( string $name): void
|
||||
{
|
||||
$name = (new Name($name));
|
||||
$this->userRepo->updateName($userId, $name);
|
||||
$this->userRepo->updateName($this->currentUserId(), $name);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ final class Channel
|
||||
function __construct(
|
||||
public string $name,
|
||||
public string $url,
|
||||
public string $previewTarget,
|
||||
public string $generateCommand,
|
||||
public Collection $schemas,
|
||||
public array $imageFilters,
|
||||
// public Collection $previewTargets,
|
||||
|
||||
@@ -36,6 +36,8 @@ final class ChannelService
|
||||
$channel = new Channel(
|
||||
name: $configArray["name"] ?? "",
|
||||
url: rtrim($configArray["url"] ?? "", "/"),
|
||||
previewTarget: rtrim($configArray["previewTarget"] ?? "", "/"),
|
||||
generateCommand: $configArray["generateCommand"] ?? "",
|
||||
schemas: $schemasCollection,
|
||||
imageFilters: $configArray["imageFilters"] ?? [],
|
||||
);
|
||||
|
||||
@@ -4,23 +4,29 @@ namespace Lucent\Http\Controller;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Lucent\Account\Auth;
|
||||
use Lucent\Account\AuthService;
|
||||
use Lucent\Svelte\Svelte;
|
||||
use Throwable;
|
||||
use function Lucent\Response\fail;
|
||||
use function Lucent\Response\ok;
|
||||
use function Lucent\Svelte\svelte;
|
||||
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
public Svelte $svelte,
|
||||
public AuthService $authService,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public function profile()
|
||||
{
|
||||
return svelte(
|
||||
return $this->svelte->render(
|
||||
layout: "account",
|
||||
view: "profile",
|
||||
title: "Profile",
|
||||
data: []
|
||||
);
|
||||
}
|
||||
|
||||
@@ -28,23 +34,12 @@ class AccountController extends Controller
|
||||
{
|
||||
|
||||
try {
|
||||
(new Auth)->updateName(session("user.id"), $request->input("name"));
|
||||
} catch (\Throwable $th) {
|
||||
$this->authService->updateName($request->input("name"));
|
||||
} catch (Throwable $th) {
|
||||
return fail($th);
|
||||
}
|
||||
|
||||
return ok();
|
||||
}
|
||||
|
||||
public function updateEmail(Request $request)
|
||||
{
|
||||
|
||||
try {
|
||||
(new Auth)->updateEmail(session("user.id"), $request->input("email"));
|
||||
} catch (\Throwable $th) {
|
||||
return fail($th);
|
||||
}
|
||||
|
||||
return ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Http\Controller\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Lucent\Account\AuthService;
|
||||
use Lucent\LucentException;
|
||||
use function Lucent\Response\fail;
|
||||
use function Lucent\Response\ok;
|
||||
use function Lucent\Svelte\svelte;
|
||||
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AuthService $authService,
|
||||
)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function profile(): View
|
||||
{
|
||||
|
||||
|
||||
return svelte(
|
||||
layout: "account",
|
||||
view: "profile",
|
||||
title: "Profile",
|
||||
data: []
|
||||
);
|
||||
}
|
||||
|
||||
public function updateName(Request $request): Response
|
||||
{
|
||||
|
||||
try {
|
||||
$this->authService->updateName(session("user.id"), $request->input("name"));
|
||||
} catch (LucentException $th) {
|
||||
return fail($th);
|
||||
}
|
||||
$request->session()->put("user.name", $request->input("name"));
|
||||
|
||||
return ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Http\Controller;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Lucent\Channel\ChannelService;
|
||||
use Lucent\Svelte\Svelte;
|
||||
use function Lucent\Response\ok;
|
||||
|
||||
class BuildController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
public readonly Svelte $svelte,
|
||||
public readonly ChannelService $channelService,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
exec("cd ".base_path(). " && php8.2 artisan {$this->channelService->channel->generateCommand} > /dev/null 2>&1 & echo $!",$op);
|
||||
$pid = (int)$op[0];
|
||||
return redirect($this->channelService->channel->lucentUrl . "/build-report");
|
||||
}
|
||||
|
||||
public function report(): View
|
||||
{
|
||||
|
||||
return $this->svelte->render(
|
||||
layout: "channel",
|
||||
view: "buildReport",
|
||||
title: "Build Report",
|
||||
);
|
||||
}
|
||||
|
||||
public function reportSource()
|
||||
{
|
||||
return response()->stream(function () {
|
||||
while (true) {
|
||||
$curDate = time();
|
||||
echo 'data: {"time": "' . $curDate . '"}';
|
||||
echo "\n\n";
|
||||
logger( $curDate);
|
||||
|
||||
ob_flush();
|
||||
flush();
|
||||
|
||||
// Break the loop if the client aborted the connection (closed the page)
|
||||
if (connection_aborted()) {break;}
|
||||
sleep(2); // 50ms
|
||||
}
|
||||
}, 200, [
|
||||
'Cache-Control' => 'no-cache',
|
||||
'X-Accel-Buffering' => 'no',
|
||||
'Content-Type' => 'text/event-stream',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Lucent\Account\AccountService;
|
||||
use Lucent\Account\UserRepo;
|
||||
use Lucent\Channel\ChannelService;
|
||||
use Lucent\Query\Query;
|
||||
@@ -16,7 +17,7 @@ class HomeController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly Svelte $svelte,
|
||||
private readonly UserRepo $userRepo,
|
||||
private readonly AccountService $accountService,
|
||||
private readonly Query $query,
|
||||
)
|
||||
{
|
||||
@@ -39,7 +40,7 @@ class HomeController extends Controller
|
||||
$sort = data_get($urlParams, "sort") ?? "-_sys.updatedAt";
|
||||
$filter = data_get($urlParams, "filter") ?? [];
|
||||
$arguments = array_merge([
|
||||
"_sys.status_in" => ["draft", "published"]
|
||||
"status_in" => ["draft", "published"]
|
||||
], $filter);
|
||||
|
||||
$limit = 30;
|
||||
@@ -52,7 +53,7 @@ class HomeController extends Controller
|
||||
->sort($sort)
|
||||
->run();
|
||||
|
||||
$users = $this->userRepo->all();
|
||||
$users = $this->accountService->all();
|
||||
|
||||
return ok([
|
||||
"users" => $users,
|
||||
|
||||
+5
-2
@@ -1,13 +1,13 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Lucent\Http\Controller\Api\AccountController;
|
||||
use Lucent\Http\Controller\AccountController;
|
||||
use Lucent\Http\Controller\AuthController;
|
||||
use Lucent\Http\Controller\BuildController;
|
||||
use Lucent\Http\Controller\FileController;
|
||||
use Lucent\Http\Controller\HomeController;
|
||||
use Lucent\Http\Controller\MemberController;
|
||||
use Lucent\Http\Controller\RecordController;
|
||||
use Lucent\Http\Controller\SchemaController;
|
||||
use Lucent\Revision\RevisionController;
|
||||
|
||||
|
||||
@@ -31,6 +31,9 @@ Route::group([
|
||||
Route::get('/logout', [AuthController::class, 'logout']);
|
||||
Route::get('/profile', [AccountController::class, 'profile']);
|
||||
Route::post('/account/update-name', [AccountController::class, 'updateName']);
|
||||
Route::get('/build-report', [BuildController::class, 'report']);
|
||||
Route::get('/build-report-source', [BuildController::class, 'reportSource']);
|
||||
Route::post('/build', [BuildController::class, 'build']);
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
<?php namespace Lucent\StaticGenerator;
|
||||
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class StaticGenerator
|
||||
{
|
||||
|
||||
public function construct()
|
||||
public function __construct(
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -35,5 +39,13 @@ class StaticGenerator
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public function createRedirect(string $from, string $to, string $title = "Redirecting", string $message = "Redirecting Soon..."): void
|
||||
{
|
||||
$html = view("lucent::redirect", [
|
||||
"to" => $to,
|
||||
"title" => $title,
|
||||
"message" => $message,
|
||||
])->render();
|
||||
$this->save($from, $html);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>{{$title}}</title>
|
||||
<meta http-equiv="refresh" content="0; url='{{$to}}'"/>
|
||||
</head>
|
||||
<body>
|
||||
<p>{{$message}}</p>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user