OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
55
app/Domain/CsvImport/Controllers/Upload.php
Normal file
55
app/Domain/CsvImport/Controllers/Upload.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\CsvImport\Controllers;
|
||||
|
||||
use League\Csv\Exception;
|
||||
use Leantime\Core\Controller\Controller;
|
||||
use Leantime\Domain\Auth\Models\Roles;
|
||||
use Leantime\Domain\Auth\Services\Auth;
|
||||
use Leantime\Domain\CsvImport\Services\CsvImport as CsvImportService;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* upload controller for csvImport plugin
|
||||
*/
|
||||
class Upload extends Controller
|
||||
{
|
||||
private CsvImportService $providerService;
|
||||
|
||||
/**
|
||||
* constructor - initialize private variables
|
||||
*/
|
||||
public function init(CsvImportService $providerService): void
|
||||
{
|
||||
Auth::authOrRedirect([Roles::$owner, Roles::$admin, Roles::$manager, Roles::$editor]);
|
||||
|
||||
$this->providerService = $providerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* get - display upload form
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get(): Response
|
||||
{
|
||||
return $this->tpl->displayPartial('csvImport.upload');
|
||||
}
|
||||
|
||||
/**
|
||||
* post - process uploaded file
|
||||
*/
|
||||
public function post(array $params): Response
|
||||
{
|
||||
$file = $this->incomingRequest->file('file');
|
||||
|
||||
try {
|
||||
$id = $this->providerService->processUpload($file);
|
||||
} catch (Exception $e) {
|
||||
return $this->tpl->displayJson(json_encode(['error' => $e->getMessage()]), 500);
|
||||
}
|
||||
|
||||
return $this->tpl->displayJson(json_encode(['id' => $id]));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user