fix paths

This commit is contained in:
2026-05-07 21:18:50 +03:00
parent 639ee895cd
commit 48e32bfdcb
12 changed files with 74 additions and 51 deletions
+2
View File
@@ -10,6 +10,8 @@
let imageSide;
let fileSide;
let fontSize;
console.log({ channel });
if (size == "large") {
imageSide = 256;
fileSide = 32;
+9 -6
View File
@@ -1,7 +1,7 @@
<script>
import Preview from "../files/Preview.svelte";
import {fileurl} from "../files/imageserver"
import {getContext} from "svelte"
import { fileurl } from "../files/imageserver";
import { getContext } from "svelte";
const channel = getContext("channel");
export let record;
@@ -11,10 +11,9 @@
{#if schema.type === "files"}
<div class="record-edit-file-preview">
<div>
<Preview {record} size="large"/>
<Preview {record} size="large" />
</div>
<div class="file-details">
<div class="file-details-item">
<span class="text-muted">Filename</span>
<span>{record._file.path}</span>
@@ -42,9 +41,13 @@
<span>{record._file.checksum}</span>
</div>
<div class="file-details-item">
<a class="button primary" target="_blank" style="display: inline-flex" href="{fileurl(channel,record)}">Download</a>
<a
class="button primary"
target="_blank"
style="display: inline-flex"
href={fileurl(channel, record)}>Download</a
>
</div>
</div>
</div>
{/if}
@@ -2,11 +2,9 @@
import { array_move } from "../../edges/sortEdges";
import Sortable from "../../libs/Sortable.svelte";
import PreviewFile from "../previews/PreviewFile.svelte";
import { getContext } from "svelte";
import FileDialog from "../../dialog/FileDialog.svelte";
import Uploader from "../../files/Uploader.svelte";
const channel = getContext("channel");
export let field;
export let record;
export let value = [];
+5 -3
View File
@@ -34,14 +34,16 @@ final class Channel
private function makeFilesUrl(): string
{
$lucentDisk = config("lucent.disk");
$lucentDisk = config("lucent.public_disk");
return match (config("filesystems.disks.$lucentDisk.driver")) {
"s3" => config("filesystems.disks.$lucentDisk.endpoint") .
"/" .
"/lucent" .
config("filesystems.disks.$lucentDisk.bucket"),
"local" => $this->url .
"/storage" .
"/storage/lucent" .
config("filesystems.disks.$lucentDisk.endpoint"),
default => "",
};
}
+4 -2
View File
@@ -4,6 +4,7 @@ namespace Lucent\Channel;
use Lucent\Channel\Data\UserCommand;
use Lucent\Data\ChannelAuth;
use Lucent\File\FileService;
use Lucent\Primitive\Collection;
use Lucent\Data\Schema;
use Lucent\Schema\SchemaService;
@@ -18,8 +19,9 @@ final class ChannelService
public static function fromConfig(): ChannelService
{
$schemasArray = [];
if (file_exists(schemas_path())) {
$schemasJson = file_get_contents(schemas_path());
$privateDisk = FileService::loadPrivateDisk();
if ($privateDisk->exists(schemas_path())) {
$schemasJson = $privateDisk->get(schemas_path());
$schemasArray = json_decode($schemasJson, true);
}
$schemaService = new SchemaService();
+7 -4
View File
@@ -6,6 +6,7 @@ use DirectoryIterator;
use Illuminate\Console\Command;
use Lucent\Data\Schema;
use Lucent\Schema\SchemaService;
use Lucent\File\FileService;
class CompileSchemas extends Command
{
@@ -13,8 +14,10 @@ class CompileSchemas extends Command
protected $description = "Compiles schemas";
public function handle(SchemaService $schemaService)
{
public function handle(
SchemaService $schemaService,
FileService $fileService,
) {
$configDir = base_path(config("lucent.schemas_path"));
$schemasDirIterator = new DirectoryIterator($configDir);
$schemas = [];
@@ -63,8 +66,8 @@ class CompileSchemas extends Command
mkdir(storage_path("lucent"));
}
file_put_contents(schemas_path(), json_encode($json));
$disk = $fileService->loadPrivateDisk();
$disk->put(schemas_path(), json_encode($json));
$this->info("Lucent Schemas were updated");
}
}
+7 -4
View File
@@ -3,7 +3,7 @@
namespace Lucent\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
use Lucent\File\FileService;
use ZipArchive;
class Export extends Command
@@ -13,7 +13,7 @@ class Export extends Command
protected $description = "Export data and files";
public function handle(): void
public function handle(FileService $fileService): void
{
$db = config("database.connections.pgsql");
$tables = [
@@ -23,7 +23,8 @@ class Export extends Command
"lucent_edges",
];
$exportDir = storage_path("exports");
$disk = $fileService->loadPrivateDisk();
$exportDir = $disk->path("lucent/exports");
if (!is_dir($exportDir)) {
mkdir($exportDir, 0755, true);
}
@@ -55,7 +56,9 @@ class Export extends Command
$this->info("Database dumped.");
// Zip SQL + files
$filesDir = Storage::disk(config("lucent.disk"))->path("files");
$publicDisk = $fileService->loadPublicDisk();
$filesDir = $publicDisk->path("lucent/files");
$zip = new ZipArchive();
if (
+21 -9
View File
@@ -3,7 +3,7 @@
namespace Lucent\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
use Lucent\File\FileService;
use ZipArchive;
class Import extends Command
@@ -12,9 +12,10 @@ class Import extends Command
protected $description = "Import data and files from an export archive";
public function handle(): void
public function handle(FileService $fileService): void
{
$exportDir = storage_path("exports");
$disk = $fileService->loadPrivateDisk();
$exportDir = $disk->path("lucent/exports");
if (!is_dir($exportDir)) {
$this->error("No exports directory found at {$exportDir}");
@@ -34,7 +35,9 @@ class Import extends Command
$chosen = $this->choice("Select an export to import", $choices, 0);
$zipFile = $exportDir . "/" . $chosen;
$this->warn("This will REPLACE all records, revisions, edges, files data and uploaded files.");
$this->warn(
"This will REPLACE all records, revisions, edges, files data and uploaded files.",
);
if (!$this->confirm("Import {$chosen}?", false)) {
$this->info("Aborted.");
@@ -118,16 +121,23 @@ class Import extends Command
$srcFilesDir = $tempDir . "/files";
if (is_dir($srcFilesDir)) {
$disk = Storage::disk(config("lucent.disk"));
$destFilesDir = $disk->path("files");
$publicDisk = $fileService->loadPublicDisk();
$filesDir = $publicDisk->path("lucent");
$destFilesDir = $publicDisk->path("lucent");
// Remove existing files directory
// Remove existing files directory or create it if missing
if (is_dir($destFilesDir)) {
exec("rm -rf " . escapeshellarg($destFilesDir));
} else {
mkdir($destFilesDir, 0755, true);
}
exec(
sprintf("cp -R %s %s", escapeshellarg($srcFilesDir), escapeshellarg($destFilesDir)),
sprintf(
"cp -R %s %s",
escapeshellarg($srcFilesDir),
escapeshellarg($destFilesDir),
),
result_code: $copyCode,
);
@@ -139,7 +149,9 @@ class Import extends Command
$this->info("Files restored.");
} else {
$this->warn("No files directory found in archive — skipping file restore.");
$this->warn(
"No files directory found in archive — skipping file restore.",
);
}
$this->cleanup($tempDir);
+1 -7
View File
@@ -2,17 +2,11 @@
namespace Lucent\Commands;
use DirectoryIterator;
use Exception;
use Illuminate\Console\Command;
use Intervention\Image\ImageManager;
use Lucent\Channel\ChannelService;
use Lucent\File\FileRepo;
use Lucent\File\FileService;
use Lucent\Query\Query;
use Lucent\Schema\FilesSchema;
use Lucent\Schema\Schema;
use Lucent\Schema\Type;
class RebuildThumbnails extends Command
{
@@ -31,7 +25,7 @@ class RebuildThumbnails extends Command
{
$this->info("Rebuilding thumbnails ");
$files = FileRepo::query()->get();
$disk = $this->fileService->loadDisk();
$disk = $this->fileService->loadPublicDisk();
foreach ($files as $file) {
try {
$this->fileService->createTemplates($disk, $file->path);
+3 -2
View File
@@ -4,12 +4,13 @@ return [
"env" => env("LUCENT_ENV", "production"),
// lucent or lunar
"auth" => env("LUCENT_AUTH", "lucent"),
"disk" => env("LUCENT_DISK", "public"),
"private_disk" => env("LUCENT_PRIVATE_DISK", "local"),
"public_disk" => env("LUCENT_PUBLIC_DISK", "public"),
"schemas_path" => env("LUCENT_SCHEMAS_PATH", "resources/lucent/schemas"),
"database" => env("LUCENT_DB_CONNECTION", env("DB_CONNECTION", "sqlite")),
"name" => env("LUCENT_NAME", "Lucent"),
"url" => env("LUCENT_URL", env("APP_URL")),
"previewTarget" => env("LUCENT_PREVIEW_TARGET", "previewTarget"),
"preview_target" => env("LUCENT_PREVIEW_TARGET", "previewTarget"),
/*
* Make available laravel artisan commands for admin users
* example:
+14 -11
View File
@@ -4,16 +4,13 @@ namespace Lucent\File;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Http\UploadedFile;
use Illuminate\Log\Logger;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Intervention\Image\ImageManager;
use Lucent\Channel\ChannelService;
use Lucent\Database\Database;
use Lucent\Id\Id;
use Lucent\LucentException;
use Lucent\Data\File as DataFile;
use Lucent\Record\QueryRecord;
use Spatie\ImageOptimizer\OptimizerChainFactory;
class FileService
@@ -21,7 +18,6 @@ class FileService
public function __construct(
public ChannelService $channelService,
public ImageManager $imageManager,
public Logger $logger,
) {}
public function createFromUrl(
@@ -58,10 +54,10 @@ class FileService
$checksum = sha1_file($file);
$disk = $this->loadDisk();
$disk = $this->loadPublicDisk();
$path = "files/" . $recordId . "/" . $filename;
$res = $disk->put(
$path,
"lucent/" . $path,
file_get_contents($file),
// 'public' // now managed by aws policy
);
@@ -117,22 +113,29 @@ class FileService
return in_array($mimetype, $imageMimes);
}
public function loadDisk(): Filesystem
public static function loadPublicDisk(): Filesystem
{
return Storage::disk(config("lucent.disk"));
return Storage::disk(config("lucent.public_disk"));
}
public static function loadPrivateDisk(): Filesystem
{
return Storage::disk(config("lucent.private_disk"));
}
public function createTemplates(Filesystem $disk, string $path): void
{
$originalImage = $this->imageManager->make($disk->get($path));
$originalImage = $this->imageManager->make(
$this->loadPublicDisk()->get("lucent/" . $path),
);
foreach (config("lucent.imageFilters") as $preset => $filterClass) {
$imageClone = clone $originalImage;
$image = $imageClone->filter(new $filterClass());
$templateUri = "/templates/" . $preset . "/" . $path;
$templateUri = "lucent/templates/" . $preset . "/" . $path;
$disk->put($templateUri, $image->encode("webp", 75));
}
$thumbDir = "thumbs/" . $path;
$thumbDir = "lucent/thumbs/" . $path;
$image = $originalImage->fit(300, 300);
$disk->put($thumbDir, $image->encode("webp", 75));
+1 -1
View File
@@ -39,7 +39,7 @@ if (!function_exists("make_dir_r")) {
if (!function_exists("schemas_path")) {
function schemas_path(): string
{
return storage_path("lucent/lucent.schemas.json");
return "lucent/lucent.schemas.json";
}
}