Skip to content

Commit

Permalink
Merge branch 'pionl:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
zaneoliver6 authored Mar 18, 2024
2 parents fa00bc8 + 0564c77 commit 220c607
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 90 deletions.
17 changes: 11 additions & 6 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
tests
travis.yml
.php_cs
.phplint.yml
phpunit.xml
CODE_OF_CONDUCT.md
# 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
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -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 |
7 changes: 7 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ composer.lock
/build
.phpunit.result.cache
.php_cs.cache
/.phpunit.cache
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions config/chunk-upload.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php
/**
* @see https://github.com/pionl/laravel-chunk-upload
*/

return [
/*
Expand Down
21 changes: 0 additions & 21 deletions phpunit.xml

This file was deleted.

13 changes: 13 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
24 changes: 12 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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) |
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Handler/ResumableJSUploadHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down
71 changes: 43 additions & 28 deletions src/Storage/ChunkStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

/**
Expand All @@ -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');
}

Expand All @@ -99,7 +114,7 @@ public function getDiskPathPrefix()
*/
public function directory()
{
return $this->config->chunksStorageDirectory().'/';
return $this->config->chunksStorageDirectory() . '/';
}

/**
Expand All @@ -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;
}
Expand Down Expand Up @@ -182,7 +197,7 @@ public function disk()
/**
* Returns the driver.
*
* @return FilesystemInterface
* @return FilesystemOperator|FilesystemInterface
*/
public function driver()
{
Expand Down
6 changes: 1 addition & 5 deletions tests/Providers/ChunkUploadServiceProviderMockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 220c607

Please sign in to comment.