Skip to content

Commit

Permalink
[WIP] v9 (spatie#2098)
Browse files Browse the repository at this point in the history
* wip

* wip

* wip

* wip

* fix case

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* update javascript docs

* update javascript docs

* wip JS components documentation

* wip javascript components documentation

* wip

* wip

* wip

* Update handling-uploads-with-vue-or-react.md

* Fix styling

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Fix styling

* remove translations

* wip

* wip

* wip

* Fix styling

* update props

* improve conversions (spatie#2101)

* wip

* Fix styling

* wip

* wip

* Fix styling

* wip

* wip

* Fix styling

* wip

* wip

* wip

* wip

* wip

* wip

* Fix styling

* wip

Co-authored-by: freekmurze <[email protected]>

* update

* document maxSizeForPreviewInBytes

* wip

* wip

* Rework frontend docs

* Rework frontend docs

* Restore data code blocks

* wip

* wip

* Update general upload guide

* Words

* Words

* Doc updates

* wip

* Fix styling

* wip

* wip

* wip

* use v9 links

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* v9

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* correct year

* wip

* docs: css installation

* wip

* Custom CSS

* Custom CSS

* Custom CSS

* Custom CSS

* Custom CSS

* docs: update JS UI components

* wip js docs

* wip

* wip

* update validation property name

* update for Vue 3

* updates for Vue 3

* Set height attribute (spatie#2132)

* update naming

* typo

* wip

* reorder sections

* capitalize CSS

* wip

* wip

* wip

* add jsonSerialize to MediaCollection

* update slot usage for Vue 3

* fix getting old values

* Fix styling

* fix last commit

* File namer#1784 (spatie#2114)

* support a custom file namer for responsive images

* Fix styling

* apply code review suggestions

* let conversions use a new file namer class

* add documentation

* cleanup last conversion file namer parts

* apply code review suggestions

* split up conversion & responsive file namer

* remove get prefix on FileNamer methods

* Update naming-generated-files.md

* Update naming-generated-files.md

Co-authored-by: Nielsvanpach <[email protected]>
Co-authored-by: Freek Van der Herten <[email protected]>

* wip

* wip

* update docs with new endpoints

* wip

* wip

* drop laravel 6

* wip

* update vapor config

* wip

* update upload endpoint

* update paths

* allow PHP 8

* wip

* remove notice

* add enable_vapor_uploads option + restructure config file

* wip

* wip

* wip

* find last occurence of starting characters (spatie#2140)

* find last occurence of starting characters

if a filename ends with _, the responsive image will have four underscores in its name. We used to trim at the first occurence, so the collection name starts with an underscore. This way responsive image will not get rendered as expected. Now, we will trim on the last occurence and the collection name will not start with an underscore in this case.

* fix test case

Co-authored-by: Adriaan <[email protected]>
Co-authored-by: freekmurze <[email protected]>
Co-authored-by: Sebastian De Deyne <[email protected]>
Co-authored-by: Willem Van Bockstal <[email protected]>
Co-authored-by: Robin Cramer <[email protected]>
Co-authored-by: AdrianMrn <[email protected]>
Co-authored-by: Niels Vanpachtenbeke <[email protected]>
Co-authored-by: Nielsvanpach <[email protected]>
  • Loading branch information
9 people authored Oct 30, 2020
1 parent 9dc9906 commit 0730227
Show file tree
Hide file tree
Showing 81 changed files with 2,989 additions and 496 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: Fix style
uses: docker://oskarstark/php-cs-fixer-ga
Expand Down
14 changes: 1 addition & 13 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ jobs:
fail-fast: false
matrix:
php: [7.4]
laravel: [8.*, 7.*, 6.*]
laravel: [8.*, 7.*]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 8.*
testbench: 6.*
- laravel: 7.*
testbench: 5.*
- laravel: 6.*
testbench: 4.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

Expand Down Expand Up @@ -63,13 +61,3 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
AWS_BUCKET: ${{ secrets.AWS_BUCKET }}

- name: Send Slack notification
uses: 8398a7/action-slack@v2
if: failure()
with:
status: ${{ job.status }}
author_name: ${{ github.actor }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to `laravel-medialibrary` will be documented in this file

## 9.0.0 - Unreleased

- names of the generated conversions will now be put in a dedicated `generated_conversions` on media
- add support for media library pro
- responsive image files can now be named using the `file_namer` key in the `media-library` config file (#2114)

## 8.10.1 - 2020-10-05

- add `queue_conversions_by_default` to config file
Expand Down Expand Up @@ -86,6 +92,7 @@ All notable changes to `laravel-medialibrary` will be documented in this file

- improve handling of file names with special characters (#1937)


## 8.3.0 - 2020-06-11

- added `Spatie\MediaLibrary\MediaCollections\Models\Collections\MediaCollection`
Expand Down
6 changes: 6 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Because there are many breaking changes an upgrade is not that easy. There are many edge cases this guide does not cover. We accept PRs to improve this guide.

## From v8 to v9

- add a column `generated_conversions` to the `media` table. If you are using Media Library Pro you used copy the values you now have in the `generated_conversions` key of the `custom_properties` column to `generated_conversions`
- rename `conversion_file_namer` key in the `media-library` config to `file_namer`. This will support both the conversions and responsive images from now on. More info [in our docs](https://spatie.be/docs/laravel-medialibrary/v9/advanced-usage/naming-generated-files).
- in several releases of v8 config options were added. We recommend going over your config file in `config/media-library.php` and add any options that are present in the default config file that ships with this package.

## From v7 to v8

- internally the media library has been restructured and nearly all namespaces have changed. Class names remained the same. In your application code hunt to any usages of classes that start with `Spatie\MediaLibrary`. Take a look in the source code of medialibrary what the new namespace of the class is and use that.
Expand Down
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
}
],
"require": {
"php": "^7.4",
"php": "^7.4|^8.0",
"ext-exif": "*",
"ext-fileinfo": "*",
"ext-json": "*",
"illuminate/bus": "^6.18|^7.0|^8.0",
"illuminate/console": "^6.18|^7.0|^8.0",
"illuminate/database": "^6.18|^7.0|^8.0",
"illuminate/pipeline": "^6.18|^7.0|^8.0",
"illuminate/support": "^6.18|^7.0|^8.0",
"illuminate/bus": "^7.0|^8.0",
"illuminate/console": "^7.0|^8.0",
"illuminate/database": "^7.0|^8.0",
"illuminate/pipeline": "^7.0|^8.0",
"illuminate/support": "^7.0|^8.0",
"league/flysystem": "^1.0.64",
"maennchen/zipstream-php": "^1.0|^2.0",
"spatie/image": "^1.4.0",
Expand All @@ -44,7 +45,7 @@
"guzzlehttp/guzzle": "^6.3|^7.0",
"league/flysystem-aws-s3-v3": "^1.0.23",
"mockery/mockery": "^1.3",
"orchestra/testbench": "^4.0|^5.0|^6.0",
"orchestra/testbench": "^5.0|^6.0",
"php-ffmpeg/php-ffmpeg": "^0.16.0",
"phpunit/phpunit": "^9.1",
"spatie/pdf-to-image": "^2.0",
Expand Down
119 changes: 64 additions & 55 deletions config/media-library.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,60 +30,15 @@
*/
'media_model' => Spatie\MediaLibrary\MediaCollections\Models\Media::class,

'remote' => [
/*
* Any extra headers that should be included when uploading media to
* a remote disk. Even though supported headers may vary between
* different drivers, a sensible default has been provided.
*
* Supported by S3: CacheControl, Expires, StorageClass,
* ServerSideEncryption, Metadata, ACL, ContentEncoding
*/
'extra_headers' => [
'CacheControl' => 'max-age=604800',
],
],

'responsive_images' => [

/*
* This class is responsible for calculating the target widths of the responsive
* images. By default we optimize for filesize and create variations that each are 20%
* smaller than the previous one. More info in the documentation.
*
* https://docs.spatie.be/laravel-medialibrary/v8/advanced-usage/generating-responsive-images
*/
'width_calculator' => Spatie\MediaLibrary\ResponsiveImages\WidthCalculator\FileSizeOptimizedWidthCalculator::class,

/*
* By default rendering media to a responsive image will add some javascript and a tiny placeholder.
* This ensures that the browser can already determine the correct layout.
*/
'use_tiny_placeholders' => true,

/*
* This class will generate the tiny placeholder used for progressive image loading. By default
* the media library will use a tiny blurred jpg image.
*/
'tiny_placeholder_generator' => Spatie\MediaLibrary\ResponsiveImages\TinyPlaceholderGenerator\Blurred::class,
],

/*
* When converting Media instances to response the media library will add
* a `loading` attribute to the `img` tag. Here you can set the default
* value of that attribute.
*
* Possible values: 'lazy', 'eager', 'auto' or null if you don't want to set any loading instruction.
*
* More info: https://css-tricks.com/native-lazy-loading/
* The fully qualified class name of the model used for temporary uploads.
*/
'default_loading_attribute_value' => null,
'temporary_upload_model' => Spatie\MediaLibraryPro\Models\TemporaryUpload::class,

/*
* This is the class that is responsible for naming conversion files. By default,
* it will use the filename of the original and concatenate the conversion name to it.
* This is the class that is responsible for naming generated files.
*/
'conversion_file_namer' => Spatie\MediaLibrary\Conversions\DefaultConversionFileNamer::class,
'file_namer' => Spatie\MediaLibrary\Support\FileNamer\DefaultFileNamer::class,

/*
* The class that contains the strategy for determining a media file's path.
Expand Down Expand Up @@ -140,6 +95,12 @@
Spatie\MediaLibrary\Conversions\ImageGenerators\Video::class,
],

/*
* The path where to store temporary files while performing image conversions.
* If set to null, storage_path('media-library/temp') will be used.
*/
'temporary_directory_path' => null,

/*
* The engine that should perform the image conversions.
* Should be either `gd` or `imagick`.
Expand All @@ -154,12 +115,6 @@
'ffmpeg_path' => env('FFMPEG_PATH', '/usr/bin/ffmpeg'),
'ffprobe_path' => env('FFPROBE_PATH', '/usr/bin/ffprobe'),

/*
* The path where to store temporary files while performing image conversions.
* If set to null, storage_path('media-library/temp') will be used.
*/
'temporary_directory_path' => null,

/*
* Here you can override the class names of the jobs used by this package. Make sure
* your custom jobs extend the ones provided by the package.
Expand All @@ -176,4 +131,58 @@
*/
'media_downloader' => Spatie\MediaLibrary\Downloaders\DefaultDownloader::class,

'remote' => [
/*
* Any extra headers that should be included when uploading media to
* a remote disk. Even though supported headers may vary between
* different drivers, a sensible default has been provided.
*
* Supported by S3: CacheControl, Expires, StorageClass,
* ServerSideEncryption, Metadata, ACL, ContentEncoding
*/
'extra_headers' => [
'CacheControl' => 'max-age=604800',
],
],

'responsive_images' => [
/*
* This class is responsible for calculating the target widths of the responsive
* images. By default we optimize for filesize and create variations that each are 20%
* smaller than the previous one. More info in the documentation.
*
* https://docs.spatie.be/laravel-medialibrary/v8/advanced-usage/generating-responsive-images
*/
'width_calculator' => Spatie\MediaLibrary\ResponsiveImages\WidthCalculator\FileSizeOptimizedWidthCalculator::class,

/*
* By default rendering media to a responsive image will add some javascript and a tiny placeholder.
* This ensures that the browser can already determine the correct layout.
*/
'use_tiny_placeholders' => true,

/*
* This class will generate the tiny placeholder used for progressive image loading. By default
* the media library will use a tiny blurred jpg image.
*/
'tiny_placeholder_generator' => Spatie\MediaLibrary\ResponsiveImages\TinyPlaceholderGenerator\Blurred::class,
],

/*
* When enabling this option, a route will be registered that will enable
* the Media Library Pro Vue and React components to move uploaded files
* in a S3 bucket to their right place.
*/
'enable_vapor_uploads' => env('ENABLE_MEDIA_LIBRARY_VAPOR_UPLOADS', true),

/*
* When converting Media instances to response the media library will add
* a `loading` attribute to the `img` tag. Here you can set the default
* value of that attribute.
*
* Possible values: 'lazy', 'eager', 'auto' or null if you don't want to set any loading instruction.
*
* More info: https://css-tricks.com/native-lazy-loading/
*/
'default_loading_attribute_value' => null,
];
1 change: 1 addition & 0 deletions database/migrations/create_media_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CreateMediaTable extends Migration
$table->unsignedBigInteger('size');
$table->json('manipulations');
$table->json('custom_properties');
$table->json('generated_conversions');
$table->json('responsive_images');
$table->unsignedInteger('order_column')->nullable();

Expand Down
4 changes: 2 additions & 2 deletions docs/_index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: v8
title: v9
slogan: Associate files with Eloquent models.
githubUrl: https://github.com/spatie/laravel-medialibrary
branch: master
branch: v9
---
55 changes: 55 additions & 0 deletions docs/advanced-usage/naming-generated-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
title: Naming generated files
weight: 11
---

### Naming conversion files

By default, all conversion files will be named in this format:

```
{original-file-name-without-extension}-{name-of-the-conversion}.{extension}
```

Should you want to name your conversion file using another format,
then you can specify the class name of your own `FileNamer` in the `file_namer` key
of the `media-library.php` config file.

The only requirements is that your class extends `Spatie\MediaLibrary\Support\FileNamer`.
In your class you should implement 2 methods:
1. `conversionFileName` should return the media file name combined with the conversion name
2. `responsiveFileName` should return the media file name

Here is the implementation of `Spatie\MediaLibrary\Support\FileNamer\DefaultFileNamer`

```php
namespace Spatie\MediaLibrary\Support\FileNamer;

use Spatie\MediaLibrary\Conversions\Conversion;

class DefaultFileNamer extends FileNamer
{
public function conversionFileName(string $fileName, Conversion $conversion): string
{
$strippedFileName = pathinfo($fileName, PATHINFO_FILENAME);

return "{$strippedFileName}-{$conversion->getName()}";
}

public function responsiveFileName(string $fileName): string
{
return pathinfo($fileName, PATHINFO_FILENAME);
}
}
```

### Naming responsive image files

By default, all responsive image files will be named in this format:

```
{original-file-name-without-extension}___{name-of-the-conversion}_{width}_{height}.{extension}
```

Just like the conversion file names, you can use another format for naming your files
by using your own `FileNamer` class. It is only possible to prefix the name, because other parts are needed in processing responsive images.
4 changes: 2 additions & 2 deletions docs/advanced-usage/working-with-multiple-filesystems.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Working with multiple filesystems
weight: 1
---

By default all files are stored on the disk specified as the `disk_name` in the config file.
By default, all files are stored on the disk specified as the `disk_name` in the config file.

Files can also be stored [on any filesystem that is configured in your Laravel app](http://laravel.com/docs/7.x/filesystem#configuration). When adding a file to the media library you can choose on which disk the file should be stored. This is useful when you have a combination of small files that should be stored locally and big files that you want to save on S3.

Expand All @@ -16,7 +16,7 @@ $yourModel->addMedia($pathToAFile)->toMediaCollection('images', 's3');

## Storing conversions on a separate disk

You can let the media library store [your conversions](/laravel-medialibrary/v8/converting-images/defining-conversions) and [responsive images](/laravel-medialibrary/v8/responsive-images/getting-started-with-responsive-images) on a disk other than the one where you save the original item. Pass the name of the disk where you want conversion to be saved to the `storingConversionsOnDisk` method.
You can let the media library store [your conversions](/v9/converting-images/defining-conversions) and [responsive images](/v9/responsive-images/getting-started-with-responsive-images) on a disk other than the one where you save the original item. Pass the name of the disk where you want conversion to be saved to the `storingConversionsOnDisk` method.

Here's an example where the original file is saved on the local disk and the conversions on S3.

Expand Down
2 changes: 1 addition & 1 deletion docs/api/defining-conversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ weight: 2

A media conversion can be added to your model in the `registerMediaConversions`-function. It should start with a call to `addMediaConversion`. From there on you can use any of the methods available in the API. They are all chainable.

Take a look in the [Defining conversions section](/laravel-medialibrary/v8/converting-images/defining-conversions/)
Take a look in the [Defining conversions section](/laravel-medialibrary/v9/converting-images/defining-conversions/)
for more details.

## General methods
Expand Down
4 changes: 2 additions & 2 deletions docs/converting-images/defining-conversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ $media->getUrl('old-picture') // the url to the sepia, bordered version

## Performing conversions on specific collections

By default a conversion will be performed on all files regardless of which [collection](/laravel-medialibrary/v8/working-with-media-collections/simple-media-collections) is used. Conversions can also be performed on all specific collections by adding a call to `performOnCollections`.
By default a conversion will be performed on all files regardless of which [collection](/laravel-medialibrary/v9/working-with-media-collections/simple-media-collections) is used. Conversions can also be performed on all specific collections by adding a call to `performOnCollections`.

This is how that looks like in the model:

Expand Down Expand Up @@ -109,7 +109,7 @@ $media->getUrl('thumb') // returns ''

## Queuing conversions

By default, a conversion will be added to the queue that you've [specified in the configuration](https://docs.spatie.be/laravel-medialibrary/v8/installation-setup). If you want your image to be created directly (and not on a queue) use `nonQueued` on a conversion.
By default, a conversion will be added to the queue that you've [specified in the configuration](https://docs.spatie.be/laravel-medialibrary/v9/installation-setup). If you want your image to be created directly (and not on a queue) use `nonQueued` on a conversion.

```php
// in your model
Expand Down
Loading

0 comments on commit 0730227

Please sign in to comment.