mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
ComposerUpdate & 配置阿里云OSS下载原文件名
This commit is contained in:
parent
584eba4b62
commit
163890af2d
8
composer.lock
generated
8
composer.lock
generated
@ -909,12 +909,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/zoujingli/ThinkLibrary.git",
|
||||
"reference": "73ce73f61a90994e23b7616c73655440f50790a0"
|
||||
"reference": "65ff43be42fcf43679c8d05a416d8b25d70b7dbf"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/73ce73f61a90994e23b7616c73655440f50790a0",
|
||||
"reference": "73ce73f61a90994e23b7616c73655440f50790a0",
|
||||
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/65ff43be42fcf43679c8d05a416d8b25d70b7dbf",
|
||||
"reference": "65ff43be42fcf43679c8d05a416d8b25d70b7dbf",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
@ -958,7 +958,7 @@
|
||||
],
|
||||
"description": "ThinkPHP v6.0 Development Library",
|
||||
"homepage": "http://framework.thinkadmin.top",
|
||||
"time": "2020-01-13T06:39:14+00:00"
|
||||
"time": "2020-01-13T07:49:16+00:00"
|
||||
},
|
||||
{
|
||||
"name": "zoujingli/wechat-developer",
|
||||
|
8
vendor/composer/installed.json
vendored
8
vendor/composer/installed.json
vendored
@ -935,12 +935,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/zoujingli/ThinkLibrary.git",
|
||||
"reference": "73ce73f61a90994e23b7616c73655440f50790a0"
|
||||
"reference": "65ff43be42fcf43679c8d05a416d8b25d70b7dbf"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/73ce73f61a90994e23b7616c73655440f50790a0",
|
||||
"reference": "73ce73f61a90994e23b7616c73655440f50790a0",
|
||||
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/65ff43be42fcf43679c8d05a416d8b25d70b7dbf",
|
||||
"reference": "65ff43be42fcf43679c8d05a416d8b25d70b7dbf",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
@ -956,7 +956,7 @@
|
||||
"ext-json": "*",
|
||||
"topthink/framework": "^6.0"
|
||||
},
|
||||
"time": "2020-01-13T06:39:14+00:00",
|
||||
"time": "2020-01-13T07:49:16+00:00",
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"think": {
|
||||
|
2
vendor/services.php
vendored
2
vendor/services.php
vendored
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
// This file is automatically generated at:2020-01-13 14:48:33
|
||||
// This file is automatically generated at:2020-01-13 15:51:21
|
||||
declare (strict_types = 1);
|
||||
return array (
|
||||
0 => 'think\\app\\Service',
|
||||
|
34
vendor/zoujingli/think-library/src/Storage.php
vendored
34
vendor/zoujingli/think-library/src/Storage.php
vendored
@ -23,10 +23,10 @@ use think\Container;
|
||||
* 文件存储引擎管理
|
||||
* Class Storage
|
||||
* @package think\admin
|
||||
* @method array info($name, $safe = false) static 文件存储信息
|
||||
* @method array set($name, $file, $safe = false) static 储存文件
|
||||
* @method array info($name, $safe = false, $attname = null) static 文件存储信息
|
||||
* @method array set($name, $file, $safe = false, $attname = null) static 储存文件
|
||||
* @method string url($name, $safe = false, $attname = null) static 获取文件链接
|
||||
* @method string get($name, $safe = false) static 读取文件内容
|
||||
* @method string url($name, $safe = false) static 获取文件链接
|
||||
* @method string path($name, $safe = false) static 文件存储路径
|
||||
* @method boolean del($name, $safe = false) static 删除存储文件
|
||||
* @method boolean has($name, $safe = false) static 检查是否存在
|
||||
@ -167,4 +167,32 @@ abstract class Storage
|
||||
return $mimes = include __DIR__ . '/storage/bin/mimes.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件基础名称
|
||||
* @param string $name 文件名称
|
||||
* @return string
|
||||
*/
|
||||
protected function delSuffix($name)
|
||||
{
|
||||
if (strpos($name, '?') !== false) {
|
||||
list($name) = explode('?', $name);
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下载链接后缀
|
||||
* @param string $attname 下载名称
|
||||
* @return string
|
||||
*/
|
||||
protected function getSuffix($attname = null)
|
||||
{
|
||||
if (is_string($attname) && strlen($attname) > 0) {
|
||||
$attname = "?attname=" . urlencode($attname);
|
||||
} else {
|
||||
$attname = '';
|
||||
}
|
||||
return $attname;
|
||||
}
|
||||
|
||||
}
|
@ -99,10 +99,10 @@ class AliossStorage extends Storage
|
||||
* @param string $name 文件名称
|
||||
* @param string $file 文件内容
|
||||
* @param boolean $safe 安全模式
|
||||
* @param string $attachment 下载名称
|
||||
* @param string $attname 下载名称
|
||||
* @return array
|
||||
*/
|
||||
public function set($name, $file, $safe = false, $attachment = null)
|
||||
public function set($name, $file, $safe = false, $attname = null)
|
||||
{
|
||||
$token = $this->buildUploadToken($name);
|
||||
$data = ['key' => $name];
|
||||
@ -110,12 +110,13 @@ class AliossStorage extends Storage
|
||||
$data['Signature'] = $token['signature'];
|
||||
$data['OSSAccessKeyId'] = $this->accessKey;
|
||||
$data['success_action_status'] = '200';
|
||||
if (is_string($attachment) && strlen($attachment) > 0) {
|
||||
$data['Content-Disposition'] = "attachment;filename=" . urlencode($attachment);
|
||||
if (is_string($attname) && strlen($attname) > 0) {
|
||||
$filename = urlencode($attname);
|
||||
$data['Content-Disposition'] = "attachment;filename={$filename}";
|
||||
}
|
||||
$file = ['field' => 'file', 'name' => $name, 'content' => $file];
|
||||
if (is_numeric(stripos(HttpExtend::submit($this->upload(), $data, $file), '200 OK'))) {
|
||||
return ['file' => $this->path($name, $safe), 'url' => $this->url($name, $safe), 'key' => $name];
|
||||
return ['file' => $this->path($name, $safe), 'url' => $this->url($name, $safe, $attname), 'key' => $name];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
@ -129,7 +130,7 @@ class AliossStorage extends Storage
|
||||
*/
|
||||
public function get($name, $safe = false)
|
||||
{
|
||||
return file_get_contents($this->url($name, $safe) . "?e=" . time());
|
||||
return file_get_contents($this->url($name, $safe));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,8 +141,9 @@ class AliossStorage extends Storage
|
||||
*/
|
||||
public function del($name, $safe = false)
|
||||
{
|
||||
$result = HttpExtend::request('DELETE', "http://{$this->bucket}.{$this->point}/{$name}", [
|
||||
'returnHeader' => true, 'headers' => $this->headerSign('DELETE', $name),
|
||||
list($file) = explode('?', $name);
|
||||
$result = HttpExtend::request('DELETE', "http://{$this->bucket}.{$this->point}/{$file}", [
|
||||
'returnHeader' => true, 'headers' => $this->headerSign('DELETE', $file),
|
||||
]);
|
||||
return is_numeric(stripos($result, '204 No Content'));
|
||||
}
|
||||
@ -154,8 +156,9 @@ class AliossStorage extends Storage
|
||||
*/
|
||||
public function has($name, $safe = false)
|
||||
{
|
||||
$result = HttpExtend::request('HEAD', "http://{$this->bucket}.{$this->point}/{$name}", [
|
||||
'returnHeader' => true, 'headers' => $this->headerSign('HEAD', $name),
|
||||
$file = $this->delSuffix($name);
|
||||
$result = HttpExtend::request('HEAD', "http://{$this->bucket}.{$this->point}/{$file}", [
|
||||
'returnHeader' => true, 'headers' => $this->headerSign('HEAD', $file),
|
||||
]);
|
||||
return is_numeric(stripos($result, 'HTTP/1.1 200 OK'));
|
||||
}
|
||||
@ -164,11 +167,12 @@ class AliossStorage extends Storage
|
||||
* 获取文件当前URL地址
|
||||
* @param string $name 文件名称
|
||||
* @param boolean $safe 安全模式
|
||||
* @param string $attname 下载名称
|
||||
* @return string
|
||||
*/
|
||||
public function url($name, $safe = false)
|
||||
public function url($name, $safe = false, $attname = null)
|
||||
{
|
||||
return "{$this->prefix}/{$name}";
|
||||
return "{$this->prefix}/{$this->delSuffix($name)}{$this->getSuffix($attname)}";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -186,15 +190,15 @@ class AliossStorage extends Storage
|
||||
* 获取文件存储信息
|
||||
* @param string $name 文件名称
|
||||
* @param boolean $safe 安全模式
|
||||
* @param string $attname 下载名称
|
||||
* @return array
|
||||
*/
|
||||
public function info($name, $safe = false)
|
||||
public function info($name, $safe = false, $attname = null)
|
||||
{
|
||||
if ($this->has($name, $safe)) {
|
||||
return ['file' => $this->path($name, $safe), 'url' => $this->url($name, $safe), 'key' => $name];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
return $this->has($name, $safe) ? [
|
||||
'url' => $this->url($name, $safe, $attname),
|
||||
'key' => $name, 'file' => $this->path($name, $safe),
|
||||
] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,15 +68,16 @@ class LocalStorage extends Storage
|
||||
* @param string $name 文件名称
|
||||
* @param string $file 文件内容
|
||||
* @param boolean $safe 安全模式
|
||||
* @param string $attname 下载名称
|
||||
* @return array
|
||||
*/
|
||||
public function set($name, $file, $safe = false)
|
||||
public function set($name, $file, $safe = false, $attname = null)
|
||||
{
|
||||
try {
|
||||
$path = $this->path($name, $safe);
|
||||
file_exists(dirname($path)) || mkdir(dirname($path), 0755, true);
|
||||
if (file_put_contents($path, $file)) {
|
||||
return $this->info($name, $safe);
|
||||
return $this->info($name, $safe, $attname);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return [];
|
||||
@ -125,12 +126,12 @@ class LocalStorage extends Storage
|
||||
* 获取文件当前URL地址
|
||||
* @param string $name 文件名称
|
||||
* @param boolean $safe 安全模式
|
||||
* @param string $attname 下载名称
|
||||
* @return string|null
|
||||
*/
|
||||
public function url($name, $safe = false)
|
||||
public function url($name, $safe = false, $attname = null)
|
||||
{
|
||||
if ($safe) return $name;
|
||||
return "{$this->prefix}/upload/{$name}";
|
||||
return $safe ? $name : "{$this->prefix}/upload/{$this->delSuffix($name)}{$this->getSuffix($attname)}";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,19 +144,21 @@ class LocalStorage extends Storage
|
||||
{
|
||||
$root = $this->app->getRootPath();
|
||||
$path = $safe ? 'safefile' : 'public/upload';
|
||||
return strtr("{$root}{$path}/{$name}", '\\', '/');
|
||||
return strtr("{$root}{$path}/{$this->delSuffix($name)}", '\\', '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件存储信息
|
||||
* @param string $name 文件名称
|
||||
* @param boolean $safe 安全模式
|
||||
* @param string $attname 下载名称
|
||||
* @return array
|
||||
*/
|
||||
public function info($name, $safe = false)
|
||||
public function info($name, $safe = false, $attname = null)
|
||||
{
|
||||
return $this->has($name, $safe) ? [
|
||||
'file' => $this->path($name, $safe), 'url' => $this->url($name, $safe), 'key' => "upload/{$name}",
|
||||
'url' => $this->url($name, $safe, $attname),
|
||||
'key' => "upload/{$name}", 'file' => $this->path($name, $safe),
|
||||
] : [];
|
||||
}
|
||||
|
||||
|
@ -73,15 +73,16 @@ class QiniuStorage extends Storage
|
||||
* @param string $name 文件名称
|
||||
* @param string $file 文件内容
|
||||
* @param boolean $safe 安全模式
|
||||
* @param string $attname 下载名称
|
||||
* @return array
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function set($name, $file, $safe = false)
|
||||
public function set($name, $file, $safe = false, $attname = null)
|
||||
{
|
||||
$token = $this->buildUploadToken($name);
|
||||
$token = $this->buildUploadToken($name, 3600, $attname);
|
||||
$data = ['key' => $name, 'token' => $token, 'fileName' => $name];
|
||||
$file = ['field' => "file", 'name' => $name, 'content' => $file];
|
||||
$result = HttpExtend::submit($this->upload(), $data, $file, [], 'POST', false);
|
||||
@ -132,11 +133,12 @@ class QiniuStorage extends Storage
|
||||
* 获取文件当前URL地址
|
||||
* @param string $name 文件名称
|
||||
* @param boolean $safe 安全模式
|
||||
* @param string $attname 下载名称
|
||||
* @return string
|
||||
*/
|
||||
public function url($name, $safe = false)
|
||||
public function url($name, $safe = false, $attname = null)
|
||||
{
|
||||
return "{$this->prefix}/{$name}";
|
||||
return "{$this->prefix}/{$this->delSuffix($name)}{$this->getSuffix($attname)}";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,13 +156,14 @@ class QiniuStorage extends Storage
|
||||
* 获取文件存储信息
|
||||
* @param string $name 文件名称
|
||||
* @param boolean $safe 安全模式
|
||||
* @param string $attname 下载名称
|
||||
* @return array
|
||||
*/
|
||||
public function info($name, $safe = false)
|
||||
public function info($name, $safe = false, $attname = null)
|
||||
{
|
||||
list($entry, $token) = $this->getAccessToken($name);
|
||||
$data = json_decode(HttpExtend::get("http://rs.qiniu.com/stat/{$entry}", [], ['headers' => ["Authorization: QBox {$token}"]]), true);
|
||||
return isset($data['md5']) ? ['file' => $name, 'url' => $this->url($name, $safe), 'key' => $name] : [];
|
||||
return isset($data['md5']) ? ['file' => $name, 'url' => $this->url($name, $safe, $attname), 'key' => $name] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -194,14 +197,15 @@ class QiniuStorage extends Storage
|
||||
* 获取文件上传令牌
|
||||
* @param string $name 文件名称
|
||||
* @param integer $expires 有效时间
|
||||
* @param string $attname 下载名称
|
||||
* @return string
|
||||
*/
|
||||
public function buildUploadToken($name = null, $expires = 3600)
|
||||
public function buildUploadToken($name = null, $expires = 3600, $attname = null)
|
||||
{
|
||||
$policy = $this->safeBase64(json_encode([
|
||||
"deadline" => time() + $expires, "scope" => is_null($name) ? $this->bucket : "{$this->bucket}:{$name}",
|
||||
'returnBody' => json_encode([
|
||||
'uploaded' => true, 'filename' => '$(key)', 'file' => $name, 'url' => "{$this->prefix}/$(key)", 'key' => $name,
|
||||
'uploaded' => true, 'filename' => '$(key)', 'url' => "{$this->prefix}/$(key){$this->getSuffix($attname)}", 'key' => $name, 'file' => $name,
|
||||
], JSON_UNESCAPED_UNICODE),
|
||||
]));
|
||||
return "{$this->accessKey}:{$this->safeBase64(hash_hmac('sha1', $policy, $this->secretKey, true))}:{$policy}";
|
||||
|
Loading…
x
Reference in New Issue
Block a user