Skip to content

Commit

Permalink
fix issue with directory closes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
milewski committed Oct 8, 2019
1 parent 0f57b96 commit 0c57d2c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/Filepond.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function withoutDoka(): self
public function disk(string $disk, string $directory = null)
{
$this->disk = $disk;
$this->directory = $directory;
$this->directory = trim(rtrim($directory, '/'), '/');

return $this;
}
Expand Down Expand Up @@ -208,7 +208,7 @@ protected function fillAttributeFromRequest(NovaRequest $request, $requestAttrib

if ($this->multiple === false) {

$serverId = $request->input($requestAttribute);
$serverId = static::getPathFromServerId($request->input($requestAttribute));

/**
* If no changes were made the first image should match the given serverId
Expand All @@ -221,7 +221,7 @@ protected function fillAttributeFromRequest(NovaRequest $request, $requestAttrib

$this->removeImages($currentImages);

$file = new File(static::getPathFromServerId($serverId));
$file = new File($serverId);

$model->setAttribute($attribute, $this->moveFile($file));

Expand All @@ -232,7 +232,9 @@ protected function fillAttributeFromRequest(NovaRequest $request, $requestAttrib
/**
* If it`s a multiple files request
*/
$files = collect(explode(',', $request->input($requestAttribute)));
$files = collect(explode(',', $request->input($requestAttribute)))->map(function ($file) {
return static::getPathFromServerId($file);
});

$toKeep = $files->intersect($currentImages); // files that exist on the request and on the model
$toAppend = $files->diff($currentImages); // files that exist only on the request
Expand All @@ -242,7 +244,7 @@ protected function fillAttributeFromRequest(NovaRequest $request, $requestAttrib

foreach ($toAppend as $serverId) {

$file = new File(static::getPathFromServerId($serverId));
$file = new File($serverId);

$toKeep->push($this->moveFile($file));

Expand All @@ -257,8 +259,7 @@ private function moveFile(File $file): string

$name = $this->storeAsCallback ? call_user_func($this->storeAsCallback, $file) : null;

return $file->move(Storage::disk($this->disk)->path($this->directory), $name)
->getBasename();
return $this->directory . '/' . $file->move(Storage::disk($this->disk)->path($this->directory), $name)->getBasename();

}

Expand Down Expand Up @@ -288,9 +289,7 @@ protected function resolveAttribute($resource, $attribute): Collection

return collect($value)->map(function ($value) {
return [
'source' => $this->getServerIdFromPath(
trim(rtrim($this->directory, '/') . '/' . $value, '/')
),
'source' => $this->getServerIdFromPath($value),
'options' => [
'type' => 'local'
]
Expand Down

0 comments on commit 0c57d2c

Please sign in to comment.