client brief > my images : upload images working

This commit is contained in:
isUnknown 2024-10-09 19:05:37 +02:00
parent 663f841fff
commit 8c19269e48
24 changed files with 164 additions and 108 deletions

View file

@ -18,4 +18,8 @@ Testimage: - file://4xs4UNZhQf3jLvsG
----
Uuid: 6yh1yt2Sk45Y2sOl
Uuid: 6yh1yt2Sk45Y2sOl
----
Clientbriefimages: - file://ihuGLrw5vll0R4j2

View file

@ -1 +1,5 @@
Template: blocks/image
Template: blocks/image
----
Uuid: vHs87W6sM0r43thr

View file

@ -0,0 +1,17 @@
Description: nouvelle description
----
Tags: matériaux & textures
----
Date: 2024-10-09 05:10
----
Uuid: vs4tgLg5q6QFeb43
----
Template: image

View file

@ -1,3 +1,7 @@
Date: 2024-10-09 05:10
----
Description:
----
@ -6,7 +10,7 @@ Tags:
----
Uuid: Ke2XIraa5jlvtOdb
Uuid: Nlkd6hX666PBBYlk
----

View file

@ -1,3 +1,7 @@
Date: 2024-10-09 05:10
----
Description:
----
@ -6,7 +10,7 @@ Tags:
----
Uuid: nqa5cCGHGoWQXulB
Uuid: UkFMsBPXVGpQMmXV
----

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 KiB

View file

@ -1,3 +1,7 @@
Date: 2024-10-09 05:10
----
Description:
----
@ -6,7 +10,7 @@ Tags:
----
Uuid: FWKdZwxSimGOaO2x
Uuid: DknJcJ7YnG29JXUN
----

View file

@ -0,0 +1,17 @@
Date: 2024-10-09 05:10
----
Description:
----
Tags:
----
Uuid: zGisP0BopebPl2ex
----
Template: image

View file

@ -0,0 +1,17 @@
Date: 2024-10-09 05:10
----
Description:
----
Tags:
----
Uuid: 2Nt5Vv2SrGcE1iro
----
Template: image

View file

@ -0,0 +1,17 @@
Date: 2024-10-09 05:10
----
Description:
----
Tags:
----
Uuid: ih7KMM6KjNoQ2umR
----
Template: image

View file

@ -16,12 +16,13 @@ Description: test
Clientbriefimages:
- file://b4Ywx4ProE0Smc0Q
- file://aCuD18YBmLHg6YaS
- file://Ke2XIraa5jlvtOdb
- file://QBax5c69DcENi2rt
- file://nqa5cCGHGoWQXulB
- file://FWKdZwxSimGOaO2x
- file://DknJcJ7YnG29JXUN
- file://Nlkd6hX666PBBYlk
- file://zGisP0BopebPl2ex
- file://ih7KMM6KjNoQ2umR
- file://UkFMsBPXVGpQMmXV
- file://2Nt5Vv2SrGcE1iro
- file://vs4tgLg5q6QFeb43
----

View file

@ -1,13 +0,0 @@
Description:
----
Tags: forme & design, coloris & nuances
----
Uuid: QBax5c69DcENi2rt
----
Template: image

View file

@ -1,13 +0,0 @@
Description: test de description mais
----
Tags: parachèvements
----
Uuid: b4Ywx4ProE0Smc0Q
----
Template: image

View file

@ -4,19 +4,19 @@ return [
'pattern' => 'upload-images.json',
'method' => 'POST',
'action' => function () {
if ($uploads = kirby()->request()->files()) {
if ($uploads = kirby()->request()->files()) {
$pageUri = kirby()->request()->query()->get('pageUri');
$page = page($pageUri);
$page = page($pageUri);
$allFiles = $page->clientBriefImages()->toFiles()->pluck('uuid', ',');
$alerts = [];
$success = '';
$newFiles = [];
$allFiles = [];
foreach ($uploads->get('images') as $upload) {
// check for duplicate
$files = $page->files();
$duplicates = $files->filter(function ($file) use ($upload) {
// get original safename without prefix
$pos = strpos($file->filename(), '_');
$originalSafename = substr($file->filename(), $pos + 1);
@ -26,9 +26,14 @@ return [
});
if ($duplicates->count() > 0) {
$alerts[$upload['name']] = "The file already exists";
$duplicate = $duplicates->first();
if (in_array($duplicate->uuid(), $allFiles)) {
$allFiles[] = $duplicate->uuid();
$alerts[$upload['name']] = "The file already exists, added to the field.";
}
}
try {
$name = crc32($upload['name'].microtime()). '_' . $upload['name'];
$newFile = $page->createFile([
@ -49,19 +54,24 @@ return [
$alerts[$upload['name']] = $e->getMessage();
}
}
$images = array_map(function ($file) {
return [
'url' => $file->url(),
'uuid' => $file->uuid()
];
}, $newFiles);
$newPage = $page->update([
'clientBriefImages' => $allFiles
]);
return compact('images', 'alerts', 'success');
$images = [];
foreach ($newPage->clientBriefImages()->toFiles() as $image) {
$images[] = [
'url' => $image->url(),
'uuid' => (string) $image->uuid(),
'tags' => $image->tags()->split(),
'name' => $image->filename(),
'description' => $image->description()->value(),
];
}
return compact('images', 'alerts');
}
return [