解压插件

This commit is contained in:
Edward Yang 2022-07-25 19:08:06 +08:00
parent 5ffcfaeb00
commit 6e9c8064c0
5 changed files with 99 additions and 3 deletions

View File

@ -37,6 +37,8 @@ class PluginController extends Controller
*/
public function import(Request $request): array
{
$zipFile = $request->file('file');
app('plugin')->import($zipFile);
return json_success("导入成功");
}

View File

@ -11,10 +11,12 @@
namespace Beike\Plugin;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use ZanySoft\Zip\Zip;
use Illuminate\Support\Arr;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Collection;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
class Manager
{
@ -162,4 +164,21 @@ class Manager
{
return config('plugins.directory') ?: base_path('plugins');
}
/**
* 上传插件并解压
* @throws \Exception
*/
public function import(UploadedFile $file)
{
$originalName = $file->getClientOriginalName();
$destPath = storage_path('upload');
$newFilePath = $destPath . '/' . $originalName;
$file->move($destPath, $originalName);
Zip::check($newFilePath);
$zipFile = Zip::open($newFilePath);
$zipFile->extract(base_path('plugins'));
}
}

View File

@ -7,13 +7,15 @@
"require": {
"php": "^7.3|^8.0",
"ext-json": "*",
"ext-zip": "*",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"intervention/image": "^2.7",
"laravel/framework": "^8.65",
"laravel/tinker": "^2.5",
"stripe/stripe-php": "^8.8",
"tormjens/eventy": "^0.8.0"
"tormjens/eventy": "^0.8.0",
"zanysoft/laravel-zip": "^1.0"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.6",

73
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "4fc9f5ec868c1a2d6737b5724e42960c",
"content-hash": "9646e182a6e72a01992da9c58f87b3fe",
"packages": [
{
"name": "asm89/stack-cors",
@ -5963,6 +5963,77 @@
"source": "https://github.com/webmozarts/assert/tree/1.10.0"
},
"time": "2021-03-09T10:59:23+00:00"
},
{
"name": "zanysoft/laravel-zip",
"version": "1.0.4",
"source": {
"type": "git",
"url": "https://github.com/zanysoft/laravel-zip.git",
"reference": "86028aa46b234565311829dd6b62d48417335925"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zanysoft/laravel-zip/zipball/86028aa46b234565311829dd6b62d48417335925",
"reference": "86028aa46b234565311829dd6b62d48417335925",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"illuminate/support": "^6.0|^7.0|^8.0",
"php": ">=7.1"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"ZanySoft\\Zip\\ZipServiceProvider"
],
"aliases": {
"Zip": "ZanySoft\\Zip\\ZipFacade"
}
}
},
"autoload": {
"psr-4": {
"ZanySoft\\Zip\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Zany Soft",
"email": "info@zanysoft.net",
"homepage": "http://www.zanysoft.net"
}
],
"description": "laravel-zip is the world's leading zip utility for file compression and backup.",
"homepage": "http://www.zanysoft.net",
"keywords": [
"backup",
"extract",
"laravel",
"laravel-zip",
"laravel5",
"merge",
"multiple",
"unzip",
"zip",
"ziparchive"
],
"support": {
"issues": "https://github.com/zanysoft/laravel-zip/issues",
"source": "https://github.com/zanysoft/laravel-zip/tree/1.0.4"
},
"time": "2021-10-27T08:16:31+00:00"
}
],
"packages-dev": [

2
storage/upload/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore