mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-11 02:12:53 +00:00
fix: 修复无法导出的问题
This commit is contained in:
parent
8746caab06
commit
115b4aacb8
@ -3,10 +3,10 @@
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use Request;
|
||||
use Session;
|
||||
use Response;
|
||||
use Madzipper;
|
||||
use Carbon\Carbon;
|
||||
use App\Module\Down;
|
||||
use App\Models\User;
|
||||
use App\Module\Base;
|
||||
use App\Module\Doo;
|
||||
@ -925,11 +925,10 @@ class ApproveController extends AbstractController
|
||||
}
|
||||
//
|
||||
if (file_exists($zipPath)) {
|
||||
$base64 = base64_encode(Base::array2string([
|
||||
$key = Down::cache_encode([
|
||||
'file' => $zipFile,
|
||||
]));
|
||||
$fileUrl = Base::fillUrl('api/approve/down?key=' . urlencode($base64));
|
||||
Session::put('approve::export:userid', $user->userid);
|
||||
]);
|
||||
$fileUrl = Base::fillUrl('api/approve/down?key=' . $key);
|
||||
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
|
||||
'type' => 'file_download',
|
||||
'title' => '导出审批数据已完成',
|
||||
@ -983,12 +982,7 @@ class ApproveController extends AbstractController
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$userid = Session::get('approve::export:userid');
|
||||
if (empty($userid)) {
|
||||
return Base::ajaxError("请求已过期,请重新导出!", [], 0, 403);
|
||||
}
|
||||
//
|
||||
$array = Base::string2array(base64_decode(urldecode(Request::input('key'))));
|
||||
$array = Down::cache_decode();
|
||||
$file = $array['file'];
|
||||
if (empty($file) || !file_exists(storage_path($file))) {
|
||||
return Base::ajaxError("文件不存在!", [], 0, 403);
|
||||
|
||||
@ -12,10 +12,10 @@ use App\Models\FileLink;
|
||||
use App\Models\FileUser;
|
||||
use App\Models\User;
|
||||
use App\Module\Base;
|
||||
use App\Module\Down;
|
||||
use App\Module\Timer;
|
||||
use App\Module\Ihttp;
|
||||
use Response;
|
||||
use Session;
|
||||
use Swoole\Coroutine;
|
||||
use Carbon\Carbon;
|
||||
use Redirect;
|
||||
@ -1016,14 +1016,8 @@ class FileController extends AbstractController
|
||||
*/
|
||||
public function download__pack()
|
||||
{
|
||||
$key = Request::input('key');
|
||||
if ($key) {
|
||||
$userid = Session::get('file::pack:userid');
|
||||
if (empty($userid)) {
|
||||
return Base::ajaxError("请求已过期,请重新导出!", [], 0, 403);
|
||||
}
|
||||
//
|
||||
$array = Base::string2array(base64_decode(urldecode($key)));
|
||||
if (Request::has('key')) {
|
||||
$array = Down::cache_decode();
|
||||
$file = $array['file'];
|
||||
if (empty($file) || !file_exists(storage_path($file))) {
|
||||
return Base::ajaxError("文件不存在!", [], 0, 403);
|
||||
@ -1091,11 +1085,10 @@ class FileController extends AbstractController
|
||||
return Base::retError('文件总大小已超过1GB,请分批下载');
|
||||
}
|
||||
|
||||
$base64 = base64_encode(Base::array2string([
|
||||
$key = Down::cache_encode([
|
||||
'file' => $zipFile,
|
||||
]));
|
||||
$fileUrl = Base::fillUrl('api/file/download/pack?key=' . urlencode($base64));
|
||||
Session::put('file::pack:userid', $user->userid);
|
||||
]);
|
||||
$fileUrl = Base::fillUrl('api/file/download/pack?key=' . $key);
|
||||
|
||||
$zip = new \ZipArchive();
|
||||
Base::makeDir(dirname($zipPath));
|
||||
|
||||
@ -3,11 +3,11 @@
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use Request;
|
||||
use Session;
|
||||
use Redirect;
|
||||
use Response;
|
||||
use Madzipper;
|
||||
use Carbon\Carbon;
|
||||
use App\Module\Down;
|
||||
use App\Module\Doo;
|
||||
use App\Models\File;
|
||||
use App\Models\User;
|
||||
@ -1292,7 +1292,7 @@ class ProjectController extends AbstractController
|
||||
->where('project_task_users.owner', 1)
|
||||
->whereIn('project_task_users.userid', $userid)
|
||||
->betweenTime(Carbon::parse($time[0])->startOfDay(), Carbon::parse($time[1])->endOfDay(), $type);
|
||||
$builder->orderByDesc('project_tasks.id')->chunk(100, function ($tasks) use (&$datas) {
|
||||
$builder->orderByDesc('project_tasks.id')->chunk(100, function ($tasks) use ($doo, &$datas) {
|
||||
/** @var ProjectTask $task */
|
||||
foreach ($tasks as $task) {
|
||||
$flowChanges = ProjectTaskFlowChange::whereTaskId($task->id)->get();
|
||||
@ -1446,11 +1446,10 @@ class ProjectController extends AbstractController
|
||||
}
|
||||
//
|
||||
if (file_exists($zipPath)) {
|
||||
$base64 = base64_encode(Base::array2string([
|
||||
$key = Down::cache_encode([
|
||||
'file' => $zipFile,
|
||||
]));
|
||||
$fileUrl = Base::fillUrl('api/project/task/down?key=' . urlencode($base64));
|
||||
Session::put('task::export:userid', $user->userid);
|
||||
]);
|
||||
$fileUrl = Base::fillUrl('api/project/task/down?key=' . $key);
|
||||
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
|
||||
'type' => 'file_download',
|
||||
'title' => '导出任务统计已完成',
|
||||
@ -1530,7 +1529,7 @@ class ProjectController extends AbstractController
|
||||
->whereNotNull('end_at')
|
||||
->where('end_at', '<=', Carbon::now())
|
||||
->orderBy('end_at')
|
||||
->chunk(100, function ($tasks) use (&$data) {
|
||||
->chunk(100, function ($tasks) use ($doo, &$data) {
|
||||
/** @var ProjectTask $task */
|
||||
foreach ($tasks as $task) {
|
||||
$taskStartTime = Carbon::parse($task->start_at ?: $task->created_at)->timestamp;
|
||||
@ -1615,11 +1614,10 @@ class ProjectController extends AbstractController
|
||||
}
|
||||
//
|
||||
if (file_exists($zipPath)) {
|
||||
$base64 = base64_encode(Base::array2string([
|
||||
$key = Down::cache_encode([
|
||||
'file' => $zipFile,
|
||||
]));
|
||||
$fileUrl = Base::fillUrl('api/project/task/down?key=' . urlencode($base64));
|
||||
Session::put('task::export:userid', $user->userid);
|
||||
]);
|
||||
$fileUrl = Base::fillUrl('api/project/task/down?key=' . $key);
|
||||
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
|
||||
'type' => 'file_download',
|
||||
'title' => '导出超期任务已完成',
|
||||
@ -1661,12 +1659,7 @@ class ProjectController extends AbstractController
|
||||
*/
|
||||
public function task__down()
|
||||
{
|
||||
$userid = Session::get('task::export:userid');
|
||||
if (empty($userid)) {
|
||||
return Base::ajaxError("请求已过期,请重新导出!", [], 0, 403);
|
||||
}
|
||||
//
|
||||
$array = Base::string2array(base64_decode(urldecode(Request::input('key'))));
|
||||
$array = Down::cache_decode();
|
||||
$file = $array['file'];
|
||||
if (empty($file) || !file_exists(storage_path($file))) {
|
||||
return Base::ajaxError("文件不存在!", [], 0, 403);
|
||||
|
||||
@ -6,8 +6,8 @@ use App\Models\UserDevice;
|
||||
use App\Models\WebSocketDialog;
|
||||
use App\Models\WebSocketDialogMsg;
|
||||
use App\Module\AI;
|
||||
use App\Module\Down;
|
||||
use Request;
|
||||
use Session;
|
||||
use Response;
|
||||
use Madzipper;
|
||||
use Carbon\Carbon;
|
||||
@ -1465,11 +1465,10 @@ class SystemController extends AbstractController
|
||||
}
|
||||
//
|
||||
if (file_exists($zipPath)) {
|
||||
$base64 = base64_encode(Base::array2string([
|
||||
$key = Down::cache_encode([
|
||||
'file' => $zipFile,
|
||||
]));
|
||||
$fileUrl = Base::fillUrl('api/system/checkin/down?key=' . urlencode($base64));
|
||||
Session::put('checkin::export:userid', $user->userid);
|
||||
]);
|
||||
$fileUrl = Base::fillUrl('api/system/checkin/down?key=' . $key);
|
||||
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
|
||||
'type' => 'file_download',
|
||||
'title' => '导出签到数据已完成',
|
||||
@ -1511,12 +1510,7 @@ class SystemController extends AbstractController
|
||||
*/
|
||||
public function checkin__down()
|
||||
{
|
||||
$userid = Session::get('checkin::export:userid');
|
||||
if (empty($userid)) {
|
||||
return Base::ajaxError("请求已过期,请重新导出!", [], 0, 403);
|
||||
}
|
||||
//
|
||||
$array = Base::string2array(base64_decode(urldecode(Request::input('key'))));
|
||||
$array = Down::cache_decode();
|
||||
$file = $array['file'];
|
||||
if (empty($file) || !file_exists(storage_path($file))) {
|
||||
return Base::ajaxError("文件不存在!", [], 0, 403);
|
||||
|
||||
@ -25,8 +25,11 @@ class Doo
|
||||
return RequestContext::get(self::DOO_INSTANCE);
|
||||
}
|
||||
|
||||
$token = $token ?: Base::token();
|
||||
$language = $language ?: Base::headerOrInput('language');
|
||||
$request = request();
|
||||
if ($request && method_exists($request, 'header')) {
|
||||
$token = $token ?: Base::token();
|
||||
$language = $language ?: Base::headerOrInput('language');
|
||||
}
|
||||
$instance = new DooSo($token, $language);
|
||||
|
||||
RequestContext::set(self::DOO_INSTANCE, $instance);
|
||||
|
||||
37
app/Module/Down.php
Normal file
37
app/Module/Down.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Module;
|
||||
|
||||
use Request;
|
||||
use Cache;
|
||||
|
||||
class Down
|
||||
{
|
||||
/**
|
||||
* @param $data
|
||||
* @param null $ttl
|
||||
* @return string
|
||||
*/
|
||||
public static function cache_encode($data, $ttl = null): string
|
||||
{
|
||||
$base64 = base64_encode(Base::array2string($data));
|
||||
$key = md5($base64);
|
||||
Cache::put("down::{$key}", $base64, $ttl ?: now()->addHour());
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ?string $inputName
|
||||
* @return array
|
||||
*/
|
||||
public static function cache_decode(?string $inputName = 'key'): array
|
||||
{
|
||||
$key = Request::input($inputName);
|
||||
$base64 = Cache::get("down::{$key}");
|
||||
if (empty($base64)) {
|
||||
return Base::ajaxError("请求已过期,请重新导出!", [], 0, 403);
|
||||
}
|
||||
//
|
||||
return Base::string2array(base64_decode($base64));
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user