diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index 5b1f279c..4d85b201 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Api; +use App\Models\File; use App\Models\ProjectTask; use App\Models\ProjectTaskFile; use App\Models\User; @@ -393,31 +394,13 @@ class DialogController extends AbstractController $data = $dialogMsg->toArray(); // if ($data['type'] == 'file') { - $codeExt = ['txt']; - $officeExt = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx']; - $localExt = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'ico', 'raw', 'tif', 'tiff', 'mp3', 'wav', 'mp4', 'flv', 'avi', 'mov', 'wmv', 'mkv', '3gp', 'rm']; $msg = Base::json2array($dialogMsg->getRawOriginal('msg')); - $filePath = public_path($msg['path']); - if (in_array($msg['ext'], $codeExt) && $msg['size'] < 2 * 1024 * 1024) { - // 文本预览,限制2M内的文件 - $data['content'] = file_get_contents($filePath); - $data['file_mode'] = 1; - } elseif (in_array($msg['ext'], $officeExt)) { - // office预览 - $data['file_mode'] = 2; - } else { - // 其他预览 - if (in_array($msg['ext'], $localExt)) { - $url = Base::fillUrl($msg['path']); - } else { - $url = 'http://' . env('APP_IPPR') . '.3/' . $msg['path']; - } - $data['url'] = base64_encode($url); - $data['file_mode'] = 3; - } + $msg = File::formatFileData($msg); + $data['content'] = $msg['content']; + $data['file_mode'] = $msg['file_mode']; } // - return Base::retSuccess("success", $data); + return Base::retSuccess('success', $data); } /** diff --git a/app/Http/Controllers/Api/FileController.php b/app/Http/Controllers/Api/FileController.php index 2afb1c29..8889f314 100755 --- a/app/Http/Controllers/Api/FileController.php +++ b/app/Http/Controllers/Api/FileController.php @@ -516,40 +516,41 @@ class FileController extends AbstractController } } // - $contentArray = Base::json2array($content); switch ($file->type) { case 'document': - $file->ext = $contentArray['type'] ?: 'md'; + $contentArray = Base::json2array($content); $contentString = $contentArray['content']; + $file->ext = $contentArray['type'] == 'md' ? 'md' : 'text'; break; case 'drawio': - $file->ext = 'drawio'; + $contentArray = Base::json2array($content); $contentString = $contentArray['xml']; + $file->ext = 'drawio'; break; case 'mind': + $contentString = $content; $file->ext = 'mind'; + break; + case 'code': + case 'txt': $contentString = $content; break; + default: + return Base::retError('参数错误'); } - if (isset($contentString)) { - $path = "uploads/file/" . $file->type . "/" . date("Ym") . "/" . $id . "/" . md5($contentString); - $save = public_path($path); - Base::makeDir(dirname($save)); - file_put_contents($save, $contentString); - $content = [ - 'type' => $file->ext, - 'url' => $path - ]; - $size = filesize($save); - } else { - $size = strlen($content); - } + $path = "uploads/file/" . $file->type . "/" . date("Ym") . "/" . $id . "/" . md5($contentString); + $save = public_path($path); + Base::makeDir(dirname($save)); + file_put_contents($save, $contentString); // $content = FileContent::createInstance([ 'fid' => $file->id, - 'content' => $content, + 'content' => [ + 'type' => $file->ext, + 'url' => $path + ], 'text' => $text, - 'size' => $size, + 'size' => filesize($save), 'userid' => $user->userid, ]); $content->save(); diff --git a/app/Http/Controllers/Api/ProjectController.php b/app/Http/Controllers/Api/ProjectController.php index cf8328f6..ab670fbf 100755 --- a/app/Http/Controllers/Api/ProjectController.php +++ b/app/Http/Controllers/Api/ProjectController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api; use App\Exceptions\ApiException; use App\Models\AbstractModel; +use App\Models\File; use App\Models\Project; use App\Models\ProjectColumn; use App\Models\ProjectFlow; @@ -1132,29 +1133,7 @@ class ProjectController extends AbstractController // ProjectTask::userTask($file->task_id, null); // - $codeExt = ['txt']; - $officeExt = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx']; - $localExt = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'ico', 'raw', 'tif', 'tiff', 'mp3', 'wav', 'mp4', 'flv', 'avi', 'mov', 'wmv', 'mkv', '3gp', 'rm']; - $filePath = public_path($data['path']); - if (in_array($data['ext'], $codeExt) && $data['size'] < 2 * 1024 * 1024) { - // 文本预览,限制2M内的文件 - $data['content'] = file_get_contents($filePath); - $data['file_mode'] = 1; - } elseif (in_array($data['ext'], $officeExt)) { - // office预览 - $data['file_mode'] = 2; - } else { - // 其他预览 - if (in_array($data['ext'], $localExt)) { - $url = Base::fillUrl($data['path']); - } else { - $url = 'http://' . env('APP_IPPR') . '.3/' . $data['path']; - } - $data['url'] = base64_encode($url); - $data['file_mode'] = 3; - } - // - return Base::retSuccess('success', $data); + return Base::retSuccess('success', File::formatFileData($data)); } /** diff --git a/app/Models/File.php b/app/Models/File.php index 5cddb8f1..c5e9b84a 100644 --- a/app/Models/File.php +++ b/app/Models/File.php @@ -50,6 +50,39 @@ class File extends AbstractModel { use SoftDeletes; + /** + * 文件文件 + */ + const codeExt = [ + 'txt', + 'htaccess', 'htgroups', 'htpasswd', 'conf', 'bat', 'cmd', 'cpp', 'c', 'cc', 'cxx', 'h', 'hh', 'hpp', 'ino', 'cs', 'css', + 'dockerfile', 'go', 'html', 'htm', 'xhtml', 'vue', 'we', 'wpy', 'java', 'js', 'jsm', 'jsx', 'json', 'jsp', 'less', 'lua', 'makefile', 'gnumakefile', + 'ocamlmakefile', 'make', 'mysql', 'nginx', 'ini', 'cfg', 'prefs', 'm', 'mm', 'pl', 'pm', 'p6', 'pl6', 'pm6', 'pgsql', 'php', + 'inc', 'phtml', 'shtml', 'php3', 'php4', 'php5', 'phps', 'phpt', 'aw', 'ctp', 'module', 'ps1', 'py', 'r', 'rb', 'ru', 'gemspec', 'rake', 'guardfile', 'rakefile', + 'gemfile', 'rs', 'sass', 'scss', 'sh', 'bash', 'bashrc', 'sql', 'sqlserver', 'swift', 'ts', 'typescript', 'str', 'vbs', 'vb', 'v', 'vh', 'sv', 'svh', 'xml', + 'rdf', 'rss', 'wsdl', 'xslt', 'atom', 'mathml', 'mml', 'xul', 'xbl', 'xaml', 'yaml', 'yml', + 'asp', 'properties', 'gitignore', 'log', 'bas', 'prg', 'python', 'ftl', 'aspx' + ]; + + /** + * office文件 + */ + const officeExt = [ + 'doc', 'docx', + 'xls', 'xlsx', + 'ppt', 'pptx', + ]; + + /** + * 本地媒体文件 + */ + const localExt = [ + 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'ico', 'raw', + 'tif', 'tiff', + 'mp3', 'wav', 'mp4', 'flv', + 'avi', 'mov', 'wmv', 'mkv', '3gp', 'rm', + ]; + /** * 是否有访问权限 * @param $userid @@ -239,4 +272,76 @@ class File extends AbstractModel } return $file; } + + /** + * 格式化内容数据 + * @param array $data [path, ext, size, name] + * @return array + */ + public static function formatFileData(array $data) + { + $filePath = $data['path']; + $fileExt = $data['ext']; + $fileSize = $data['size']; + $fileName = $data['name']; + $publicPath = public_path($filePath); + // + switch ($fileExt) { + case 'md': + case 'text': + // 文本 + $data['content'] = [ + 'type' => $fileExt, + 'content' => file_get_contents($publicPath), + ]; + $data['file_mode'] = $fileExt; + break; + + case 'drawio': + // 图表 + $data['content'] = [ + 'xml' => file_get_contents($publicPath) + ]; + $data['file_mode'] = $fileExt; + break; + + case 'mind': + // 思维导图 + $data['content'] = Base::json2array(file_get_contents($publicPath)); + $data['file_mode'] = $fileExt; + break; + + default: + if (in_array($fileExt, self::codeExt) && $fileSize < 2 * 1024 * 1024) + { + // 文本预览,限制2M内的文件 + $data['content'] = file_get_contents($publicPath); + $data['file_mode'] = 'code'; + } + elseif (in_array($fileExt, File::officeExt)) + { + // office预览 + $data['content'] = ''; + $data['file_mode'] = 'office'; + } + else + { + // 其他预览 + if (in_array($fileExt, File::localExt)) { + $url = Base::fillUrl($filePath); + } else { + $url = 'http://' . env('APP_IPPR') . '.3/' . $filePath; + } + $data['content'] = [ + 'preview' => true, + 'url' => base64_encode(Base::urlAddparameter($url, [ + 'fullfilename' => $fileName + ])), + ]; + $data['file_mode'] = 'preview'; + } + break; + } + return $data; + } } diff --git a/app/Models/FileContent.php b/app/Models/FileContent.php index 45864ed8..df86e574 100644 --- a/app/Models/FileContent.php +++ b/app/Models/FileContent.php @@ -69,48 +69,20 @@ class FileContent extends AbstractModel abort(403, "This file is empty."); } } else { - $content['preview'] = false; + $path = $content['url']; if ($file->ext) { - $filePath = public_path($content['url']); - $fileType = $file->type; - if ($fileType == 'document') - { - // 文本 - $content = [ - 'type' => $file->ext, - 'content' => file_get_contents($filePath) - ]; - } - elseif ($fileType == 'drawio') - { - // 图表 - $content = [ - 'xml' => file_get_contents($filePath) - ]; - } - elseif ($fileType == 'mind') - { - // 思维导图 - $content = Base::json2array(file_get_contents($filePath)); - } - elseif (in_array($fileType, ['txt', 'code']) && $file->size < 2 * 1024 * 1024) - { - // 其他文本和代码(限制2M内的文件,支持编辑) - $content['content'] = file_get_contents($filePath); - } - else - { - // 支持预览 - if (in_array($fileType, ['picture', 'image', 'tif', 'media'])) { - $url = Base::fillUrl($content['url']); - } else { - $url = 'http://' . env('APP_IPPR') . '.3/' . $content['url']; - } - $content['url'] = base64_encode($url); - $content['preview'] = true; - } + $res = File::formatFileData([ + 'path' => $path, + 'ext' => $file->ext, + 'size' => $file->size, + 'name' => $file->name, + ]); + $content = $res['content']; + } else { + $content['preview'] = false; } if ($download) { + $filePath = public_path($path); if (isset($filePath)) { return Response::download($filePath, $name); } else { diff --git a/app/Module/Base.php b/app/Module/Base.php index 2e64c3be..6de39b29 100755 --- a/app/Module/Base.php +++ b/app/Module/Base.php @@ -812,6 +812,31 @@ class Base return $scheme.($_SERVER['HTTP_HOST'] ?? ''); } + /** + * 地址后拼接参数 + * @param $url + * @param $parames + * @return mixed|string + */ + public static function urlAddparameter($url, $parames) + { + if ($parames && is_array($parames)) { + $array = []; + foreach ($parames as $key => $val) { + $array[] = $key . "=" . $val; + } + if ($array) { + $query = implode("&", $array); + if (str_contains($url, "?")) { + $url .= "&" . $query; + } else { + $url .= "?" . $query; + } + } + } + return $url; + } + /** * 格式化内容图片地址 * @param $content diff --git a/resources/assets/js/pages/manage/components/DialogView.vue b/resources/assets/js/pages/manage/components/DialogView.vue index 0215fa48..51e3bbbf 100644 --- a/resources/assets/js/pages/manage/components/DialogView.vue +++ b/resources/assets/js/pages/manage/components/DialogView.vue @@ -216,6 +216,7 @@ export default { this.$Electron.sendMessage('windowRouter', { name: 'file-msg-' + this.msgData.id, path: "/single/file/msg/" + this.msgData.id, + userAgent: "/hideenOfficeTitle/", force: false, config: { title: `${this.msgData.msg.name} (${$A.bytesToSize(this.msgData.msg.size)})`, diff --git a/resources/assets/js/pages/manage/components/FileContent.vue b/resources/assets/js/pages/manage/components/FileContent.vue index 7da28a12..b2624730 100644 --- a/resources/assets/js/pages/manage/components/FileContent.vue +++ b/resources/assets/js/pages/manage/components/FileContent.vue @@ -52,8 +52,8 @@ + -
diff --git a/resources/assets/js/pages/manage/components/FilePreview.vue b/resources/assets/js/pages/manage/components/FilePreview.vue index b70a9a92..6314a6f8 100644 --- a/resources/assets/js/pages/manage/components/FilePreview.vue +++ b/resources/assets/js/pages/manage/components/FilePreview.vue @@ -25,12 +25,12 @@
- - - - + + + +
diff --git a/resources/assets/js/pages/manage/components/TaskDetail.vue b/resources/assets/js/pages/manage/components/TaskDetail.vue index 6c597990..1c55d266 100644 --- a/resources/assets/js/pages/manage/components/TaskDetail.vue +++ b/resources/assets/js/pages/manage/components/TaskDetail.vue @@ -1164,6 +1164,7 @@ export default { this.$Electron.sendMessage('windowRouter', { name: 'file-task-' + file.id, path: "/single/file/task/" + file.id, + userAgent: "/hideenOfficeTitle/", force: false, config: { title: `${file.name} (${$A.bytesToSize(file.size)})`, diff --git a/resources/assets/js/pages/single/fileMsg.vue b/resources/assets/js/pages/single/fileMsg.vue index 19ae4f05..d7bf6349 100644 --- a/resources/assets/js/pages/single/fileMsg.vue +++ b/resources/assets/js/pages/single/fileMsg.vue @@ -3,9 +3,13 @@