实现下载分享文件/文件夹时日志记录

This commit is contained in:
Chenx221 2024-04-06 13:12:53 +08:00
parent 8996158fb5
commit 03333cd180
Signed by: chenx221
GPG Key ID: D7A9EC07024C3021

View File

@ -2,6 +2,7 @@
namespace app\controllers;
use app\models\DownloadLogs;
use app\models\Share;
use app\models\ShareSearch;
use RecursiveDirectoryIterator;
@ -60,6 +61,7 @@ class ShareController extends Controller
]
);
}
public function init(): void
{
parent::init();
@ -72,6 +74,7 @@ class ShareController extends Controller
$this->layout = 'main';
}
}
/**
* Lists all Share models.
*
@ -267,7 +270,7 @@ class ShareController extends Controller
}
$model = $this->findModel($share_id, true);
DownloadLogs::addLog(Yii::$app->user->id, $model->share_id, Yii::$app->request->userIP, Yii::$app->request->userAgent); // logging for access(DL)
$absolutePath = Yii::getAlias(Yii::$app->params['dataDirectory']) . '/' . $model->sharer_id . '/' . $model->file_relative_path;
if (is_file($absolutePath)) {
return Yii::$app->response->sendFile($absolutePath);
@ -290,4 +293,7 @@ class ShareController extends Controller
throw new NotFoundHttpException('异常,文件不存在');
}
}
// TODO
// Preview file
}