This commit is contained in:
2023-10-04 13:32:30 +03:00
parent 215d238505
commit 1ca5f4e521
82 changed files with 519 additions and 1889 deletions
+10 -1
View File
@@ -3,18 +3,27 @@
namespace Lucent\File;
use Illuminate\Http\UploadedFile;
use Lucent\Channel\ChannelService;
use Lucent\LucentException;
use Lucent\Record\File;
use Lucent\Record\QueryRecord;
use Lucent\Schema\Schema;
use Lucent\Schema\Type;
class FileService
{
public function __construct()
public function __construct(
public ChannelService $channelService
)
{
}
public function getPath(QueryRecord $file): string
{
return $this->channelService->channel->url. "/storage/".$file->_file->path;
}
/**
* @throws LucentException
*/
+11 -9
View File
@@ -102,7 +102,7 @@ function checkDuplicate(string $schemaName, string $checksum, int $filesize): st
{
$record = DB::table("records")
->where("_sys->schema", $schemaName)
->where("schema", $schemaName)
->where("_file->checksum", $checksum)
->where("_file->size", $filesize)
->first();
@@ -112,22 +112,24 @@ function checkDuplicate(string $schemaName, string $checksum, int $filesize): st
function createThumbnail(Filesystem $disk, string $schemaPath, string $filename, UploadedFile $file): void
{
$thumbDir = storage_path("app/public/thumbs/" . $schemaPath . "/");
if (!file_exists($thumbDir)) {
make_dir_r($thumbDir);
}
try {
$image = ImageManagerStatic::make($file);
} catch (Exception $e) {
logger($e->getMessage());
return;
}
$image->fit(300, 300);
try {
$image->encode('webp', 75);
$disk->put(
"thumbs/" . $schemaPath . "/" . $filename,
$image,
// 'public' // now managed by aws policy
);
$image->encode('webp', 75)->save($thumbDir .$filename);
} catch (Exception $e) {
logger($e->getMessage());
}
}