添加配置文件验证逻辑,修改css和js的加载逻辑

This commit is contained in:
root 2024-11-21 22:59:50 +08:00
parent d59ad8f7b7
commit d22404bdbb
12 changed files with 136 additions and 120 deletions

View file

@ -8,5 +8,6 @@
- [x] 文件大小限制
- [x] 基于IP查询提交的任务状态
- [x] 基于IP和路由的请求次数限制
- [ ] 任务队列
- [ ] 已经存在对应文件时候直接跳过代理下载 直接下载已经缓存的内容
- [ ] 捐赠

View file

@ -1,4 +1,5 @@
using Serilog;
using iFileProxy.Helpers;
using Serilog;
using System.Text.Json;
using System.Text.Json.Serialization;
@ -40,6 +41,33 @@ namespace iFileProxy.Config
_logger.Fatal($"Config File: {configPath} not exists!");
return null;
}
public static void CheckAppConfig()
{
AppConfig? c = GetCurrConfig();
if (c != null)
{
if (!Directory.Exists(c.DownloadOptions.SavePath))
{
_logger.Warning($"下载路径不存在, 尝试创建文件夹...");
Directory.CreateDirectory(c.DownloadOptions.SavePath);
_logger.Warning($"succ.");
}
if (!File.Exists(c.DownloadOptions.Aria2cPath))
{
_logger.Fatal("Aria2c 路径错误!");
Environment.Exit(1);
}
DatabaseHelper databaseHelper = new(c);
databaseHelper.TestDbConfig();
}
else
{
_logger.Error("配置为空!");
Environment.Exit(1);
}
}
}
public class DownloadOptions
@ -49,6 +77,7 @@ namespace iFileProxy.Config
public uint MaxAllowedFileSize { get; set; }
public uint MaxParallelTasks { get; set; } = 4;
public string Aria2cPath { get; set; } = "./bin/aria2c";
public int CacheLifetime { get; set; } = 3600;
}
public class SecurityOptions
{

View file

@ -79,6 +79,31 @@ namespace iFileProxy.Helpers
}
return conn;
}
public bool TestDbConfig()
{
foreach (var db in _dbDictionary)
{
_logger.Information($"[程序启动前配置验证] 正在测试数据库配置: {db.Key} ...");
MySqlConnection dbConn = new();
try
{
dbConn = GetAndOpenDBConn(db.Key);
_logger.Information($"succ.");
}
catch (Exception)
{
_logger.Fatal($"=========== 数据库: {db.Key} 测试失败! ===========");
return false;
}
finally
{
dbConn.Close();
}
}
return true;
}
/// <summary>
/// 获取一个json格式的数据表
/// </summary>

View file

@ -1,10 +1,11 @@
namespace iFileProxy.Models
{
public enum TaskState {
public enum TaskState {
NoInit = 0, // 还未初始化
Running = 1, // 正在进行
Error = 2, // 任务执行时候发生错误 已经结束
End = 3, // 任务正常结束
Cached = 4, // 要下载的内容已经缓存
}
public enum TaskAddState {
Success = 0,

View file

@ -12,6 +12,10 @@ namespace iFileProxy
SerilogConfig.CreateLogger();
Serilog.ILogger logger = Log.Logger.ForContext<Program>();
Console.Write(" ");
AppConfig.CheckAppConfig();
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.

View file

@ -15,7 +15,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<_TargetId>Folder</_TargetId>
<SiteUrlToLaunchAfterPublish />
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<ProjectGuid>e343bd8a-27ed-47e2-b50d-e3000730e65e</ProjectGuid>
<SelfContained>false</SelfContained>
<PublishSingleFile>true</PublishSingleFile>

View file

@ -0,0 +1,9 @@
namespace iFileProxy.Services
{
/// <summary>
/// 本地缓存管理器
/// </summary>
public class LocalCacheManager
{
}
}

View file

@ -18,7 +18,8 @@
"ThreadNum": 4, // 线
"MaxAllowedFileSize": 65536, //
"MaxParallelTasks": 4, //
"Aria2cPath": "./lib/aria2c"
"Aria2cPath": "./lib/aria2c",
"CacheLifetime": 3600 // ()
},
"Security": {
"BlockedHost": [ //

View file

@ -7,51 +7,7 @@
<title>Github文件下载加速</title>
<!-- 引入 Bootstrap 5 CSS -->
<link href="static/css/bootstarp/5/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<style>
.more-content {
text-align: center;
}
a {
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>
<link href="static/css/custom/Common.css" rel="stylesheet" crossorigin="anonymous">
</head>
<body>
@ -62,7 +18,7 @@
<div class="card">
<div id="from_data" class="card-body">
<div id="loading-mask" style="display: none;">
<div class="loading-spinner"></div>
<div class="loading-spinner"><p>加载中</p></div>
</div>
<h5 class="card-title text-center">Github文件下载加速</h5>
@ -95,19 +51,8 @@
<!-- 优先加载jq一类的三方库 -->
<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/custom/Common.js"></script>
<script>
const $loadingMask = $('#loading-mask');
const $dataTable = $('#from_data');
// 显示遮罩层
function showLoadingMask() {
$loadingMask.show();
}
// 隐藏遮罩层
function hideLoadingMask() {
$loadingMask.hide();
}
$(document).ready(function () {
console.log("document ready")
sub_btn.addEventListener('click', function (param) {

View file

@ -6,6 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>离线下载任务管理</title>
<link href="static/css/bootstarp/5/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<link href="static/css/custom/Common.css" rel="stylesheet" crossorigin="anonymous">
<style>
body {
padding: 20px;
@ -79,50 +81,6 @@
display: none !important;
}
}
a {
text-decoration: none;
}
.more-content {
text-align: center;
}
#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>
</head>
@ -156,21 +114,10 @@
<!-- 优先加载jq一类的三方库 -->
<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/custom/Common.js"></script>
<script>
const $loadingMask = $('#loading-mask');
const $dataTable = $('#data-table');
// 显示遮罩层
function showLoadingMask() {
$loadingMask.show();
}
// 隐藏遮罩层
function hideLoadingMask() {
$loadingMask.hide();
}
showLoadingMask();
showLoadingMask();
let statusStrDict = new Map([
[0, "排队中"],
[1, "进行中"],

View file

@ -0,0 +1,42 @@
.more-content {
text-align: center;
}
a {
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);
}
}

View file

@ -0,0 +1,12 @@
const $loadingMask = $('#loading-mask');
const $dataTable = $('#from_data');
// 显示遮罩层
function showLoadingMask() {
$loadingMask.show();
}
// 隐藏遮罩层
function hideLoadingMask() {
$loadingMask.hide();
}