ComposerUpdate 增加文件链接配置

This commit is contained in:
Anyon 2020-01-13 16:55:55 +08:00
parent 592142cc87
commit b85978f0a6
11 changed files with 55 additions and 48 deletions

View File

@ -63,19 +63,19 @@ class Upload extends Controller
$data['url'] = $info['url'];
$this->success('文件已经上传', $data, 200);
} elseif ('local' === $data['uptype']) {
$data['url'] = LocalStorage::instance()->url($data['xkey']);
$data['url'] = LocalStorage::instance()->url($data['xkey'], $this->safe, $this->name);
$data['server'] = LocalStorage::instance()->upload();
} elseif ('qiniu' === $data['uptype']) {
$data['url'] = QiniuStorage::instance()->url($data['xkey']);
$data['url'] = QiniuStorage::instance()->url($data['xkey'], $this->safe, $this->name);
$data['token'] = QiniuStorage::instance()->buildUploadToken($data['xkey'], 3600, $this->name);
$data['server'] = QiniuStorage::instance()->upload();
} elseif ('alioss' === $data['uptype']) {
$token = AliossStorage::instance()->buildUploadToken($data['xkey']);
$data['server'] = AliossStorage::instance()->upload();
$token = AliossStorage::instance()->buildUploadToken($data['xkey'], 3600, $this->name);
$data['url'] = $token['siteurl'];
$data['policy'] = $token['policy'];
$data['signature'] = $token['signature'];
$data['OSSAccessKeyId'] = $token['keyid'];
$data['server'] = AliossStorage::instance()->upload();
}
$data['safe'] = intval($this->safe);
$this->success('获取上传参数', $data, 404);

View File

@ -28,7 +28,7 @@ define(['md5'], function (SparkMD5, allowExtsMimes) {
opt.element.data('file', file).data('index', index);
jQuery.ajax("{:url('@admin/api.upload/state')}", {
data: {xkey: file.xkey, uptype: opt.uptype, safe: opt.safe, name: file.name}, method: 'post', success: function (ret) {
file.xurl = ret.data.url + (ret.data.url.indexOf('?attname=') > -1 ? '' : '?attname=' + encodeURIComponent(file.name));
file.xurl = ret.data.url;
if (parseInt(ret.code) === 404) {
uploader.config.url = ret.data.server;
uploader.config.data.key = ret.data.xkey;

View File

@ -0,0 +1,27 @@
<div class="layui-form-item">
<label class="layui-form-label label-required">
<span class="color-green font-w7">LinkType</span><br><span class="nowrap color-desc">链接类型</span>
</label>
<div class="layui-input-block">
{foreach ['link_type_none'=>'简洁链接','link_type_full'=>'完整链接'] as $k=>$v}
<label class="think-radio">
{if sysconf('storage.link_type') eq $k}
<input checked type="radio" name="storage.link_type" value="{$k}" lay-ignore> {$v}
{else}
<input type="radio" name="storage.link_type" value="{$k}" lay-ignore> {$v}
{/if}
</label>
{/foreach}
<p class="help-block">类型为“简洁链接”时链接将只返回 hash 地址,而“完整链接”将携带参数保留文件名称</p>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label" for="storage.allow_exts">
<span class="color-green font-w7">AllowExts</span><br><span class="nowrap color-desc">允许类型</span>
</label>
<div class="layui-input-block">
<input id="storage.allow_exts" type="text" name="storage.allow_exts" required value="{:sysconf('storage.allow_exts')}" placeholder="请输入系统文件上传后缀" class="layui-input">
<p class="help-block">设置系统允许上传文件的后缀多个以英文逗号隔开如png,jpg,rar,doc</p>
</div>
</div>

View File

@ -6,15 +6,7 @@
<p>直传需要配置跨域规则,设置来源为 *,允许 Methods 为 POST允许 Headers 为 *</p>
</div>
<div class="layui-form-item">
<label class="layui-form-label" for="storage.allow_exts">
<span class="color-green font-w7">AllowExts</span><br><span class="nowrap color-desc">允许类型</span>
</label>
<div class="layui-input-block">
<input id="storage.allow_exts" type="text" name="storage.allow_exts" required value="{:sysconf('storage.allow_exts')}" placeholder="请输入系统文件上传后缀" class="layui-input">
<p class="help-block">设置系统允许上传文件的后缀多个以英文逗号隔开如png,jpg,rar,doc</p>
</div>
</div>
{include file='config/storage-0'}
<div class="layui-form-item">
<label class="layui-form-label label-required">

View File

@ -6,15 +6,7 @@
<p>文件存储的目录需要有读写权限,有足够的存储空间</p>
</div>
<div class="layui-form-item">
<label class="layui-form-label" for="storage.allow_exts">
<span class="color-green font-w7">AllowExts</span><br><span class="nowrap color-desc">允许类型</span>
</label>
<div class="layui-input-block">
<input id="storage.allow_exts" type="text" name="storage.allow_exts" required value="{:sysconf('storage.allow_exts')}" placeholder="请输入系统文件上传后缀" class="layui-input">
<p class="help-block">设置系统允许上传文件的后缀多个以英文逗号隔开。如png,jpg,rar,doc</p>
</div>
</div>
{include file='config/storage-0'}
<div class="layui-form-item">
<label class="layui-form-label label-required">

View File

@ -6,15 +6,7 @@
完成实名认证后可获得10G免费存储空间哦<a target="_blank" href="https://portal.qiniu.com/signup?code=3lhz6nmnwbple">我要免费申请</a>
</div>
<div class="layui-form-item">
<label class="layui-form-label" for="storage.allow_exts">
<span class="color-green font-w7">AllowExts</span><br><span class="nowrap color-desc">允许类型</span>
</label>
<div class="layui-input-block">
<input id="storage.allow_exts" type="text" name="storage.allow_exts" required value="{:sysconf('storage.allow_exts')}" placeholder="请输入系统文件上传后缀" class="layui-input">
<p class="help-block">设置系统允许上传文件的后缀多个以英文逗号隔开如png,jpg,rar,doc</p>
</div>
</div>
{include file='config/storage-0'}
<div class="layui-form-item">
<label class="layui-form-label label-required">

8
composer.lock generated
View File

@ -909,12 +909,12 @@
"source": {
"type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "65ff43be42fcf43679c8d05a416d8b25d70b7dbf"
"reference": "d2a8d9065308d0ce7b5d4e8ac916bb2a5095cb4c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/65ff43be42fcf43679c8d05a416d8b25d70b7dbf",
"reference": "65ff43be42fcf43679c8d05a416d8b25d70b7dbf",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/d2a8d9065308d0ce7b5d4e8ac916bb2a5095cb4c",
"reference": "d2a8d9065308d0ce7b5d4e8ac916bb2a5095cb4c",
"shasum": "",
"mirrors": [
{
@ -958,7 +958,7 @@
],
"description": "ThinkPHP v6.0 Development Library",
"homepage": "http://framework.thinkadmin.top",
"time": "2020-01-13T07:49:16+00:00"
"time": "2020-01-13T08:52:47+00:00"
},
{
"name": "zoujingli/wechat-developer",

View File

@ -935,12 +935,12 @@
"source": {
"type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "65ff43be42fcf43679c8d05a416d8b25d70b7dbf"
"reference": "d2a8d9065308d0ce7b5d4e8ac916bb2a5095cb4c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/65ff43be42fcf43679c8d05a416d8b25d70b7dbf",
"reference": "65ff43be42fcf43679c8d05a416d8b25d70b7dbf",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/d2a8d9065308d0ce7b5d4e8ac916bb2a5095cb4c",
"reference": "d2a8d9065308d0ce7b5d4e8ac916bb2a5095cb4c",
"shasum": "",
"mirrors": [
{
@ -956,7 +956,7 @@
"ext-json": "*",
"topthink/framework": "^6.0"
},
"time": "2020-01-13T07:49:16+00:00",
"time": "2020-01-13T08:52:47+00:00",
"type": "library",
"extra": {
"think": {

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php
// This file is automatically generated at:2020-01-13 16:07:29
// This file is automatically generated at:2020-01-13 16:54:27
declare (strict_types = 1);
return array (
0 => 'think\\app\\Service',

View File

@ -184,15 +184,18 @@ abstract class Storage
* 获取下载链接后缀
* @param string $attname 下载名称
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
protected function getSuffix($attname = null)
{
if (is_string($attname) && strlen($attname) > 0) {
$attname = "?attname=" . urlencode($attname);
} else {
$attname = '';
if (sysconf('storage.link_type') === 'link_type_full') {
if (is_string($attname) && strlen($attname) > 0) {
return "?attname=" . urlencode($attname);
}
}
return $attname;
return '';
}
}

View File

@ -215,16 +215,17 @@ class AliossStorage extends Storage
* 获取文件上传令牌
* @param string $name 文件名称
* @param integer $expires 有效时间
* @param string $attname 下载名称
* @return array
*/
public function buildUploadToken($name = null, $expires = 3600)
public function buildUploadToken($name = null, $expires = 3600, $attname = null)
{
$data = [
'policy' => base64_encode(json_encode([
'conditions' => [['content-length-range', 0, 1048576000]],
'expiration' => date('Y-m-d\TH:i:s.000\Z', time() + $expires),
])),
'siteurl' => $this->url($name),
'siteurl' => $this->url($name, false, $attname),
'keyid' => $this->accessKey,
];
$data['signature'] = base64_encode(hash_hmac('sha1', $data['policy'], $this->secretKey, true));