ext ? "{$file->name}.{$file->ext}" : null; $content = Base::json2array($content ?: []); if (in_array($file->type, ['word', 'excel', 'ppt'])) { if (empty($content)) { return Response::download(resource_path('assets/statics/office/empty.' . str_replace(['word', 'excel', 'ppt'], ['docx', 'xlsx', 'pptx'], $file->type)), $name); } return Response::download(public_path($content['url']), $name); } if (empty($content)) { $content = match ($file->type) { 'document' => [ "type" => "md", "content" => "", ], default => json_decode('{}'), }; if ($download) { abort(403, "This file is empty."); } } else { $content['preview'] = false; if ($file->ext) { $filePath = public_path($content['url']); if (in_array($file->type, ['txt', 'code']) && $file->size < 2 * 1024 * 1024) { // 支持编辑,限制2M内的文件 $content['content'] = file_get_contents($filePath); } else { // 支持预览 if (in_array($file->type, ['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; } } if ($download) { if (isset($filePath)) { return Response::download($filePath, $name); } else { abort(403, "This file not support download."); } } } return Base::retSuccess('success', [ 'content' => $content ]); } }