mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-05-29 01:49:16 +08:00
增加 Alist 存储配置
This commit is contained in:
parent
06679ba6f5
commit
2e15451544
@ -21,6 +21,7 @@ use think\admin\service\AdminService;
|
||||
use think\admin\service\ModuleService;
|
||||
use think\admin\service\RuntimeService;
|
||||
use think\admin\service\SystemService;
|
||||
use think\admin\Storage;
|
||||
use think\admin\storage\AliossStorage;
|
||||
use think\admin\storage\QiniuStorage;
|
||||
use think\admin\storage\TxcosStorage;
|
||||
@ -53,6 +54,7 @@ class Config extends Controller
|
||||
public function index()
|
||||
{
|
||||
$this->title = '系统参数配置';
|
||||
$this->files = Storage::types();
|
||||
$this->super = AdminService::isSuper();
|
||||
$this->version = ModuleService::getVersion();
|
||||
$this->fetch();
|
||||
|
@ -22,6 +22,7 @@ use think\admin\model\SystemFile;
|
||||
use think\admin\service\AdminService;
|
||||
use think\admin\Storage;
|
||||
use think\admin\storage\AliossStorage;
|
||||
use think\admin\storage\AlistStorage;
|
||||
use think\admin\storage\LocalStorage;
|
||||
use think\admin\storage\QiniuStorage;
|
||||
use think\admin\storage\TxcosStorage;
|
||||
@ -107,34 +108,47 @@ class Upload extends Controller
|
||||
$extr = ['id' => $file->id ?? 0, 'url' => $info['url'], 'key' => $info['key']];
|
||||
$this->success('文件已经上传', array_merge($data, $extr), 200);
|
||||
} elseif ('local' === $data['uptype']) {
|
||||
$data['url'] = LocalStorage::instance()->url($data['key'], $safe, $name);
|
||||
$data['server'] = LocalStorage::instance()->upload();
|
||||
$local = LocalStorage::instance();
|
||||
$data['url'] = $local->url($data['key'], $safe, $name);
|
||||
$data['server'] = $local->upload();
|
||||
} elseif ('qiniu' === $data['uptype']) {
|
||||
$data['url'] = QiniuStorage::instance()->url($data['key'], $safe, $name);
|
||||
$data['token'] = QiniuStorage::instance()->buildUploadToken($data['key'], 3600, $name);
|
||||
$data['server'] = QiniuStorage::instance()->upload();
|
||||
$qiniu = QiniuStorage::instance();
|
||||
$data['url'] = $qiniu->url($data['key'], $safe, $name);
|
||||
$data['token'] = $qiniu->token($data['key'], 3600, $name);
|
||||
$data['server'] = $qiniu->upload();
|
||||
} elseif ('alioss' === $data['uptype']) {
|
||||
$token = AliossStorage::instance()->buildUploadToken($data['key'], 3600, $name);
|
||||
$alioss = AliossStorage::instance();
|
||||
$token = $alioss->token($data['key'], 3600, $name);
|
||||
$data['url'] = $token['siteurl'];
|
||||
$data['policy'] = $token['policy'];
|
||||
$data['signature'] = $token['signature'];
|
||||
$data['OSSAccessKeyId'] = $token['keyid'];
|
||||
$data['server'] = AliossStorage::instance()->upload();
|
||||
$data['server'] = $alioss->upload();
|
||||
} elseif ('txcos' === $data['uptype']) {
|
||||
$token = TxcosStorage::instance()->buildUploadToken($data['key'], 3600, $name);
|
||||
$txcos = TxcosStorage::instance();
|
||||
$token = $txcos->token($data['key'], 3600, $name);
|
||||
$data['url'] = $token['siteurl'];
|
||||
$data['q-ak'] = $token['q-ak'];
|
||||
$data['policy'] = $token['policy'];
|
||||
$data['q-key-time'] = $token['q-key-time'];
|
||||
$data['q-signature'] = $token['q-signature'];
|
||||
$data['q-sign-algorithm'] = $token['q-sign-algorithm'];
|
||||
$data['server'] = TxcosStorage::instance()->upload();
|
||||
$data['server'] = $txcos->upload();
|
||||
} elseif ('upyun' === $data['uptype']) {
|
||||
$token = UpyunStorage::instance()->buildUploadToken($data['key'], 3600, $name, input('hash', ''));
|
||||
$upyun = UpyunStorage::instance();
|
||||
$token = $upyun->token($data['key'], 3600, $name, input('hash', ''));
|
||||
$data['url'] = $token['siteurl'];
|
||||
$data['policy'] = $token['policy'];
|
||||
$data['server'] = $upyun->upload();
|
||||
$data['authorization'] = $token['authorization'];
|
||||
$data['server'] = UpyunStorage::instance()->upload();
|
||||
} elseif ('alist' === $data['uptype']) {
|
||||
$alist = AlistStorage::instance();
|
||||
$data['url'] = $alist->url($data['key']);
|
||||
$data['server'] = $alist->upload();
|
||||
$data['filepath'] = $alist->real($data['key'], true);
|
||||
$data['authorization'] = $alist->token();
|
||||
} else {
|
||||
$this->error('未知的存储引擎!');
|
||||
}
|
||||
$file->save(['xurl' => $data['url'], 'isfast' => 0, 'issafe' => $data['safe']]);
|
||||
$this->success('获取上传授权参数', array_merge($data, ['id' => $file->id ?? 0]), 404);
|
||||
|
@ -114,13 +114,19 @@ define(['md5', 'notify'], function (SparkMD5, Notify, allowMime) {
|
||||
file.xsafe = ret.data.safe, file.xpath = ret.data.key, file.xtype = ret.data.uptype;
|
||||
if (parseInt(ret.code) === 404) {
|
||||
var uploader = {};
|
||||
uploader.uptype = ret.data.uptype;
|
||||
uploader.url = ret.data.server;
|
||||
uploader.head = {};
|
||||
uploader.form = new FormData();
|
||||
uploader.form.append('key', ret.data.key);
|
||||
uploader.form.append('safe', ret.data.safe);
|
||||
uploader.form.append('uptype', ret.data.uptype);
|
||||
if (ret.data.uptype === 'qiniu') {
|
||||
uploader.form.append('token', ret.data.token);
|
||||
} else if (ret.data.uptype === 'alist') {
|
||||
uploader.type = 'put';
|
||||
uploader.head['file-path'] = ret.data['filepath'];
|
||||
uploader.head['authorization'] = ret.data['authorization'];
|
||||
} else if (ret.data.uptype === 'alioss') {
|
||||
uploader.form.append('policy', ret.data['policy']);
|
||||
uploader.form.append('signature', ret.data['signature']);
|
||||
@ -145,8 +151,8 @@ define(['md5', 'notify'], function (SparkMD5, Notify, allowMime) {
|
||||
uploader.form.append('Content-Disposition', 'inline;filename=' + encodeURIComponent(file.name));
|
||||
}
|
||||
uploader.form.append('file', file, file.name), jQuery.ajax({
|
||||
xhrFields: {withCredentials: ret.data.uptype === 'local'},
|
||||
url: uploader.url, data: uploader.form, type: 'post', xhr: function (xhr) {
|
||||
xhrFields: {withCredentials: ret.data.uptype === 'local'}, headers: uploader.head,
|
||||
url: uploader.url, data: uploader.form, type: uploader.type || 'post', xhr: function (xhr) {
|
||||
xhr = new XMLHttpRequest();
|
||||
return xhr.upload.addEventListener('progress', function (event) {
|
||||
file.xtotal = event.total, file.xloaded = event.loaded || 0;
|
||||
@ -167,6 +173,8 @@ define(['md5', 'notify'], function (SparkMD5, Notify, allowMime) {
|
||||
/*! 检查单个文件上传返回的结果 */
|
||||
if (typeof ret === 'object' && ret.code < 1) {
|
||||
that.event('upload.error', {file: file}, file, ret.info || '上传失败');
|
||||
} else if (uploader.uptype === 'alist' && parseInt(ret.code) !== 200) {
|
||||
that.event('upload.error', {file: file}, file, ret.message || '上传失败');
|
||||
} else {
|
||||
that.done(ret, file.index, file, done, '上传成功');
|
||||
}
|
||||
|
@ -67,18 +67,19 @@
|
||||
{if !sysconf('storage.local_http_protocol')}{php}sysconf('storage.local_http_protocol','follow');{/php}{/if}
|
||||
<div class="layui-card-body layui-clear">
|
||||
<div class="layui-btn-group shadow-mini nowrap">
|
||||
{foreach ['local'=>'本地服务器存储','qiniu'=>'七牛云对象存储','upyun'=>'又拍云USS存储','alioss'=>'阿里云OSS存储','txcos'=>'腾讯云COS存储'] as $k => $v}{if sysconf('storage.type') eq $k}
|
||||
{foreach $files as $k => $v}{if sysconf('storage.type') eq $k}
|
||||
{if auth('storage')}<a data-title="配置{$v}" data-modal="{:url('storage')}?type={$k}" class="layui-btn layui-btn-sm layui-btn-active">{$v}</a>{else}<a class="layui-btn layui-btn-sm layui-btn-active">{$v}</a>{/if}
|
||||
{else}
|
||||
{if auth('storage')}<a data-title="配置{$v}" data-modal="{:url('storage')}?type={$k}" class="layui-btn layui-btn-sm layui-btn-primary">{$v}</a>{else}<a class="layui-btn layui-btn-sm layui-btn-primary">{$v}</a>{/if}
|
||||
{/if}{/foreach}
|
||||
</div>
|
||||
<div class="margin-top-20 nowrap full-width pull-left">
|
||||
<p><b>本地服务器存储</b>:文件直接上传到本地服务器的 `static/upload` 目录,不支持大文件上传,占用服务器磁盘空间,访问时消耗服务器带宽流量。</p>
|
||||
<p><b>七牛云对象存储</b>:文件直接上传到七牛云存储空间,支持大文件上传,不占用服务器空间及服务器带宽流量,支持 CDN 加速访问,访问量大时推荐使用。</p>
|
||||
<p><b>又拍云USS存储</b>:文件直接上传到又拍云 USS 存储空间,支持大文件上传,不占用服务器空间及服务器带宽流量,支持 CDN 加速访问,访问量大时推荐使用。</p>
|
||||
<p><b>阿里云OSS存储</b>:文件直接上传到阿里云 OSS 存储空间,支持大文件上传,不占用服务器空间及服务器带宽流量,支持 CDN 加速访问,访问量大时推荐使用。</p>
|
||||
<p><b>腾讯云COS存储</b>:文件直接上传到腾讯云 COS 存储空间,支持大文件上传,不占用服务器空间及服务器带宽流量,支持 CDN 加速访问,访问量大时推荐使用。</p>
|
||||
<p><b>本地服务器存储</b>:文件上传到本地服务器的 `static/upload` 目录,不支持大文件上传,占用服务器磁盘空间,访问时消耗服务器带宽流量。</p>
|
||||
<p><b>自建<code>Alist</code>存储</b>:文件上传到 Alist 存储的服务器或云存储空间,根据服务配置可支持大文件上传,不占用本身服务器空间及服务器带宽流量。</p>
|
||||
<p><b>七牛云对象存储</b>:文件上传到七牛云存储空间,支持大文件上传,不占用服务器空间及服务器带宽流量,支持 CDN 加速访问,访问量大时推荐使用。</p>
|
||||
<p><b>又拍云<code>USS</code>存储</b>:文件上传到又拍云 USS 存储空间,支持大文件上传,不占用服务器空间及服务器带宽流量,支持 CDN 加速访问,访问量大时推荐使用。</p>
|
||||
<p><b>阿里云<code>OSS</code>存储</b>:文件上传到阿里云 OSS 存储空间,支持大文件上传,不占用服务器空间及服务器带宽流量,支持 CDN 加速访问,访问量大时推荐使用。</p>
|
||||
<p><b>腾讯云<code>COS</code>存储</b>:文件上传到腾讯云 COS 存储空间,支持大文件上传,不占用服务器空间及服务器带宽流量,支持 CDN 加速访问,访问量大时推荐使用。</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -113,7 +114,7 @@
|
||||
<div class="help-block">管理程序版本,将显示在后台左上角标题。</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<div class="help-label"><b>公网备案号</b>Baian</div>
|
||||
<div class="help-label"><b>公网备案号</b>Beian</div>
|
||||
<label class="relative block">
|
||||
<input readonly value="{:sysconf('beian')?:'-'}" class="layui-input layui-bg-gray">
|
||||
<a data-copy="{:sysconf('beian')}" class="layui-icon layui-icon-release input-right-icon"></a>
|
||||
|
79
app/admin/view/config/storage-alist.html
Normal file
79
app/admin/view/config/storage-alist.html
Normal file
@ -0,0 +1,79 @@
|
||||
<form action="{:sysuri()}" method="post" data-auto="true" class="layui-form layui-card">
|
||||
<div class="layui-card-body padding-top-20">
|
||||
|
||||
<div class="color-text layui-code text-center layui-bg-gray" style="border-left-width:1px;margin:0 0 15px 40px">
|
||||
<p class="margin-bottom-5 font-w7">文件将上传到 <a target="_blank" href="https://alist.nn.ci/zh/">Alist</a> 自建存储,需要自行搭建 <a target="_blank" href="https://alist.nn.ci/zh/">Alist</a> 存储服务器。</p>
|
||||
<p>Alist 是一个支持多种存储的文件列表程序,可将各种云盘及本地磁盘资源进行整合。</p>
|
||||
<p>请使用 Alist v3 版本,建议不要开放匿名用户访问,尽量使用账号独立管理访问目录权限。</p>
|
||||
</div>
|
||||
|
||||
{include file='config/storage-0'}
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label label-required">
|
||||
<b class="color-green">访问协议</b><br><span class="nowrap color-desc">Protocol</span>
|
||||
</label>
|
||||
<div class="layui-input-block">
|
||||
{if !sysconf('storage.alist_http_protocol')}{php}sysconf('storage.alist_http_protocol','http');{/php}{/if}
|
||||
{foreach ['http'=>'HTTP','https'=>'HTTPS','auto'=>"AUTO"] as $protocol=>$remark}
|
||||
<label class="think-radio">
|
||||
{if sysconf('storage.alist_http_protocol') eq $protocol}
|
||||
<input checked type="radio" name="storage.alist_http_protocol" value="{$protocol}" lay-ignore> {$remark}
|
||||
{else}
|
||||
<input type="radio" name="storage.alist_http_protocol" value="{$protocol}" lay-ignore> {$remark}
|
||||
{/if}
|
||||
</label>
|
||||
{/foreach}
|
||||
<p class="help-block">请选择 Alist 存储访问协议,其中 HTTPS 需要配置证书才能使用( AUTO 为相对协议 )</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label" for="storage.alist_http_domain">
|
||||
<b class="color-green">访问域名</b><br><span class="nowrap color-desc">Domain</span>
|
||||
</label>
|
||||
<div class="layui-input-block">
|
||||
<input id="storage.alist_http_domain" type="text" name="storage.alist_http_domain" value="{:sysconf('storage.alist_http_domain')}" required vali-name="访问域名" placeholder="请输入 Alist 存储的访问域名" class="layui-input">
|
||||
<p class="help-block">请填写 Alist 存储访问域名,如:storage.thinkadmin.top</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label" for="storage.alist_userpath">
|
||||
<b class="color-green">存储目录</b><br><span class="nowrap color-desc">Directory</span>
|
||||
</label>
|
||||
<div class="layui-input-block">
|
||||
<input id="storage.alist_userpath" type="text" name="storage.alist_userpath" value="{:sysconf('storage.alist_userpath')}" required vali-name="存储目录" placeholder="请输入 Alist 存储存储目录" class="layui-input">
|
||||
<p class="help-block">请填写 Alist 存储目录 ( 如:/uploads ),填写 / 表示根目录( 需要拥有读写权限 )</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label" for="storage.alist_username">
|
||||
<b class="color-green">用户账号</b><br><span class="nowrap color-desc">Username</span>
|
||||
</label>
|
||||
<div class="layui-input-block">
|
||||
<input id="storage.alist_username" name="storage.alist_username" value="{:sysconf('storage.alist_username')}" maxlength="100" required vali-name="用户账号" placeholder="请输入 Alist 存储的用户账号" class="layui-input">
|
||||
<p class="help-block">请填写 Alist 用户账号,注意此账号需要拥有上面存储目录的访问权限。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label" for="storage.alist_password">
|
||||
<b class="color-green">用户密码</b><br><span class="nowrap color-desc">Password</span>
|
||||
</label>
|
||||
<div class="layui-input-block">
|
||||
<input id="storage.alist_password" name="storage.alist_password" value="{:sysconf('storage.alist_password')}" maxlength="100" required vali-name="用户密码" placeholder="请输入 Alist 存储的用户密码" class="layui-input">
|
||||
<p class="help-block">请填写 Alist 用户登录密码,用于生成文件上传的接口认证令牌,如果填写错误将无法上传文件。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed margin-left-40"></div>
|
||||
<input type="hidden" name="storage.type" value="alist">
|
||||
|
||||
<div class="layui-form-item text-center padding-left-40">
|
||||
<button class="layui-btn" type="submit">保存配置</button>
|
||||
<button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消修改吗?" data-close>取消修改</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
@ -44,7 +44,7 @@
|
||||
<a class="input-right-icon layui-icon layui-icon-refresh" id="RefreshJwtKey"></a>
|
||||
</label>
|
||||
<div class="help-block sub-span-blue">
|
||||
请输入 <span>32</span> 位 <span>JWT</span> 接口密钥,在使用 <span>JWT</span> 接口时需要使用其密钥进行加密及签名!
|
||||
请输入 <span>32</span> 位 <span>JWT</span> 接口密钥,在使用 <span>JWT</span> 接口时需要使用此密钥进行加密及签名!
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -83,7 +83,7 @@
|
||||
</div>
|
||||
<div class="layui-col-xs4 padding-top-0 padding-bottom-0">
|
||||
<label class="relative block">
|
||||
<span class="help-label"><b>公网安备号</b>Baian</span>
|
||||
<span class="help-label"><b>公网安备号</b>Beian</span>
|
||||
<input name="beian" placeholder="请输入公网安备号" value="{:sysconf('beian')}" class="layui-input">
|
||||
</label>
|
||||
</div>
|
||||
|
@ -33,7 +33,7 @@
|
||||
{
|
||||
field: 'xurl', title: '查看文件', width: '7%', align: 'center', templet: function (d) {
|
||||
if (typeof d.mime === 'string' && /^image\//.test(d.mime)) {
|
||||
return laytpl('<div class="headimg headimg-no headimg-ss margin-0" data-tips-hover data-tips-image="{{d.xurl}}" style="background-image:url({{d.xurl}})"></div>').render(d)
|
||||
return laytpl('<div><a target="_blank" data-tips-hover data-tips-image="{{d.xurl}}"><i class="layui-icon layui-icon-eye"></i></a></div>').render(d)
|
||||
} else if (typeof d.mime === 'string' && /^(video|audio)\//.test(d.mime)) {
|
||||
return laytpl('<div><a target="_blank" data-iframe="{{d.xurl}}" data-title="查看媒体">查看</a></div>').render(d);
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user