rabin před 4 dny
rodič
revize
96ef86c0d0

+ 4 - 2
app/Api/Save.php

@@ -9,19 +9,21 @@ class Save
     public $cate_id = null;
     public $group_id = null;
     public $user_id = null;
+    public $project = null;
 
     public function __construct()
     {
         $this->id = Dever::input('id', 'is_numeric', '上传规则错误', 1);
         $this->file = Dever::input('file', '!empty', '上传文件错误');
         $this->cate_id = Dever::input('cate_id', 'is_numeric', '上传分类', 1);
+        $this->project = Dever::input('project', 'is_string', '项目', 'api');
         $this->group_id = Dever::load(Util::class)->getGroup();
         $this->user_id = Dever::load(Util::class)->getUser();
     }
 
     public function act()
     {
-        return Dever::load(Service::class)->init($this->id, $this->cate_id, $this->group_id, $this->user_id)->act($this->file);
+        return Dever::load(Service::class)->init($this->id, $this->cate_id, $this->group_id, $this->user_id, $this->project)->act($this->file);
     }
 
     public function wangEditor()
@@ -36,6 +38,6 @@ class Save
     public function avatar()
     {
         $uid = Dever::input('uid', 'is_numeric', '用户ID');
-        return Dever::load(Service::class)->init($this->id, $this->cate_id, $this->group_id, $this->user_id)->act($this->file, 'jpg', $uid);
+        return Dever::load(Service::class)->init($this->id, $this->cate_id, $this->group_id, $this->user_id, $this->project)->act($this->file, 'jpg', $uid);
     }
 }

+ 5 - 4
app/Lib/Save.php

@@ -17,13 +17,14 @@ class Save
         8 => 'exe,msi',
     ];
     private $type = 1;
-    public function init($id, $cate_id = 1, $group_id = false, $user_id = false)
+    public function init($id, $cate_id = 1, $group_id = false, $user_id = false, $project = 'api')
     {
         $this->config = Dever::db('upload/rule')->find($id);
         if (!$this->config) {
             Dever::error('上传规则错误');
         }
-        $this->config['save'] = Dever::db('upload/save')->find($this->config['save_id']);
+        $this->config['save'] = Dever::load(\Upload\Lib\Util::class)->getSaveInfo($this->config['save_id'], $project);
+        //$this->config['save'] = Dever::db('upload/save')->find($this->config['save_id']);
         if (!$this->config['save']) {
             Dever::error('存储位置错误');
         }
@@ -33,9 +34,9 @@ class Save
         return $this;
     }
 
-    public function get($id)
+    public function get($id, $project = 'api')
     {
-        $this->init($id);
+        $this->init($id, 1, false, false, $project);
         $result = [];
         $result['id'] = $id;
         $result['chunkSize'] = $this->config['chunk'];

+ 1 - 1
app/Lib/Tool.php

@@ -15,7 +15,7 @@ class Tool
             Dever::error('存储位置错误');
         }
         $tool = 'Upload\\Lib\\Tool\\' . $save;
-        $tool = new $tool();
+        $tool = Dever::load($tool);
         $tool->init($config);
         return $tool;
     }

+ 12 - 7
app/Lib/Tool/Local.php

@@ -7,6 +7,7 @@ class Local
     public function init($config)
     {
         $this->config = $config;
+
     }
     public function upload($type, $source, $dest, $chunk, $upload)
     {
@@ -33,15 +34,18 @@ class Local
                 $files = scandir($dir);
                 $num = count($files) - 2;
                 if ($num == $chunk['total']) {
-                    $blob = '';
-                    foreach ($files as $k => $v) {
-                        if (strstr($v, '.blob')) {
+                    $out = fopen($chunk['file'], 'ab');
+                    natsort($files);
+                    foreach ($files as $v) {
+                        if (pathinfo($v, PATHINFO_EXTENSION) === 'blob') {
                             $temp = $dir . '/' . $v;
-                            $blob .= file_get_contents($temp);
-                            @unlink($temp);
+                            $in = fopen($temp, 'rb');
+                            stream_copy_to_stream($in, $out); // 边读边写
+                            fclose($in);
+                            @unlink($temp); // 删除分片
                         }
                     }
-                    file_put_contents($chunk['file'], $blob);
+                    fclose($out);
                     @rmdir($dir);
                     $file = $chunk['file'];
                 } else {
@@ -51,6 +55,7 @@ class Local
                 return '';
             }
         }
+
         $after = $upload->after();
         if ($after) {
             $tool = Dever::load(Tool::class)->get()->cover(true);
@@ -67,7 +72,7 @@ class Local
     private function url($file)
     {
         $dest = str_replace(Dever::data() . DEVER_PROJECT . '/', '', $file);
-        if ($this->config['host']) {
+        if (isset($this->config['host']) && $this->config['host']) {
             return $this->config['host'] . $dest;
         }
         return Dever::host() . 'data/' . DEVER_PROJECT . '/' . $dest;

+ 4 - 4
app/Lib/Tool/Qiniu.php

@@ -11,10 +11,10 @@ class Qiniu
     private $host;
     public function init($config)
     {
-        $this->auth = new \Qiniu\Auth($config['appkey'], $config['appsecret']);
-        $this->token = $this->auth->uploadToken($config['bucket'], null, 3600);
-        $this->bucket = $config['bucket'];
-        $this->host = $config['host'];
+        $this->auth = new \Qiniu\Auth($config['setting']['appkey'], $config['setting']['appsecret']);
+        $this->token = $this->auth->uploadToken($config['setting']['bucket'], null, 3600);
+        $this->bucket = $config['setting']['bucket'];
+        $this->host = $config['setting']['host'];
     }
 
     # 获取基本信息

+ 30 - 0
app/Lib/Util.php

@@ -30,4 +30,34 @@ class Util
         }
         return $id;
     }
+
+    # 获取存储位置列表,不再使用save表,直接用万接
+    public function getSaveList()
+    {
+        $data[-1] = '本地存储';
+        $account = Dever::load(\Api\Lib\Account::class)->getList('save');
+        if ($account) {
+            foreach ($account as $k => $v) {
+                $data[$v['id']] = $v['name'];
+            }
+        }
+        return $data;
+    }
+
+    # 获取存储位置信息
+    public function getSaveInfo($id, $project = 'api')
+    {
+        $data['type'] = 1;
+        $data['method'] = 1;
+        if ($id > 0) {
+            $data = Dever::load(\Api\Lib\Account::class)->get($id, $project, true);
+            if ($data['key'] == 'qiniu') {
+                $data['type'] = 2;
+            } elseif ($data['key'] == 'aliyun') {
+                $data['type'] = 3;
+            }
+            $data['method'] = 1;
+        }
+        return $data;
+    }
 }

+ 21 - 4
app/Lib/View.php

@@ -8,14 +8,31 @@ class View
         3 => 'Oss',
     ];
 
-    public function getUrl($info)
+    # 获取源文件信息
+    public function getSource($file, $url = false)
+    {
+        $path = parse_url($file, PHP_URL_PATH);
+        $filename = basename($path);
+        $parts = explode('_', $filename);
+        $pureName = $parts[0];
+        $pureName = pathinfo($pureName, PATHINFO_FILENAME);
+        $info = Dever::db('upload/file')->find(['name' => $pureName]);
+        if ($url) {
+            $file = Dever::load(\Upload\Lib\View::class)->getUrl($info);
+            return $file;
+        }
+        return $info;
+    }
+
+    public function getUrl($info, $project = 'api')
     {
         if (strstr($info['file'], 'http')) {
             return $info['file'];
         }
-        $save = Dever::db('upload/save')->find($info['save_id']);
-        if ($save['host']) {
-            $host = $save['host'];
+        $save = Dever::load(\Upload\Lib\Util::class)->getSaveInfo($info['save_id'], $project);
+        //$save = Dever::db('upload/save')->find($info['save_id']);
+        if (isset($save['setting']['host']) && $save['setting']['host']) {
+            $host = $save['setting']['host'];
             if (strstr($host, '{host}')) {
                 $host = str_replace('{host}', Dever::host(), $host);
             }

+ 2 - 1
manage/core.php

@@ -13,12 +13,13 @@ return [
             'icon'      => 'gallery-upload-line',
             'sort'      => '1',
         ],
+        /* 废弃,用万接
         'save' => [
             'parent'    => 'upload',
             'name'      => '存储位置',
             'icon'      => 'save-line',
             'sort'      => '2',
-        ],
+        ],*/
         'file' => [
             'parent'    => 'upload',
             'name'      => '文件列表',

+ 3 - 1
manage/rule.php

@@ -18,7 +18,9 @@ return [
     'update' => [
         'field'    => [
             'name',
-            'save_id',
+            'save_id' => [
+                'type' => 'radio',
+            ],
             'type' => [
                 'type' => 'checkbox',
                 'control' => true,

+ 1 - 1
manage/rule_after.php

@@ -4,7 +4,7 @@ return [
         'field'    => [
             'type' => [
                 'type' => 'radio',
-                'remote' => 'Upload/Api/Manage.getImage',
+                'remote' => 'Upload/Manage/Api/Manage.getImage',
             ],
             'type_id' => [
                 'name' => '操作配置',

+ 2 - 2
table/group.php

@@ -5,12 +5,12 @@ return [
     'struct' => [
         'name'      => [
             'name'      => '分组名称',
-            'type'      => 'varchar(32)',
+            'type'      => 'varchar(200)',
         ],
 
         'key'      => [
             'name'      => '分组标识',
-            'type'      => 'varchar(32)',
+            'type'      => 'varchar(200)',
         ],
     ],
 ];

+ 3 - 2
table/rule.php

@@ -11,8 +11,9 @@ return [
         'save_id'     => [
             'name'      => '存储位置',
             'type'      => 'int(11)',
-            'default'   => '1',
-            'value'     => 'upload/save',
+            'default'   => '-1',
+            //'value'     => 'upload/save',
+            'value'     => 'Dever::call("Upload/Lib/Util.getSaveList")',
         ],
 
         'type'     => [