Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hexbee
Cloudreve
提交
732d04c0
C
Cloudreve
项目概览
hexbee
/
Cloudreve
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Cloudreve
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
732d04c0
编写于
9月 07, 2018
作者:
H
HFO4
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add QiniuAdapter
上级
6593cb7d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
148 addition
and
81 deletion
+148
-81
application/index/model/FileManage.php
application/index/model/FileManage.php
+6
-81
application/index/model/LocalAdapter.php
application/index/model/LocalAdapter.php
+5
-0
application/index/model/QiniuAdapter.php
application/index/model/QiniuAdapter.php
+137
-0
未找到文件。
application/index/model/FileManage.php
浏览文件 @
732d04c0
<?php
namespace
app\index\model
;
require_once
'extend/Qiniu/functions.php'
;
use
think\Model
;
use
think\Db
;
use
think\Validate
;
use
Qiniu\Auth
;
use
\
app\index\model\Option
;
use
OSS\OssClient
;
use
OSS\Core\OssException
;
...
...
@@ -53,7 +50,9 @@ class FileManage extends Model{
case
'local'
:
$this
->
adapter
=
new
\
app\index\model\LocalAdapter
(
$this
->
fileData
,
$this
->
policyData
,
$this
->
userData
);
break
;
case
'qiniu'
:
$this
->
adapter
=
new
\
app\index\model\QiniuAdapter
(
$this
->
fileData
,
$this
->
policyData
,
$this
->
userData
);
break
;
default
:
# code...
break
;
...
...
@@ -116,16 +115,6 @@ class FileManage extends Model{
}
}
/**
* 获取七牛策略文本文件内容
*
* @return string 文件内容
*/
public
function
getQiniuFileContent
(){
return
file_get_contents
(
$this
->
qiniuPreview
()[
1
]);
}
/**
* 获取OSS策略文本文件内容
*
...
...
@@ -206,26 +195,6 @@ class FileManage extends Model{
echo
(
'{ "result": { "success": true} }'
);
}
/**
* 保存七牛文件内容
*
* @param string $content 文件内容
* @return bool
*/
public
function
saveQiniuContent
(
$content
){
$auth
=
new
Auth
(
$this
->
policyData
[
"ak"
],
$this
->
policyData
[
"sk"
]);
$expires
=
3600
;
$keyToOverwrite
=
$this
->
fileData
[
"pre_name"
];
$upToken
=
$auth
->
uploadToken
(
$this
->
policyData
[
"bucketname"
],
$keyToOverwrite
,
$expires
,
null
,
true
);
$uploadMgr
=
new
\
Qiniu\Storage\UploadManager
();
list
(
$ret
,
$err
)
=
$uploadMgr
->
put
(
$upToken
,
$keyToOverwrite
,
$content
);
if
(
$err
!==
null
)
{
die
(
'{ "result": { "success": false, "error": "编辑失败" } }'
);
}
else
{
return
true
;
}
}
/**
* 保存OSS文件内容
*
...
...
@@ -659,7 +628,8 @@ class FileManage extends Model{
}
foreach
(
$fileListTemp
as
$key
=>
$value
)
{
if
(
in_array
(
$key
,
$uniquePolicy
[
"qiniuList"
])){
self
::
qiniuDelete
(
$value
,
$uniquePolicy
[
"qiniuPolicyData"
][
$key
][
0
]);
QiniuAdapter
::
DeleteFile
(
$value
,
$uniquePolicy
[
"qiniuPolicyData"
][
$key
][
0
]);
self
::
deleteFileRecord
(
array_column
(
$value
,
'id'
),
array_sum
(
array_column
(
$value
,
'size'
)),
$value
[
0
][
"upload_user"
]);
}
else
if
(
in_array
(
$key
,
$uniquePolicy
[
"localList"
])){
LocalAdapter
::
DeleteFile
(
$value
,
$uniquePolicy
[
"localPolicyData"
][
$key
][
0
]);
self
::
deleteFileRecord
(
array_column
(
$value
,
'id'
),
array_sum
(
array_column
(
$value
,
'size'
)),
$value
[
0
][
"upload_user"
]);
...
...
@@ -742,23 +712,6 @@ class FileManage extends Model{
}
/**
* 删除某一策略下的指定七牛文件
*
* @param array $fileList 待删除文件的数据库记录
* @param array $policyData 待删除文件的上传策略信息
* @return void
*/
static
function
qiniuDelete
(
$fileList
,
$policyData
){
$auth
=
new
Auth
(
$policyData
[
"ak"
],
$policyData
[
"sk"
]);
$config
=
new
\
Qiniu\Config
();
$bucketManager
=
new
\
Qiniu\Storage\BucketManager
(
$auth
);
$fileListTemp
=
array_column
(
$fileList
,
'pre_name'
);
$ops
=
$bucketManager
->
buildBatchDelete
(
$policyData
[
"bucketname"
],
$fileListTemp
);
list
(
$ret
,
$err
)
=
$bucketManager
->
batch
(
$ops
);
self
::
deleteFileRecord
(
array_column
(
$fileList
,
'id'
),
array_sum
(
array_column
(
$fileList
,
'size'
)),
$fileList
[
0
][
"upload_user"
]);
}
/**
* 删除某一策略下的指定OSS文件
*
...
...
@@ -847,10 +800,6 @@ class FileManage extends Model{
}
}
public
function
getQiniuThumb
(){
return
$this
->
qiniuPreview
(
"?imageView2/2/w/90/h/39"
);
}
private
function
getUpyunThumb
(){
$picInfo
=
explode
(
","
,
$this
->
fileData
[
"pic_info"
]);
$thumbSize
=
self
::
getThumbSize
(
$picInfo
[
0
],
$picInfo
[
1
]);
...
...
@@ -892,18 +841,6 @@ class FileManage extends Model{
}
}
public
function
qiniuPreview
(
$thumb
=
null
){
if
(
!
$this
->
policyData
[
'bucket_private'
]){
$fileUrl
=
$this
->
policyData
[
"url"
]
.
$this
->
fileData
[
"pre_name"
]
.
$thumb
;
return
[
true
,
$fileUrl
];
}
else
{
$auth
=
new
Auth
(
$this
->
policyData
[
"ak"
],
$this
->
policyData
[
"sk"
]);
$baseUrl
=
$this
->
policyData
[
"url"
]
.
$this
->
fileData
[
"pre_name"
]
.
$thumb
;
$signedUrl
=
$auth
->
privateDownloadUrl
(
$baseUrl
);
return
[
true
,
$signedUrl
];
}
}
public
function
ossPreview
(){
if
(
!
$this
->
policyData
[
'bucket_private'
]){
$fileUrl
=
$this
->
policyData
[
"url"
]
.
$this
->
fileData
[
"pre_name"
];
...
...
@@ -1142,7 +1079,7 @@ class FileManage extends Model{
static
function
deleteFile
(
$fname
,
$policy
){
switch
(
$policy
[
'policy_type'
])
{
case
'qiniu'
:
return
self
::
deleteQiniuFi
le
(
$fname
,
$policy
);
return
QiniuAdapter
::
deleteSing
le
(
$fname
,
$policy
);
break
;
case
'oss'
:
return
self
::
deleteOssFile
(
$fname
,
$policy
);
...
...
@@ -1159,18 +1096,6 @@ class FileManage extends Model{
}
}
static
function
deleteQiniuFile
(
$fname
,
$policy
){
$auth
=
new
Auth
(
$policy
[
"ak"
],
$policy
[
"sk"
]);
$config
=
new
\
Qiniu\Config
();
$bucketManager
=
new
\
Qiniu\Storage\BucketManager
(
$auth
);
$err
=
$bucketManager
->
delete
(
$policy
[
"bucketname"
],
$fname
);
if
(
$err
)
{
return
false
;
}
else
{
return
true
;
}
}
static
function
deleteOssFile
(
$fname
,
$policy
){
$accessKeyId
=
$policy
[
"ak"
];
$accessKeySecret
=
$policy
[
"sk"
];
...
...
application/index/model/LocalAdapter.php
浏览文件 @
732d04c0
...
...
@@ -374,6 +374,11 @@ class LocalAdapter extends Model{
}
}
/**
* 签名临时直链,用于Office365预览
*
* @return array
*/
public
function
signTmpUrl
(){
$options
=
Option
::
getValues
([
"oss"
,
"basic"
]);
$timeOut
=
$options
[
"timeout"
];
...
...
application/index/model/QiniuAdapter.php
0 → 100644
浏览文件 @
732d04c0
<?php
namespace
app\index\model
;
use
think\Model
;
use
think\Db
;
require_once
'extend/Qiniu/functions.php'
;
use
Qiniu\Auth
;
use
\
app\index\model\Option
;
/**
* 七牛策略文件管理适配器
*/
class
QiniuAdapter
extends
Model
{
private
$fileModel
;
private
$policyModel
;
private
$userModel
;
public
function
__construct
(
$file
,
$policy
,
$user
){
$this
->
fileModel
=
$file
;
$this
->
policyModel
=
$policy
;
$this
->
userModel
=
$user
;
}
/**
* 获取文本文件内容
*
* @return string 文件内容
*/
public
function
getFileContent
(){
return
file_get_contents
(
$this
->
Preview
()[
1
]);
}
/**
* 签名七牛文件预览URL
*
* @param string $thumb 缩略图参数
* @return void
*/
public
function
Preview
(
$thumb
=
null
){
if
(
!
$this
->
policyModel
[
'bucket_private'
]){
$fileUrl
=
$this
->
policyModel
[
"url"
]
.
$this
->
fileModel
[
"pre_name"
]
.
$thumb
;
return
[
true
,
$fileUrl
];
}
else
{
$auth
=
new
Auth
(
$this
->
policyModel
[
"ak"
],
$this
->
policyModel
[
"sk"
]);
$baseUrl
=
$this
->
policyModel
[
"url"
]
.
$this
->
fileModel
[
"pre_name"
]
.
$thumb
;
$signedUrl
=
$auth
->
privateDownloadUrl
(
$baseUrl
);
return
[
true
,
$signedUrl
];
}
}
/**
* 保存七牛文件内容
*
* @param string $content 文件内容
* @return bool
*/
public
function
saveContent
(
$content
){
$auth
=
new
Auth
(
$this
->
policyModel
[
"ak"
],
$this
->
policyModel
[
"sk"
]);
$expires
=
3600
;
$keyToOverwrite
=
$this
->
fileModel
[
"pre_name"
];
$upToken
=
$auth
->
uploadToken
(
$this
->
policyModel
[
"bucketname"
],
$keyToOverwrite
,
$expires
,
null
,
true
);
$uploadMgr
=
new
\
Qiniu\Storage\UploadManager
();
list
(
$ret
,
$err
)
=
$uploadMgr
->
put
(
$upToken
,
$keyToOverwrite
,
$content
);
if
(
$err
!==
null
)
{
die
(
'{ "result": { "success": false, "error": "编辑失败" } }'
);
}
else
{
return
true
;
}
}
/**
* 获取缩略图地址
*
* @return string 缩略图地址
*/
public
function
getThumb
(){
return
$this
->
Preview
(
"?imageView2/2/w/90/h/39"
);
}
/**
* 删除某一策略下的指定七牛文件
*
* @param array $fileList 待删除文件的数据库记录
* @param array $policyData 待删除文件的上传策略信息
* @return void
*/
static
function
deleteFile
(
$fileList
,
$policyData
){
$auth
=
new
Auth
(
$policyData
[
"ak"
],
$policyData
[
"sk"
]);
$config
=
new
\
Qiniu\Config
();
$bucketManager
=
new
\
Qiniu\Storage\BucketManager
(
$auth
);
$fileListTemp
=
array_column
(
$fileList
,
'pre_name'
);
$ops
=
$bucketManager
->
buildBatchDelete
(
$policyData
[
"bucketname"
],
$fileListTemp
);
list
(
$ret
,
$err
)
=
$bucketManager
->
batch
(
$ops
);
}
/**
* 生成文件下载URL
*
* @return array
*/
public
function
Download
(){
if
(
!
$this
->
policyModel
[
'bucket_private'
]){
$fileUrl
=
$this
->
policyModel
[
"url"
]
.
$this
->
fileModel
[
"pre_name"
]
.
"?attname="
.
urlencode
(
$this
->
fileModel
[
"orign_name"
]);
return
[
true
,
$fileUrl
];
}
else
{
$auth
=
new
Auth
(
$this
->
policyModel
[
"ak"
],
$this
->
policyModel
[
"sk"
]);
$baseUrl
=
$this
->
policyModel
[
"url"
]
.
$this
->
fileModel
[
"pre_name"
]
.
"?attname="
.
urlencode
(
$this
->
fileModel
[
"orign_name"
]);
$signedUrl
=
$auth
->
privateDownloadUrl
(
$baseUrl
);
return
[
true
,
$signedUrl
];
}
}
/**
* 删除临时文件
*
* @param string $fname 文件名
* @param array $policy 上传策略信息
* @return void
*/
static
function
deleteSingle
(
$fname
,
$policy
){
$auth
=
new
Auth
(
$policy
[
"ak"
],
$policy
[
"sk"
]);
$config
=
new
\
Qiniu\Config
();
$bucketManager
=
new
\
Qiniu\Storage\BucketManager
(
$auth
);
$err
=
$bucketManager
->
delete
(
$policy
[
"bucketname"
],
$fname
);
if
(
$err
)
{
return
false
;
}
else
{
return
true
;
}
}
}
?>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录