mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-03 10:16:56 +00:00
feat: 检查应用是否已安装
This commit is contained in:
parent
5ccaa8f106
commit
270ddc6487
@ -35,9 +35,7 @@ class ApproveController extends AbstractController
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (!Apps::isInstalled('approve')) {
|
||||
throw new ApiException('应用「Approval」未安装');
|
||||
}
|
||||
Apps::isInstalledThrow('approve');
|
||||
$this->flow_url = env('FLOW_URL') ?: 'http://approve';
|
||||
}
|
||||
|
||||
@ -77,7 +75,7 @@ class ApproveController extends AbstractController
|
||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||
* @apiSuccess {Object} data 返回数据
|
||||
*/
|
||||
public function procdef__all()
|
||||
public function procdef__all()
|
||||
{
|
||||
User::auth();
|
||||
$data['name'] = Request::input('name');
|
||||
|
||||
@ -11,7 +11,6 @@ use App\Models\FileContent;
|
||||
use App\Models\FileLink;
|
||||
use App\Models\FileUser;
|
||||
use App\Models\User;
|
||||
use App\Module\Apps;
|
||||
use App\Module\Base;
|
||||
use App\Module\Timer;
|
||||
use App\Module\Ihttp;
|
||||
@ -504,29 +503,16 @@ class FileController extends AbstractController
|
||||
return Base::retError('参数错误');
|
||||
}
|
||||
//
|
||||
if ($down == 'no') {
|
||||
File::isNeedInstallApp($file->type);
|
||||
}
|
||||
//
|
||||
if ($only_update_at == 'yes') {
|
||||
return Base::retSuccess('success', [
|
||||
'id' => $file->id,
|
||||
'update_at' => Carbon::parse($file->updated_at)->toDateTimeString()
|
||||
]);
|
||||
}
|
||||
//
|
||||
if ($down != 'yes') {
|
||||
// office
|
||||
if (in_array($file->type, ['word', 'excel', 'ppt']) && !Apps::isInstalled('office')) {
|
||||
return Base::retError('应用「OnlyOffice」未安装');
|
||||
}
|
||||
// drawio
|
||||
if ($file->type == 'drawio' && !Apps::isInstalled('drawio')) {
|
||||
return Base::retError('应用「Drawio」未安装');
|
||||
}
|
||||
// mind
|
||||
if ($file->type == 'mind' && !Apps::isInstalled('minder')) {
|
||||
return Base::retError('应用「Minder」未安装');
|
||||
}
|
||||
}
|
||||
//
|
||||
|
||||
//
|
||||
$builder = FileContent::whereFid($file->id);
|
||||
if ($history_id > 0) {
|
||||
@ -595,16 +581,12 @@ class FileController extends AbstractController
|
||||
$contentArray = Base::json2array($content);
|
||||
$contentString = $contentArray['xml'];
|
||||
$file->ext = 'drawio';
|
||||
if (!Apps::isInstalled('drawio')) {
|
||||
return Base::retError('应用「Drawio」未安装');
|
||||
}
|
||||
File::isNeedInstallApp($file->type);
|
||||
break;
|
||||
case 'mind':
|
||||
$contentString = $content;
|
||||
$file->ext = 'mind';
|
||||
if (!Apps::isInstalled('minder')) {
|
||||
return Base::retError('应用「Minder」未安装');
|
||||
}
|
||||
File::isNeedInstallApp($file->type);
|
||||
break;
|
||||
case 'txt':
|
||||
case 'code':
|
||||
@ -656,9 +638,7 @@ class FileController extends AbstractController
|
||||
{
|
||||
User::auth();
|
||||
//
|
||||
if (!Apps::isInstalled('office')) {
|
||||
return Base::retError('应用「OnlyOffice」未安装');
|
||||
}
|
||||
File::isNeedInstallApp('office');
|
||||
//
|
||||
$config = Request::input('config');
|
||||
$token = \Firebase\JWT\JWT::encode($config, env('APP_KEY') ,'HS256');
|
||||
@ -685,9 +665,7 @@ class FileController extends AbstractController
|
||||
{
|
||||
$user = User::auth();
|
||||
//
|
||||
if (!Apps::isInstalled('office')) {
|
||||
return Base::retError('应用「OnlyOffice」未安装');
|
||||
}
|
||||
File::isNeedInstallApp('office');
|
||||
//
|
||||
$id = intval(Request::input('id'));
|
||||
$status = intval(Request::input('status'));
|
||||
@ -808,19 +786,8 @@ class FileController extends AbstractController
|
||||
$history_id = intval(Request::input('history_id'));
|
||||
//
|
||||
$file = File::permissionFind($id, $user);
|
||||
// office
|
||||
if (in_array($file->type, ['word', 'excel', 'ppt']) && !Apps::isInstalled('office')) {
|
||||
return Base::retError('应用「OnlyOffice」未安装');
|
||||
}
|
||||
// drawio
|
||||
if ($file->type == 'drawio' && !Apps::isInstalled('drawio')) {
|
||||
return Base::retError('应用「Drawio」未安装');
|
||||
}
|
||||
// mind
|
||||
if ($file->type == 'mind' && !Apps::isInstalled('minder')) {
|
||||
return Base::retError('应用「Minder」未安装');
|
||||
}
|
||||
|
||||
//
|
||||
File::isNeedInstallApp($file->type);
|
||||
//
|
||||
$history = FileContent::whereFid($file->id)->whereId($history_id)->first();
|
||||
if (empty($history)) {
|
||||
|
||||
@ -41,7 +41,6 @@ use App\Models\ProjectTaskFlowChange;
|
||||
use App\Models\ProjectTaskVisibilityUser;
|
||||
use App\Models\ProjectTaskTemplate;
|
||||
use App\Models\ProjectTag;
|
||||
use App\Module\Apps;
|
||||
|
||||
/**
|
||||
* @apiDefine project
|
||||
@ -1832,18 +1831,7 @@ class ProjectController extends AbstractController
|
||||
'update_at' => Carbon::parse($file->updated_at)->toDateTimeString()
|
||||
]);
|
||||
}
|
||||
// office
|
||||
if (in_array($file->ext, ['docx', 'xlsx', 'pptx']) && !Apps::isInstalled('office')) {
|
||||
return Base::retError('应用「OnlyOffice」未安装');
|
||||
}
|
||||
// drawio
|
||||
if ($file->ext == 'drawio' && !Apps::isInstalled('drawio')) {
|
||||
return Base::retError('应用「Drawio」未安装');
|
||||
}
|
||||
// mind
|
||||
if ($file->ext == 'mind' && !Apps::isInstalled('minder')) {
|
||||
return Base::retError('应用「Minder」未安装');
|
||||
}
|
||||
File::isNeedInstallApp($file->ext);
|
||||
//
|
||||
$data = $file->toArray();
|
||||
$data['path'] = $file->getRawOriginal('path');
|
||||
|
||||
@ -302,9 +302,7 @@ class SystemController extends AbstractController
|
||||
{
|
||||
User::auth('admin');
|
||||
//
|
||||
if (!Apps::isInstalled('ai')) {
|
||||
return Base::retError('应用「AI Robot」未安装');
|
||||
}
|
||||
Apps::isInstalledThrow('ai');
|
||||
//
|
||||
$type = trim(Request::input('type'));
|
||||
$filter = trim(Request::input('filter'));
|
||||
@ -469,11 +467,9 @@ class SystemController extends AbstractController
|
||||
}
|
||||
}
|
||||
// 人脸识别
|
||||
if (in_array('face', $all['modes'])){
|
||||
if (!Apps::isInstalled('face')) {
|
||||
return Base::retError('应用「Face check-in」未安装');
|
||||
}
|
||||
}
|
||||
if (in_array('face', $all['modes'])) {
|
||||
Apps::isInstalledThrow('face');
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($all['modes']) {
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Request;
|
||||
use App\Module\Apps;
|
||||
use App\Module\Base;
|
||||
use App\Tasks\PushTask;
|
||||
use App\Exceptions\ApiException;
|
||||
@ -978,4 +979,41 @@ class File extends AbstractModel
|
||||
];
|
||||
Task::deliver(new PushTask($params));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文件类型判断是否需要安装应用
|
||||
* @param $type
|
||||
* @return void
|
||||
*/
|
||||
public static function isNeedInstallApp($type): void
|
||||
{
|
||||
// 文件类型与应用的映射配置
|
||||
$fileTypeAppMapping = [
|
||||
// Office 应用映射
|
||||
[
|
||||
'types' => ['word', 'excel', 'ppt', 'docx', 'xlsx', 'pptx'],
|
||||
'app_id' => 'office',
|
||||
'app_name' => 'OnlyOffice'
|
||||
],
|
||||
// Drawio 应用映射
|
||||
[
|
||||
'types' => ['drawio'],
|
||||
'app_id' => 'drawio',
|
||||
'app_name' => 'Drawio'
|
||||
],
|
||||
// Minder 应用映射
|
||||
[
|
||||
'types' => ['mind'],
|
||||
'app_id' => 'minder',
|
||||
'app_name' => 'Minder'
|
||||
]
|
||||
];
|
||||
|
||||
// 遍历配置检查是否需要安装应用
|
||||
foreach ($fileTypeAppMapping as $config) {
|
||||
if (in_array($type, $config['types'])) {
|
||||
Apps::isInstalledThrow($config['app_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Module;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Services\RequestContext;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
@ -33,4 +34,26 @@ class Apps
|
||||
|
||||
return RequestContext::save($key, $installed);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断应用是否已安装,如果未安装则抛出异常
|
||||
* @param string $appId
|
||||
* @return void
|
||||
*/
|
||||
public static function isInstalledThrow(string $appId): void
|
||||
{
|
||||
if (!self::isInstalled($appId)) {
|
||||
$name = match ($appId) {
|
||||
'ai' => 'AI Robot',
|
||||
'face' => 'Face check-in',
|
||||
'appstore' => 'AppStore',
|
||||
'approve' => 'Approval',
|
||||
'office' => 'OnlyOffice',
|
||||
'drawio' => 'Drawio',
|
||||
'minder' => 'Minder',
|
||||
default => $appId,
|
||||
};
|
||||
throw new ApiException("应用「{$name}」未安装");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user