diff --git a/.gitattributes b/.gitattributes index 87ff7d7..3d7b658 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,11 @@ -tests -travis.yml -.php_cs -.phplint.yml -phpunit.xml -CODE_OF_CONDUCT.md \ No newline at end of file +# Ignore all test and documentation for archive +/.github export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.scrutinizer.yml export-ignore +/phpunit.xml.dist export-ignore +/tests export-ignore +/docs export-ignore +/.php_cs export-ignore +/.phplint.yml export-ignore +/CODE_OF_CONDUCT.md export-ignore \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..ebddba8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,14 @@ +### What steps will reproduce the problem? + +### What is the expected result? + +### What do you get instead? + +### Additional info + +| Q | A +| ------------------------- | --- +| This Package Version | 1.?.? +| Laravel Framework Version | 9.?.? +| PHP version | +| Operating system | diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..f4af2f3 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,7 @@ +| Q | A +| ------------- | --- +| Is bugfix? | ✔️/❌ +| New feature? | ✔️/❌ +| Breaks BC? | ✔️/❌ +| Tests pass? | ✔️/❌ +| Fixed issues | comma-separated list of tickets # fixed by the PR, if any \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..9292b34 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,32 @@ +name: build + +on: [push, pull_request] + +jobs: + phpunit: + name: PHP ${{ matrix.php }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: mbstring + tools: composer:v2 + coverage: none + + - name: Install dependencies + run: | + composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - name: Run unit tests + run: vendor/bin/phpunit --colors=always diff --git a/.gitignore b/.gitignore index b9b19b9..b1f8a02 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ composer.lock /build .phpunit.result.cache .php_cs.cache +/.phpunit.cache +phpunit.xml.dist.bak diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b12cbf5..0000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -language: php -php: - - '7.2' - - '7.3' - - '7.4' -os: - - linux - -before_script: composer install --dev - -script: ./vendor/phpunit/phpunit/phpunit --configuration phpunit.xml diff --git a/composer.json b/composer.json index 76129d1..8b3bbd3 100644 --- a/composer.json +++ b/composer.json @@ -15,14 +15,13 @@ "test": "./vendor/bin/phpunit" }, "require": { - "illuminate/http": "5.2 - 5.8 | ^6.0 | ^7.0 | ^8.0", - "illuminate/console": "5.2 - 5.8 | ^6.0 | ^7.0 | ^8.0", - "illuminate/support": "5.2 - 5.8 | ^6.0 | ^7.0 | ^8.0", - "illuminate/filesystem": "5.2 - 5.8 | ^6.0 | ^7.0 | ^8.0" + "illuminate/http": "5.2 - 5.8 | ^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0", + "illuminate/console": "5.2 - 5.8 | ^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0", + "illuminate/support": "5.2 - 5.8 | ^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0", + "illuminate/filesystem": "5.2 - 5.8 | ^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0" }, "require-dev": { - "laravel/laravel": "5.2 - 5.8 | ^6.0 | ^7.0 | ^8.0", - "phpunit/phpunit": "5.7 | 6.0 | 7.0 | 7.5 | 8.4 | ^8.5 | ^9.3", + "phpunit/phpunit": "5.7 | 6.0 | 7.0 | 7.5 | 8.4 | ^8.5 | ^9.3 | ^10.0", "mockery/mockery": "^1.1.0 | ^1.3.0", "friendsofphp/php-cs-fixer": "^2.16.0", "overtrue/phplint": "^1.1 | ^2.0" diff --git a/config/chunk-upload.php b/config/chunk-upload.php index dea3251..7b8cba7 100644 --- a/config/chunk-upload.php +++ b/config/chunk-upload.php @@ -1,4 +1,7 @@ - - - - ./tests/ - - - - - src/ - - - diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..079d5be --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,13 @@ + + + + + ./tests/ + + + + + src/ + + + diff --git a/readme.md b/readme.md index 45b9530..ccc05c8 100644 --- a/readme.md +++ b/readme.md @@ -1,14 +1,14 @@ # Laravel Chunk Upload [![Total Downloads](https://poser.pugx.org/pion/laravel-chunk-upload/downloads?format=flat)](https://packagist.org/packages/pion/laravel-chunk-upload) -[![Build Status](https://travis-ci.org/pionl/laravel-chunk-upload.svg?branch=master)](https://travis-ci.org/pionl/laravel-chunk-upload) +[![Build Status](https://github.com/pionl/laravel-chunk-upload/workflows/build/badge.svg)](https://github.com/pionl/laravel-chunk-upload/actions) [![Latest Stable Version](https://poser.pugx.org/pion/laravel-chunk-upload/v/stable?format=flat)](https://packagist.org/packages/pion/laravel-chunk-upload) [![Latest Unstable Version](https://poser.pugx.org/pion/laravel-chunk-upload/v/unstable?format=flat)](https://packagist.org/packages/pion/laravel-chunk-upload) [![License](https://poser.pugx.org/pion/laravel-chunk-upload/license)](https://packagist.org/packages/pion/laravel-chunk-upload) ## Introduction -> Supports Laravel from 5.2 to 7 (covered by integration tests on all versions). +> Supports Laravel from 5.2 to 9 (covered by integration tests for 7/8/9 versions). Easy to use service/library for chunked upload with supporting multiple JS libraries on top of Laravel's file upload with low memory footprint in mind. @@ -43,7 +43,7 @@ Setup consists of 3 steps: | Library | Wiki | single & chunk upload | simultaneous uploads | In [example project](https://github.com/pionl/laravel-chunk-upload-example) | Author | |---- |----|----|----| ---- | ---- | | [resumable.js](https://github.com/23/resumable.js) | [Wiki](https://github.com/pionl/laravel-chunk-upload/wiki/resumable-js) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | [@pionl](https://github.com/pionl) | -| [DropZone](https://gitlab.com/meno/dropzone/) | [Wiki](https://github.com/pionl/laravel-chunk-upload/wiki/dropzone) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | [@pionl](https://github.com/pionl) | +| [DropZone](https://github.com/dropzone/dropzone) | [Wiki](https://github.com/pionl/laravel-chunk-upload/wiki/dropzone) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | [@pionl](https://github.com/pionl) | | [jQuery-File-Upload](https://github.com/blueimp/jQuery-File-Upload) | [Wiki](https://github.com/pionl/laravel-chunk-upload/wiki/jquery-file-upload) | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | [@pionl](https://github.com/pionl) | | [Plupload](https://github.com/moxiecode/plupload) | [Wiki](https://github.com/pionl/laravel-chunk-upload/wiki/plupload) | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: | [@pionl](https://github.com/pionl) | | [simple uploader](https://github.com/simple-uploader) | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: | [@dyktek](https://github.com/dyktek) | @@ -67,15 +67,15 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for how to contribute changes. All contri ## Compatibility -* 7.* (last tested on v7.16.1) -* 6.* (last tested on v6.18.20) -* 5.8.* (last tested on v5.8.38) -* 5.7.* (last tested on v5.7.29) -* 5.6.* (last tested on v5.6.40) -* 5.5.* (last tested on v5.5.49) -* 5.4.* (last tested on v5.4.36) -* 5.3.* (last tested on v5.3.31) -* 5.2.* (last tested on v5.2.45) +> Laravel 5/6 should be still supported but we are not testing them via automation sccripts + +| Version | PHP | +|---------|---------------| +| 10.* | 8.1, 8.2 | +| 9.* | 8.0, 8.1 | +| 8.* | 7.4, 8.0, 8.1 | +| 7.* | 7.4 | + ## Copyright and License diff --git a/src/Handler/ResumableJSUploadHandler.php b/src/Handler/ResumableJSUploadHandler.php index 59f79f2..7a70ae9 100644 --- a/src/Handler/ResumableJSUploadHandler.php +++ b/src/Handler/ResumableJSUploadHandler.php @@ -43,7 +43,7 @@ public function __construct(Request $request, $file, $config) */ public function getChunkFileName() { - return $this->createChunkFileName($this->fileUuid, $this->getCurrentChunk()); + return $this->createChunkFileName(substr($this->fileUuid,0,40), $this->getCurrentChunk()); } /** diff --git a/src/Storage/ChunkStorage.php b/src/Storage/ChunkStorage.php index aa9cc16..882a837 100644 --- a/src/Storage/ChunkStorage.php +++ b/src/Storage/ChunkStorage.php @@ -4,7 +4,9 @@ use Illuminate\Contracts\Filesystem\Filesystem as FilesystemContract; use Illuminate\Support\Collection; +use Illuminate\Filesystem\FilesystemAdapter; use League\Flysystem\Adapter\Local; +use League\Flysystem\Local\LocalFilesystemAdapter; use League\Flysystem\FilesystemInterface; use Pion\Laravel\ChunkUpload\ChunkFile; use Pion\Laravel\ChunkUpload\Config\AbstractConfig; @@ -28,52 +30,61 @@ public static function storage() * @var AbstractConfig */ protected $config; - /** * The disk that holds the chunk files. * - * @var FilesystemAdapter + * @var FilesystemContract|FilesystemAdapter */ protected $disk; - /** - * @var Local + * @var Local|LocalFilesystemAdapter */ protected $diskAdapter; + protected $isLocalDisk; /** - * Is provided disk a local drive. - * - * @var bool + * @var */ - protected $isLocalDisk; + protected $usingDeprecatedLaravel; /** - * ChunkStorage constructor. - * - * @param FilesystemContract $disk the desired disk for chunk storage - * @param AbstractConfig $config + * @param FilesystemAdapter|FilesystemContract $disk the desired disk for chunk storage + * @param AbstractConfig $config */ - public function __construct(FilesystemContract $disk, $config) + public function __construct($disk, $config) { // save the config $this->config = $config; - - // cache the storage path + $this->usingDeprecatedLaravel = class_exists(LocalFilesystemAdapter::class) === false; $this->disk = $disk; - $driver = $this->driver(); + if ($this->usingDeprecatedLaravel === false) { - // try to get the adapter - if (!method_exists($driver, 'getAdapter')) { - throw new RuntimeException('FileSystem driver must have an adapter implemented'); - } + // try to get the adapter + if (!method_exists($this->disk, 'getAdapter')) { + throw new RuntimeException('FileSystem driver must have an adapter implemented'); + } + + // get the disk adapter + $this->diskAdapter = $this->disk->getAdapter(); - // get the disk adapter - $this->diskAdapter = $driver->getAdapter(); + // check if its local adapter + $this->isLocalDisk = $this->diskAdapter instanceof LocalFilesystemAdapter; + } else { + $driver = $this->driver(); + + // try to get the adapter + if (!method_exists($driver, 'getAdapter')) { + throw new RuntimeException('FileSystem driver must have an adapter implemented'); + } + + // get the disk adapter + $this->diskAdapter = $driver->getAdapter(); + + // check if its local adapter + $this->isLocalDisk = $this->diskAdapter instanceof Local; + } - // check if its local adapter - $this->isLocalDisk = $this->diskAdapter instanceof Local; } /** @@ -85,10 +96,14 @@ public function __construct(FilesystemContract $disk, $config) */ public function getDiskPathPrefix() { - if ($this->isLocalDisk) { + if ($this->usingDeprecatedLaravel === true && $this->isLocalDisk) { return $this->diskAdapter->getPathPrefix(); } + if ($this->isLocalDisk) { + return $this->disk->path(''); + } + throw new RuntimeException('The full path is not supported on current disk - local adapter supported only'); } @@ -99,7 +114,7 @@ public function getDiskPathPrefix() */ public function directory() { - return $this->config->chunksStorageDirectory().'/'; + return $this->config->chunksStorageDirectory() . '/'; } /** @@ -119,7 +134,7 @@ public function files($rejectClosure = null) return $filesCollection->reject(function ($file) use ($rejectClosure) { // ensure the file ends with allowed extension - $shouldReject = !preg_match('/.'.self::CHUNK_EXTENSION.'$/', $file); + $shouldReject = !preg_match('/.' . self::CHUNK_EXTENSION . '$/', $file); if ($shouldReject) { return true; } @@ -182,7 +197,7 @@ public function disk() /** * Returns the driver. * - * @return FilesystemInterface + * @return FilesystemOperator|FilesystemInterface */ public function driver() { diff --git a/tests/Providers/ChunkUploadServiceProviderMockTest.php b/tests/Providers/ChunkUploadServiceProviderMockTest.php index 4bcf619..4adb3ed 100644 --- a/tests/Providers/ChunkUploadServiceProviderMockTest.php +++ b/tests/Providers/ChunkUploadServiceProviderMockTest.php @@ -39,14 +39,10 @@ class ChunkUploadServiceProviderMockTest extends Mockery\Adapter\Phpunit\Mockery */ protected $config; - public function __construct($name = null, array $data = [], $dataName = '') - { - parent::__construct($name, $data, $dataName); - } - protected function setUp(): void { parent::setUp(); + $this->app = Mockery::mock(\Illuminate\Contracts\Container\Container::class); $this->config = Mockery::mock(Repository::class);