mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-23 10:28:13 +00:00
feat: 检查应用是否已安装
This commit is contained in:
parent
5ccaa8f106
commit
270ddc6487
@ -35,9 +35,7 @@ class ApproveController extends AbstractController
|
|||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
if (!Apps::isInstalled('approve')) {
|
Apps::isInstalledThrow('approve');
|
||||||
throw new ApiException('应用「Approval」未安装');
|
|
||||||
}
|
|
||||||
$this->flow_url = env('FLOW_URL') ?: 'http://approve';
|
$this->flow_url = env('FLOW_URL') ?: 'http://approve';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +75,7 @@ class ApproveController extends AbstractController
|
|||||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||||
* @apiSuccess {Object} data 返回数据
|
* @apiSuccess {Object} data 返回数据
|
||||||
*/
|
*/
|
||||||
public function procdef__all()
|
public function procdef__all()
|
||||||
{
|
{
|
||||||
User::auth();
|
User::auth();
|
||||||
$data['name'] = Request::input('name');
|
$data['name'] = Request::input('name');
|
||||||
|
|||||||
@ -11,7 +11,6 @@ use App\Models\FileContent;
|
|||||||
use App\Models\FileLink;
|
use App\Models\FileLink;
|
||||||
use App\Models\FileUser;
|
use App\Models\FileUser;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Module\Apps;
|
|
||||||
use App\Module\Base;
|
use App\Module\Base;
|
||||||
use App\Module\Timer;
|
use App\Module\Timer;
|
||||||
use App\Module\Ihttp;
|
use App\Module\Ihttp;
|
||||||
@ -504,29 +503,16 @@ class FileController extends AbstractController
|
|||||||
return Base::retError('参数错误');
|
return Base::retError('参数错误');
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
if ($down == 'no') {
|
||||||
|
File::isNeedInstallApp($file->type);
|
||||||
|
}
|
||||||
|
//
|
||||||
if ($only_update_at == 'yes') {
|
if ($only_update_at == 'yes') {
|
||||||
return Base::retSuccess('success', [
|
return Base::retSuccess('success', [
|
||||||
'id' => $file->id,
|
'id' => $file->id,
|
||||||
'update_at' => Carbon::parse($file->updated_at)->toDateTimeString()
|
'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);
|
$builder = FileContent::whereFid($file->id);
|
||||||
if ($history_id > 0) {
|
if ($history_id > 0) {
|
||||||
@ -595,16 +581,12 @@ class FileController extends AbstractController
|
|||||||
$contentArray = Base::json2array($content);
|
$contentArray = Base::json2array($content);
|
||||||
$contentString = $contentArray['xml'];
|
$contentString = $contentArray['xml'];
|
||||||
$file->ext = 'drawio';
|
$file->ext = 'drawio';
|
||||||
if (!Apps::isInstalled('drawio')) {
|
File::isNeedInstallApp($file->type);
|
||||||
return Base::retError('应用「Drawio」未安装');
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'mind':
|
case 'mind':
|
||||||
$contentString = $content;
|
$contentString = $content;
|
||||||
$file->ext = 'mind';
|
$file->ext = 'mind';
|
||||||
if (!Apps::isInstalled('minder')) {
|
File::isNeedInstallApp($file->type);
|
||||||
return Base::retError('应用「Minder」未安装');
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'txt':
|
case 'txt':
|
||||||
case 'code':
|
case 'code':
|
||||||
@ -656,9 +638,7 @@ class FileController extends AbstractController
|
|||||||
{
|
{
|
||||||
User::auth();
|
User::auth();
|
||||||
//
|
//
|
||||||
if (!Apps::isInstalled('office')) {
|
File::isNeedInstallApp('office');
|
||||||
return Base::retError('应用「OnlyOffice」未安装');
|
|
||||||
}
|
|
||||||
//
|
//
|
||||||
$config = Request::input('config');
|
$config = Request::input('config');
|
||||||
$token = \Firebase\JWT\JWT::encode($config, env('APP_KEY') ,'HS256');
|
$token = \Firebase\JWT\JWT::encode($config, env('APP_KEY') ,'HS256');
|
||||||
@ -685,9 +665,7 @@ class FileController extends AbstractController
|
|||||||
{
|
{
|
||||||
$user = User::auth();
|
$user = User::auth();
|
||||||
//
|
//
|
||||||
if (!Apps::isInstalled('office')) {
|
File::isNeedInstallApp('office');
|
||||||
return Base::retError('应用「OnlyOffice」未安装');
|
|
||||||
}
|
|
||||||
//
|
//
|
||||||
$id = intval(Request::input('id'));
|
$id = intval(Request::input('id'));
|
||||||
$status = intval(Request::input('status'));
|
$status = intval(Request::input('status'));
|
||||||
@ -808,19 +786,8 @@ class FileController extends AbstractController
|
|||||||
$history_id = intval(Request::input('history_id'));
|
$history_id = intval(Request::input('history_id'));
|
||||||
//
|
//
|
||||||
$file = File::permissionFind($id, $user);
|
$file = File::permissionFind($id, $user);
|
||||||
// office
|
//
|
||||||
if (in_array($file->type, ['word', 'excel', 'ppt']) && !Apps::isInstalled('office')) {
|
File::isNeedInstallApp($file->type);
|
||||||
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」未安装');
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
$history = FileContent::whereFid($file->id)->whereId($history_id)->first();
|
$history = FileContent::whereFid($file->id)->whereId($history_id)->first();
|
||||||
if (empty($history)) {
|
if (empty($history)) {
|
||||||
|
|||||||
@ -41,7 +41,6 @@ use App\Models\ProjectTaskFlowChange;
|
|||||||
use App\Models\ProjectTaskVisibilityUser;
|
use App\Models\ProjectTaskVisibilityUser;
|
||||||
use App\Models\ProjectTaskTemplate;
|
use App\Models\ProjectTaskTemplate;
|
||||||
use App\Models\ProjectTag;
|
use App\Models\ProjectTag;
|
||||||
use App\Module\Apps;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @apiDefine project
|
* @apiDefine project
|
||||||
@ -1832,18 +1831,7 @@ class ProjectController extends AbstractController
|
|||||||
'update_at' => Carbon::parse($file->updated_at)->toDateTimeString()
|
'update_at' => Carbon::parse($file->updated_at)->toDateTimeString()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
// office
|
File::isNeedInstallApp($file->ext);
|
||||||
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」未安装');
|
|
||||||
}
|
|
||||||
//
|
//
|
||||||
$data = $file->toArray();
|
$data = $file->toArray();
|
||||||
$data['path'] = $file->getRawOriginal('path');
|
$data['path'] = $file->getRawOriginal('path');
|
||||||
|
|||||||
@ -302,9 +302,7 @@ class SystemController extends AbstractController
|
|||||||
{
|
{
|
||||||
User::auth('admin');
|
User::auth('admin');
|
||||||
//
|
//
|
||||||
if (!Apps::isInstalled('ai')) {
|
Apps::isInstalledThrow('ai');
|
||||||
return Base::retError('应用「AI Robot」未安装');
|
|
||||||
}
|
|
||||||
//
|
//
|
||||||
$type = trim(Request::input('type'));
|
$type = trim(Request::input('type'));
|
||||||
$filter = trim(Request::input('filter'));
|
$filter = trim(Request::input('filter'));
|
||||||
@ -469,11 +467,9 @@ class SystemController extends AbstractController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 人脸识别
|
// 人脸识别
|
||||||
if (in_array('face', $all['modes'])){
|
if (in_array('face', $all['modes'])) {
|
||||||
if (!Apps::isInstalled('face')) {
|
Apps::isInstalledThrow('face');
|
||||||
return Base::retError('应用「Face check-in」未安装');
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($all['modes']) {
|
if ($all['modes']) {
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Request;
|
use Request;
|
||||||
|
use App\Module\Apps;
|
||||||
use App\Module\Base;
|
use App\Module\Base;
|
||||||
use App\Tasks\PushTask;
|
use App\Tasks\PushTask;
|
||||||
use App\Exceptions\ApiException;
|
use App\Exceptions\ApiException;
|
||||||
@ -978,4 +979,41 @@ class File extends AbstractModel
|
|||||||
];
|
];
|
||||||
Task::deliver(new PushTask($params));
|
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;
|
namespace App\Module;
|
||||||
|
|
||||||
|
use App\Exceptions\ApiException;
|
||||||
use App\Services\RequestContext;
|
use App\Services\RequestContext;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
@ -33,4 +34,26 @@ class Apps
|
|||||||
|
|
||||||
return RequestContext::save($key, $installed);
|
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