Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
6e5ad0c1
Unverified
Commit
6e5ad0c1
authored
Sep 22, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fetching image thumbnails from subfolders
parent
c00db947
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
8 deletions
+61
-8
Imagy.php
Modules/Media/Image/Imagy.php
+27
-5
FileTest.php
Modules/Media/Tests/FileTest.php
+1
-1
ImagyTest.php
Modules/Media/Tests/ImagyTest.php
+33
-2
No files found.
Modules/Media/Image/Imagy.php
View file @
6e5ad0c1
...
...
@@ -93,7 +93,7 @@ class Imagy
return
(
new
MediaPath
(
$originalImage
))
->
getRelativeUrl
();
}
$path
=
config
(
'asgard.media.config.files-path'
)
.
$this
->
newFilename
(
$originalImage
,
$thumbnail
);
$path
=
$this
->
getFilenameFor
(
$originalImage
,
$thumbnail
);
return
(
new
MediaPath
(
$path
))
->
getUrl
();
}
...
...
@@ -245,16 +245,38 @@ class Imagy
return
$path
;
}
private
function
getFilenameFor
(
MediaPath
$path
,
Thumbnail
$thumbnail
)
/**
* @param MediaPath $path
* @param Thumbnail|string $thumbnail
* @return string
*/
private
function
getFilenameFor
(
MediaPath
$path
,
$thumbnail
)
{
$filenameWithoutPrefix
=
str_replace
(
config
(
'asgard.media.config.files-path'
),
''
,
$path
->
getRelativeUrl
());
if
(
$thumbnail
instanceof
Thumbnail
)
{
$thumbnail
=
$thumbnail
->
name
();
}
$filenameWithoutPrefix
=
$this
->
removeConfigPrefix
(
$path
->
getRelativeUrl
());
$filename
=
substr
(
strrchr
(
$filenameWithoutPrefix
,
'/'
),
1
);
$folders
=
str_replace
(
$filename
,
''
,
$filenameWithoutPrefix
);
if
(
$filename
===
false
)
{
return
config
(
'asgard.media.config.files-path'
)
.
$this
->
newFilename
(
$path
,
$thumbnail
->
name
()
);
return
config
(
'asgard.media.config.files-path'
)
.
$this
->
newFilename
(
$path
,
$thumbnail
);
}
return
config
(
'asgard.media.config.files-path'
)
.
$folders
.
$this
->
newFilename
(
$path
,
$thumbnail
->
name
());
return
config
(
'asgard.media.config.files-path'
)
.
$folders
.
$this
->
newFilename
(
$path
,
$thumbnail
);
}
/**
* @param string $path
* @return string
*/
private
function
removeConfigPrefix
(
string
$path
)
:
string
{
$configAssetPath
=
config
(
'asgard.media.config.files-path'
);
return
str_replace
([
$configAssetPath
,
ltrim
(
$configAssetPath
,
'/'
)
],
''
,
$path
);
}
}
Modules/Media/Tests/FileTest.php
View file @
6e5ad0c1
...
...
@@ -70,7 +70,7 @@ class FileTest extends MediaTestCase
{
$file
=
$this
->
createFile
(
'my/file/name.jpg'
);
$this
->
assertEquals
(
'http://localhost/name_smallThumb.jpg'
,
$file
->
getThumbnail
(
'smallThumb'
));
$this
->
assertEquals
(
'http://localhost/
my/file/
name_smallThumb.jpg'
,
$file
->
getThumbnail
(
'smallThumb'
));
}
/** @test */
...
...
Modules/Media/Tests/ImagyTest.php
View file @
6e5ad0c1
...
...
@@ -8,6 +8,8 @@ use Illuminate\Support\Facades\App;
use
Modules\Media\Image\Imagy
;
use
Modules\Media\Image\Intervention\InterventionFactory
;
use
Modules\Media\Image\ThumbnailManager
;
use
Modules\Media\Repositories\FolderRepository
;
use
Modules\Media\Services\FileService
;
use
Modules\Media\ValueObjects\MediaPath
;
class
ImagyTest
extends
MediaTestCase
...
...
@@ -36,6 +38,7 @@ class ImagyTest extends MediaTestCase
public
function
setUp
()
{
parent
::
setUp
();
$this
->
app
[
'config'
]
->
set
(
'asgard.media.config.files-path'
,
'/assets/media/'
);
$this
->
config
=
App
::
make
(
Repository
::
class
);
$this
->
finder
=
App
::
make
(
Filesystem
::
class
);
$this
->
imagy
=
new
Imagy
(
new
InterventionFactory
(),
app
(
ThumbnailManager
::
class
),
$this
->
config
);
...
...
@@ -49,6 +52,9 @@ class ImagyTest extends MediaTestCase
{
$this
->
finder
->
delete
(
"
{
$this
->
testbenchPublicPath
}
google-map.png"
);
$this
->
finder
->
delete
(
"
{
$this
->
testbenchPublicPath
}
google-map_smallThumb.png"
);
if
(
$this
->
app
[
'files'
]
->
isDirectory
(
public_path
(
'assets'
))
===
true
)
{
$this
->
app
[
'files'
]
->
deleteDirectory
(
public_path
(
'assets'
));
}
}
public
function
it_should_create_a_file
()
...
...
@@ -70,13 +76,38 @@ class ImagyTest extends MediaTestCase
/** @test */
public
function
it_should_return_thumbnail_path
()
{
$
path
=
$this
->
imagy
->
getThumbnail
(
"
{
$this
->
mediaPath
}
google-map.png"
,
'smallThumb'
);
$
this
->
resetDatabase
(
);
$
expected
=
config
(
'app.url'
)
.
DIRECTORY_SEPARATOR
.
config
(
'asgard.media.config.files-path'
)
.
'google-map_smallThumb.png'
;
$
file
=
\Illuminate\Http\UploadedFile
::
fake
()
->
image
(
'my-file.jpg'
)
;
$file
=
app
(
FileService
::
class
)
->
store
(
$file
);
$expected
=
config
(
'app.url'
)
.
config
(
'asgard.media.config.files-path'
)
.
'my-file_smallThumb.jpg'
;
$path
=
$this
->
imagy
->
getThumbnail
(
$file
->
path
,
'smallThumb'
);
$this
->
assertTrue
(
$this
->
app
[
'files'
]
->
exists
(
public_path
(
'assets/media/my-file.jpg'
)));
$this
->
assertEquals
(
$expected
,
$path
);
}
/** @test */
public
function
it_should_return_thumbnail_path_to_sub_folders
()
{
$this
->
resetDatabase
();
app
(
FolderRepository
::
class
)
->
create
([
'name'
=>
'My Folder'
,
'parent_id'
=>
0
]);
$file
=
\Illuminate\Http\UploadedFile
::
fake
()
->
image
(
'my-file.jpg'
);
$file
=
app
(
FileService
::
class
)
->
store
(
$file
,
1
);
$this
->
assertTrue
(
$this
->
app
[
'files'
]
->
exists
(
public_path
(
'assets/media/my-folder/my-file.jpg'
)));
$smallThumbPath
=
$this
->
imagy
->
getThumbnail
(
$file
->
path
,
'smallThumb'
);
$expected
=
config
(
'app.url'
)
.
config
(
'asgard.media.config.files-path'
)
.
'my-folder/my-file_smallThumb.jpg'
;
$this
->
assertEquals
(
$expected
,
$smallThumbPath
);
}
/** @test */
public
function
it_should_return_same_path_for_non_images
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment