完善页面,支持异IP下载
This commit is contained in:
parent
3323eef81e
commit
d59ad8f7b7
6 changed files with 102 additions and 12 deletions
|
@ -57,6 +57,7 @@ namespace iFileProxy.Config
|
||||||
public List<string> BlockedClientIP { get; set; } = [];
|
public List<string> BlockedClientIP { get; set; } = [];
|
||||||
public List<string> RoutesToTrack { get; set; } = [];
|
public List<string> RoutesToTrack { get; set; } = [];
|
||||||
public int DailyRequestLimitPerIP { get; set; } = -1;
|
public int DailyRequestLimitPerIP { get; set; } = -1;
|
||||||
|
public bool AllowDifferentIPsForDownload { get; set; } = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial class Database
|
public partial class Database
|
||||||
|
|
|
@ -12,6 +12,7 @@ namespace iFileProxy.Controllers
|
||||||
{
|
{
|
||||||
static readonly TaskManager taskManager = new ();
|
static readonly TaskManager taskManager = new ();
|
||||||
static Dictionary<string, Dictionary<string, uint>> IPAccessCountDict = [];
|
static Dictionary<string, Dictionary<string, uint>> IPAccessCountDict = [];
|
||||||
|
static AppConfig? appConfig = AppConfig.GetCurrConfig();
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("/AddOfflineTask")]
|
[Route("/AddOfflineTask")]
|
||||||
|
@ -51,9 +52,21 @@ namespace iFileProxy.Controllers
|
||||||
{
|
{
|
||||||
string fileName = "";
|
string fileName = "";
|
||||||
var d = taskManager.GetTaskListByIpAddr(HttpContext);
|
var d = taskManager.GetTaskListByIpAddr(HttpContext);
|
||||||
if (d.Where(x => x.TaskId == taskID).Any())
|
var taskInfo = taskManager.GetTaskInfo(taskID);
|
||||||
|
|
||||||
|
if ((!appConfig.SecurityOptions.AllowDifferentIPsForDownload && d.Where(x => x.TaskId == taskID).Any()) || taskInfo != null)
|
||||||
{
|
{
|
||||||
fileName = d.Where(x => x.TaskId == taskID).FirstOrDefault()?.FileName;
|
if (appConfig.SecurityOptions.AllowDifferentIPsForDownload)
|
||||||
|
{
|
||||||
|
fileName = taskInfo[0].FileName;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fileName = d.Where(x => x.TaskId == taskID).FirstOrDefault()?.FileName;
|
||||||
|
}
|
||||||
|
if (fileName == null)
|
||||||
|
return Ok(new CommonRsp() { message = "file not exists", retcode = -1 });
|
||||||
|
|
||||||
var filePath = Path.Combine(AppConfig.GetCurrConfig().DownloadOptions.SavePath, fileName);
|
var filePath = Path.Combine(AppConfig.GetCurrConfig().DownloadOptions.SavePath, fileName);
|
||||||
if (!System.IO.File.Exists(filePath))
|
if (!System.IO.File.Exists(filePath))
|
||||||
{
|
{
|
||||||
|
|
|
@ -85,25 +85,23 @@ namespace iFileProxy.Helpers
|
||||||
/// <param name="sql"></param>
|
/// <param name="sql"></param>
|
||||||
/// <param name="conn"></param>
|
/// <param name="conn"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetTableData(string sql, MySqlConnection conn)
|
public static string GetTableData(MySqlCommand sqlCmd)
|
||||||
{
|
{
|
||||||
DataTable dataTable = new();
|
DataTable dataTable = new();
|
||||||
|
using (MySqlDataAdapter adapter = new (sqlCmd))
|
||||||
using (MySqlCommand getAllData = new (sql, conn))
|
|
||||||
{
|
|
||||||
using (MySqlDataAdapter adapter = new (getAllData))
|
|
||||||
adapter.Fill(dataTable);
|
adapter.Fill(dataTable);
|
||||||
}
|
|
||||||
return JsonConvert.SerializeObject(dataTable);
|
return JsonConvert.SerializeObject(dataTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetTaskListByIP(string ipAddr)
|
public string GetTaskListByIP(string ipAddr)
|
||||||
{
|
{
|
||||||
string sql = $"SELECT * FROM t_tasks_info WHERE client_ip = \"{ipAddr}\"";
|
string sql = $"SELECT * FROM t_tasks_info WHERE client_ip = @ip_addr";
|
||||||
MySqlConnection conn = GetAndOpenDBConn("iFileProxy_Db");
|
MySqlConnection conn = GetAndOpenDBConn("iFileProxy_Db");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return GetTableData(sql, conn);
|
using MySqlCommand sqlCmd = new (sql,conn);
|
||||||
|
sqlCmd.Parameters.AddWithValue("@ip_addr", ipAddr);
|
||||||
|
return GetTableData(sqlCmd);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -112,6 +110,25 @@ namespace iFileProxy.Helpers
|
||||||
}
|
}
|
||||||
finally { conn.Close(); }
|
finally { conn.Close(); }
|
||||||
}
|
}
|
||||||
|
public string GetTaskInfoByTid(string tid)
|
||||||
|
{
|
||||||
|
string sql = $"SELECT * FROM t_tasks_info WHERE `tid` =@tid";
|
||||||
|
MySqlConnection conn = GetAndOpenDBConn("iFileProxy_Db");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using MySqlCommand sqlCmd = new(sql, conn);
|
||||||
|
sqlCmd.Parameters.AddWithValue("@tid", tid);
|
||||||
|
return GetTableData(sqlCmd);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.Error($"无法获取任务信息: {e.Message}");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
finally { conn.Close(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public bool InsertTaskData(TaskInfo taskInfo)
|
public bool InsertTaskData(TaskInfo taskInfo)
|
||||||
{
|
{
|
||||||
|
|
|
@ -157,6 +157,12 @@ namespace iFileProxy.Services
|
||||||
return JsonSerializer.Deserialize<List<TaskInfo>>(_dbHelper.GetTaskListByIP(clientIp)) ?? [];
|
return JsonSerializer.Deserialize<List<TaskInfo>>(_dbHelper.GetTaskListByIP(clientIp)) ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<TaskInfo> GetTaskInfo(string taskId)
|
||||||
|
{
|
||||||
|
_logger.Debug(_dbHelper.GetTaskInfoByTid(taskId));
|
||||||
|
return JsonSerializer.Deserialize<List<TaskInfo>>(_dbHelper.GetTaskInfoByTid(taskId)) ?? [] ;
|
||||||
|
}
|
||||||
|
|
||||||
//public bool DeleteTask(HttpContext c)
|
//public bool DeleteTask(HttpContext c)
|
||||||
//{
|
//{
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
"RoutesToTrack": [ // 参加IP请求数统计的路径名单
|
"RoutesToTrack": [ // 参加IP请求数统计的路径名单
|
||||||
"/Download",
|
"/Download",
|
||||||
"/AddOfflineTask"
|
"/AddOfflineTask"
|
||||||
]
|
],
|
||||||
|
"AllowDifferentIPsForDownload": true // 下载者与任务数据提交者IP不同是否允许下载文件
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -17,15 +17,53 @@
|
||||||
a {
|
a {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#loading-mask {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-color: rgba(255, 255, 255, 0.8);
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
z-index: 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-spinner {
|
||||||
|
border: 16px solid #f3f3f3;
|
||||||
|
/* Light grey */
|
||||||
|
border-top: 16px solid #3498db;
|
||||||
|
/* Blue */
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 120px;
|
||||||
|
height: 120px;
|
||||||
|
animation: spin 2s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
0% {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="container mt-5">
|
<div class="container mt-5">
|
||||||
<div class="row justify-content-center">
|
<div class="row justify-content-center">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body">
|
<div id="from_data" class="card-body">
|
||||||
|
<div id="loading-mask" style="display: none;">
|
||||||
|
<div class="loading-spinner"></div>
|
||||||
|
</div>
|
||||||
<h5 class="card-title text-center">Github文件下载加速</h5>
|
<h5 class="card-title text-center">Github文件下载加速</h5>
|
||||||
|
|
||||||
<!-- URL 输入框 -->
|
<!-- URL 输入框 -->
|
||||||
|
@ -58,9 +96,22 @@
|
||||||
<script src="static/js/bootstarp/5/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
|
<script src="static/js/bootstarp/5/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
|
||||||
<script src="static/js/jquery/2.1.4/jquery.min.js"></script>
|
<script src="static/js/jquery/2.1.4/jquery.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
const $loadingMask = $('#loading-mask');
|
||||||
|
const $dataTable = $('#from_data');
|
||||||
|
|
||||||
|
// 显示遮罩层
|
||||||
|
function showLoadingMask() {
|
||||||
|
$loadingMask.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 隐藏遮罩层
|
||||||
|
function hideLoadingMask() {
|
||||||
|
$loadingMask.hide();
|
||||||
|
}
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
console.log("document ready")
|
console.log("document ready")
|
||||||
sub_btn.addEventListener('click', function (param) {
|
sub_btn.addEventListener('click', function (param) {
|
||||||
|
showLoadingMask();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "/AddOfflineTask",
|
url: "/AddOfflineTask",
|
||||||
|
@ -69,6 +120,7 @@
|
||||||
},
|
},
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
|
hideLoadingMask();
|
||||||
if (response.retcode == 0)
|
if (response.retcode == 0)
|
||||||
alert("任务提交成功! 请稍后点击页面下方的 \"查询文件下载任务状态\" 超链接查询任务状态!");
|
alert("任务提交成功! 请稍后点击页面下方的 \"查询文件下载任务状态\" 超链接查询任务状态!");
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue