Fix minor issues (#9)

This commit is contained in:
Pavel Pikta 2026-02-07 00:18:50 +03:00 committed by GitHub
parent b3d4806809
commit a19d972ea2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
26 changed files with 230 additions and 97 deletions

View File

@ -68,11 +68,8 @@ namespace Lampac.Controllers
#region migration storage to sql
if (AppInit.conf.sync_user.version != 1 && !string.IsNullOrEmpty(requestInfo.user_uid))
{
string profile_id = getProfileid(requestInfo, HttpContext);
string id = requestInfo.user_uid + profile_id;
string md5key = AppInit.conf.storage.md5name ? CrypTo.md5(id) : Regex.Replace(id, "[^a-z0-9\\-]", "");
string storageFile = $"database/storage/sync_favorite/{md5key.Substring(0, 2)}/{md5key.Substring(2)}";
string profileId = getProfileid(requestInfo, HttpContext);
var storageFile = StorageManager.GetFilePath("sync_favorite", false, requestInfo.user_uid, profileId);
if (System.IO.File.Exists(storageFile) && !System.IO.File.Exists($"{storageFile}.migration"))
{

View File

@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@ -9,7 +8,6 @@ using Shared.Engine.Utilities;
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using IO = System.IO;
@ -18,14 +16,6 @@ namespace Lampac.Controllers
{
public class StorageController : BaseController
{
#region StorageController
static StorageController()
{
Directory.CreateDirectory("database/storage");
Directory.CreateDirectory("database/storage/temp");
}
#endregion
#region backup.js
[HttpGet]
[AllowAnonymous]
@ -83,7 +73,7 @@ namespace Lampac.Controllers
if (!AppInit.conf.storage.enable)
return ContentTo("{\"success\": false, \"msg\": \"disabled\"}");
string outFile = getFilePath(path, pathfile, false);
string outFile = StorageManager.GetFilePath(path, false, requestInfo, pathfile);
if (outFile == null || !IO.File.Exists(outFile))
return ContentTo("{\"success\": false, \"msg\": \"outFile\"}");
@ -135,7 +125,7 @@ namespace Lampac.Controllers
if (HttpContext.Request.ContentLength > AppInit.conf.storage.max_size)
return ContentTo("{\"success\": false, \"msg\": \"max_size\"}");
string outFile = getFilePath(path, pathfile, true);
string outFile = StorageManager.GetFilePath(path, true, requestInfo, pathfile);
if (outFile == null)
return ContentTo("{\"success\": false, \"msg\": \"outFile\"}");
@ -164,7 +154,7 @@ namespace Lampac.Controllers
{
await semaphore.WaitAsync();
using (var fileStream = new FileStream(outFile, FileMode.Create, FileAccess.Write, FileShare.None, PoolInvk.bufferSize))
await using var fileStream = new FileStream(outFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, PoolInvk.bufferSize);
await memoryStream.CopyToAsync(fileStream, PoolInvk.bufferSize);
}
catch
@ -216,7 +206,7 @@ namespace Lampac.Controllers
if (!AppInit.conf.storage.enable)
return ContentTo("{\"success\": false, \"msg\": \"disabled\"}");
string outFile = getFilePath("temp", null, false, user_uid: key);
string outFile = StorageManager.GetFilePath("temp", false, key);
if (outFile == null || !IO.File.Exists(outFile))
return ContentTo("{\"success\": false, \"msg\": \"outFile\"}");
@ -268,7 +258,7 @@ namespace Lampac.Controllers
if (HttpContext.Request.ContentLength > AppInit.conf.storage.max_size)
return ContentTo("{\"success\": false, \"msg\": \"max_size\"}");
string outFile = getFilePath("temp", null, true, user_uid: key);
string outFile = StorageManager.GetFilePath("temp", true, key);
if (outFile == null)
return ContentTo("{\"success\": false, \"msg\": \"outFile\"}");
@ -322,35 +312,5 @@ namespace Lampac.Controllers
});
}
#endregion
#region getFilePath
string getFilePath(string path, string pathfile, bool createDirectory, string user_uid = null)
{
if (path == "temp" && string.IsNullOrEmpty(user_uid))
return null;
path = Regex.Replace(path, "[^a-z0-9\\-]", "", RegexOptions.IgnoreCase);
string id = user_uid ?? requestInfo.user_uid;
if (string.IsNullOrEmpty(id))
return null;
id += pathfile;
string md5key = AppInit.conf.storage.md5name ? CrypTo.md5(id) : Regex.Replace(id, "[^a-z0-9\\-]", "");
if (path == "temp")
{
return $"database/storage/{path}/{md5key}";
}
else
{
if (createDirectory)
Directory.CreateDirectory($"database/storage/{path}/{md5key.Substring(0, 2)}");
return $"database/storage/{path}/{md5key.Substring(0, 2)}/{md5key.Substring(2)}";
}
}
#endregion
}
}

View File

@ -51,14 +51,14 @@ namespace Catalog.Controllers
html = rch.enable
? await rch.Post(url, init.card_parse.postData, headers, useDefaultHeaders: init.useDefaultHeaders)
: await Http.Post(url, httpdata, headers: headers, proxy: proxy.proxy, timeoutSeconds: init.timeout, httpversion: init.httpversion, useDefaultHeaders: init.useDefaultHeaders);
: await Http.Post(url, httpdata, headers: headers, proxy: proxy.proxy, timeoutSeconds: init.timeout, httpversion: init.GetHttpVersion(), useDefaultHeaders: init.useDefaultHeaders);
}
else
{
html = rch.enable
? await rch.Get(url, headers, useDefaultHeaders: init.useDefaultHeaders)
: init.priorityBrowser == "playwright" ? await PlaywrightBrowser.Get(init, url, headers, proxy.data, cookies: init.cookies)
: await Http.Get(url, headers: headers, proxy: proxy.proxy, timeoutSeconds: init.timeout, httpversion: init.httpversion, useDefaultHeaders: init.useDefaultHeaders);
: await Http.Get(url, headers: headers, proxy: proxy.proxy, timeoutSeconds: init.timeout, httpversion: init.GetHttpVersion(), useDefaultHeaders: init.useDefaultHeaders);
}
if (html == null)

View File

@ -99,14 +99,14 @@ namespace Catalog.Controllers
html = rch.enable
? await rch.Post(url.Replace("{page}", page.ToString()), data, headers, useDefaultHeaders: init.useDefaultHeaders)
: await Http.Post(url.Replace("{page}", page.ToString()), httpdata, headers: headers, proxy: proxy.proxy, timeoutSeconds: init.timeout, httpversion: init.httpversion, useDefaultHeaders: init.useDefaultHeaders);
: await Http.Post(url.Replace("{page}", page.ToString()), httpdata, headers: headers, proxy: proxy.proxy, timeoutSeconds: init.timeout, httpversion: init.GetHttpVersion(), useDefaultHeaders: init.useDefaultHeaders);
}
else
{
html = rch.enable
? await rch.Get(url.Replace("{page}", page.ToString()), headers, useDefaultHeaders: init.useDefaultHeaders)
: init.priorityBrowser == "playwright" ? await PlaywrightBrowser.Get(init, url.Replace("{page}", page.ToString()), headers, proxy.data, cookies: init.cookies)
: await Http.Get(url.Replace("{page}", page.ToString()), headers: headers, proxy: proxy.proxy, timeoutSeconds: init.timeout, httpversion: init.httpversion, useDefaultHeaders: init.useDefaultHeaders);
: await Http.Get(url.Replace("{page}", page.ToString()), headers: headers, proxy: proxy.proxy, timeoutSeconds: init.timeout, httpversion: init.GetHttpVersion(), useDefaultHeaders: init.useDefaultHeaders);
}
#endregion

View File

@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Newtonsoft.Json;
@ -19,7 +18,9 @@ namespace Lampac.Controllers
[HttpGet]
[AllowAnonymous]
[Route("/version")]
public ActionResult Version() => Content($"{appversion}.{minorversion}");
public ActionResult Version() => string.IsNullOrEmpty(versionTag)
? Content($"{appversion}.{minorversion}")
: Content($"{appversion}.{minorversion}-{versionTag}");
[HttpGet]
[AllowAnonymous]

View File

@ -317,13 +317,17 @@ namespace Lampac.Engine
if (name == "devices")
{
var evc = event_clients.Where(i => i.Value == uid).ToArray();
var uidClients = event_clients
.Where(i => i.Value == uid)
.ToDictionary();
var devices = _connections
.Where(i => i.Value.ConnectionId != connection.ConnectionId)
.Where(i => i.Value.Ip == connection.Ip || event_clients.Values.Contains(uid))
.Where(i =>
(!AppInit.conf.accsdb.enable && i.Value.Ip == connection.Ip)
|| uidClients.Keys.Contains(i.Key))
.Select(i => new {
uid = event_clients.TryGetValue(i.Value.ConnectionId, out var _uid) ? _uid : null,
uid = uidClients.TryGetValue(i.Value.ConnectionId, out var targetUid) ? targetUid : null,
i.Value.ConnectionId,
i.Value.RequestInfo.UserAgent
})
@ -517,7 +521,7 @@ namespace Lampac.Engine
try
{
var now = DateTime.UtcNow;
var cutoff = now.AddSeconds(-125); // ping êàæäûå 40 ñåêóíä
var cutoff = now.AddSeconds(-125);
foreach (var connection in _connections)
{

View File

@ -192,11 +192,17 @@ namespace Lampac
#endregion
#region vers.txt
Directory.CreateDirectory("data");
if (!File.Exists("data/vers.txt"))
File.WriteAllText("data/vers.txt", BaseController.appversion);
if (!File.Exists("data/vers-minor.txt"))
File.WriteAllText("data/vers-minor.txt", "1");
File.WriteAllText("data/vers-minor.txt", BaseController.minorversion);
if (!string.IsNullOrEmpty(BaseController.versionTag) && !File.Exists("data/vers-tag.txt"))
File.WriteAllText("data/vers-tag.txt", BaseController.versionTag);
#endregion
#region SQL
@ -421,6 +427,7 @@ namespace Lampac
if (AppInit.modules?.FirstOrDefault(i => i.dll == "DLNA.dll" && i.enable) != null)
TrackersCron.Run();
Directory.CreateDirectory("wwwroot");
LampaCron.Run();
appReload = new AppReload();

View File

@ -639,7 +639,7 @@ namespace Lampac
AppInit.conf.BaseModule.EnableControllers.Length == 0)
return;
WebLogEnableController = AppInit.conf.BaseModule.EnableControllers.Contains("WebLogController.cs");
WebLogEnableController = AppInit.conf.BaseModule.EnableControllers.Contains("WebLog");
var syntaxTree = new List<SyntaxTree>();

View File

@ -364,7 +364,7 @@ namespace Online.Controllers
);
var result = await Http.Post<JObject>("https://api.cdnlibs.org/api/auth/oauth/token", content,
httpversion: init.httpversion, timeoutSeconds: init.httptimeout, headers: headers, useDefaultHeaders: false
httpversion: init.GetHttpVersion(), timeoutSeconds: init.GetHttpTimeout(), headers: headers, useDefaultHeaders: false
);
if (result == null)

View File

@ -27,7 +27,7 @@ namespace Online.Controllers
async public Task<ActionResult> Pro()
{
string uri = $"{init.corsHost()}/api/v2/token_request?user_dev_apk=2.0.1&user_dev_id=&user_dev_name=Xiaomi&user_dev_os=11&user_dev_vendor=Xiaomi&user_dev_token=";
var token_request = await Http.Get<JObject>(uri, httpversion: init.httpversion, proxy: proxy, useDefaultHeaders: false);
var token_request = await Http.Get<JObject>(uri, httpversion: init.GetHttpVersion(), timeoutSeconds: init.GetHttpTimeout(), proxy: proxy, useDefaultHeaders: false);
if (token_request == null)
return ContentTo($"нет доступа к {init.corsHost()}");

View File

@ -122,7 +122,7 @@ namespace Online.Controllers
else
{
var rtk = await Http.Get<JObject>($"{init.corsHost()}/api-fx/request-token",
proxy: proxy, httpversion: init.httpversion, timeoutSeconds: 30
proxy: proxy, httpversion: init.GetHttpVersion(), timeoutSeconds: 30
);
if (rtk == null || !rtk.ContainsKey("token"))
@ -146,14 +146,14 @@ namespace Online.Controllers
string refreshToken = Regex.Match(F.ReadAllText(authFile), "\"refreshToken\": ?\"([^\"]+)\"").Groups[1].Value;
root_auth = await Http.Get<JObject>($"{init.corsHost()}/api-fx/refresh?refreshToken={HttpUtility.UrlEncode(refreshToken)}",
proxy: proxy, headers: HeadersModel.Init("hash", init.hash_apitv), httpversion: init.httpversion, timeoutSeconds: 30
proxy: proxy, headers: HeadersModel.Init("hash", init.hash_apitv), httpversion: init.GetHttpVersion(), timeoutSeconds: 30
);
}
else
{
var data = new System.Net.Http.StringContent($"{{\"user_name\":\"{init.user_apitv}\",\"user_passw\":\"{init.passwd_apitv}\",\"session\":true}}", Encoding.UTF8, "application/json");
root_auth = await Http.Post<JObject>($"{init.corsHost()}/api-fx/auth", data,
proxy: proxy, headers: HeadersModel.Init("hash", init.hash_apitv), httpversion: init.httpversion, timeoutSeconds: 30
proxy: proxy, headers: HeadersModel.Init("hash", init.hash_apitv), httpversion: init.GetHttpVersion(), timeoutSeconds: 30
);
}

View File

@ -33,7 +33,7 @@ namespace Online.Controllers
else
{
var postdata = new System.Net.Http.StringContent($"{{\"email\":\"{login}\",\"password\":\"{pass}\",\"fingerprint\":\"{CrypTo.md5(DateTime.Now.ToString())}\",\"device\":{{}}}}", Encoding.UTF8, "application/json");
var result = await Http.Post<JObject>($"{init.corsHost()}/api/login", postdata, httpversion: init.httpversion, proxy: proxy, headers: httpHeaders(init));
var result = await Http.Post<JObject>($"{init.corsHost()}/api/login", postdata, httpversion: init.GetHttpVersion(), proxy: proxy, headers: httpHeaders(init));
if (result == null)
return ContentTo("Ошибка авторизации ;(");

View File

@ -168,7 +168,7 @@ namespace Online.Controllers
string uri = $"{init.host}/v1/api/media/{(serial == 1 ? "serials" : "movies")}";
var data = new System.Net.Http.StringContent(JsonConvert.SerializeObject(new { search }), Encoding.UTF8, "application/json");
var video = await Http.Get<JObject>(uri, body: data, timeoutSeconds: init.httptimeout, proxy: proxy, useDefaultHeaders: false, headers: httpHeaders(init, HeadersModel.Init(
var video = await Http.Get<JObject>(uri, body: data, timeoutSeconds: init.GetHttpTimeout(), httpversion: init.GetHttpVersion(), proxy: proxy, useDefaultHeaders: false, headers: httpHeaders(init, HeadersModel.Init(
("X-API-AUTH", codeauth),
("X-API-ID", init.token.Split(":")[0])
)));

View File

@ -30,7 +30,7 @@ namespace Online.Controllers
if (string.IsNullOrWhiteSpace(code))
{
string uri = $"{init.corsHost()}/oauth2/device?grant_type=device_code&client_id=xbmc&client_secret=cgg3gtifu46urtfp2zp1nqtba0k2ezxh";
var token_request = await Http.Post<JObject>(uri, "", httpversion: init.httpversion, proxy: proxy, headers: httpHeaders(init));
var token_request = await Http.Post<JObject>(uri, "", httpversion: init.GetHttpVersion(), proxy: proxy, headers: httpHeaders(init));
if (token_request == null)
return ContentTo($"нет доступа к {init.corsHost()}");
@ -46,14 +46,14 @@ namespace Online.Controllers
else
{
string uri = $"{init.corsHost()}/oauth2/device?grant_type=device_token&client_id=xbmc&client_secret=cgg3gtifu46urtfp2zp1nqtba0k2ezxh&code={code}";
var device_token = await Http.Post<JObject>(uri, "", httpversion: init.httpversion, proxy: proxy, headers: httpHeaders(init));
var device_token = await Http.Post<JObject>(uri, "", httpversion: init.GetHttpVersion(), proxy: proxy, headers: httpHeaders(init));
if (device_token == null || string.IsNullOrWhiteSpace(device_token.Value<string>("access_token")))
return LocalRedirect("/lite/kinopubpro");
if (!string.IsNullOrEmpty(name))
{
uri = $"{init.corsHost()}/v1/device/notify?access_token={device_token.Value<string>("access_token")}";
await Http.Post(uri, $"&title={name}", httpversion: init.httpversion, proxy: proxy, headers: httpHeaders(init));
await Http.Post(uri, $"&title={name}", httpversion: init.GetHttpVersion(), proxy: proxy, headers: httpHeaders(init));
}
return ContentTo("Добавьте в init.conf<br><br>\"KinoPub\": {<br>&nbsp;&nbsp;\"enable\": true,<br>&nbsp;&nbsp;\"token\": \"" + device_token.Value<string>("access_token") + "\"<br>}");

View File

@ -119,7 +119,7 @@ namespace Online.Controllers
}
else if (init.priorityBrowser == "http")
{
location = await Http.GetLocation(link, httpversion: init.httpversion, timeoutSeconds: init.httptimeout, proxy: proxy, headers: headers);
location = await Http.GetLocation(link, httpversion: init.GetHttpVersion(), timeoutSeconds: init.GetHttpTimeout(), proxy: proxy, headers: headers);
}
else
{

View File

@ -41,7 +41,7 @@ namespace SISI.Controllers.Ebalovo
return res.currentUrl;
}
return await Http.GetLocation(init.cors(location), timeoutSeconds: init.httptimeout, httpversion: init.httpversion, proxy: proxy, headers: httpHeaders(init));
return await Http.GetLocation(init.cors(location), timeoutSeconds: init.GetHttpTimeout(), httpversion: init.GetHttpVersion(), proxy: proxy, headers: httpHeaders(init));
}
);

View File

@ -613,13 +613,13 @@ namespace SISI.Controllers.NextHUB
return rch?.enable == true
? await rch.Post(url.Replace("{page}", pg.ToString()), data, httpHeaders(init))
: await Http.Post(url.Replace("{page}", pg.ToString()), data, encoding: encodingResponse, headers: httpHeaders(init), proxy: proxy, timeoutSeconds: init.timeout, httpversion: init.httpversion);
: await Http.Post(url.Replace("{page}", pg.ToString()), data, encoding: encodingResponse, headers: httpHeaders(init), proxy: proxy, timeoutSeconds: init.GetHttpTimeout(), httpversion: init.GetHttpVersion());
}
else
{
return rch?.enable == true
? await rch.Get(url.Replace("{page}", pg.ToString()), httpHeaders(init))
: init.priorityBrowser == "http" ? await Http.Get(url.Replace("{page}", pg.ToString()), encoding: encodingResponse, headers: httpHeaders(init), proxy: proxy, timeoutSeconds: init.timeout, httpversion: init.httpversion)
: init.priorityBrowser == "http" ? await Http.Get(url.Replace("{page}", pg.ToString()), encoding: encodingResponse, headers: httpHeaders(init), proxy: proxy, timeoutSeconds: init.timeout, httpversion: init.GetHttpVersion())
: init.list.viewsource ? await PlaywrightBrowser.Get(init, url.Replace("{page}", pg.ToString()), httpHeaders(init), proxy_data, cookies: init.cookies)
: await ContentAsync(init, url.Replace("{page}", pg.ToString()), httpHeaders(init), proxy_data, search, sort, cat, model, pg);
}

View File

@ -89,7 +89,7 @@ namespace SISI.Controllers.Porntrex
}
else
{
location = await Http.GetLocation(init.cors(link), timeoutSeconds: init.httptimeout, httpversion: init.httpversion, proxy: proxy, headers: headers);
location = await Http.GetLocation(init.cors(link), timeoutSeconds: init.GetHttpTimeout(), httpversion: init.GetHttpVersion(), proxy: proxy, headers: headers);
}
if (string.IsNullOrEmpty(location) || link == location)

View File

@ -45,7 +45,7 @@ namespace SISI.Controllers.XvideosRED
}
#endregion
string html = await Http.Get(init.cors(url), cookie: init.cookie, timeoutSeconds: init.httptimeout, proxy: proxy, headers: httpHeaders(init));
string html = await Http.Get(init.cors(url), cookie: init.cookie, timeoutSeconds: init.GetHttpVersion(), httpversion: init.GetHttpVersion(), proxy: proxy, headers: httpHeaders(init));
if (html == null)
return OnError("html", refresh_proxy: string.IsNullOrEmpty(search));

View File

@ -21,7 +21,7 @@ namespace SISI.Controllers.XvideosRED
if (url == null)
return OnError("stream_links");
string html = await Http.Get(url, cookie: init.cookie, timeoutSeconds: init.httptimeout, proxy: proxy, headers: httpHeaders(init));
string html = await Http.Get(url, cookie: init.cookie, timeoutSeconds: init.GetHttpVersion(), httpversion: init.GetHttpVersion(), proxy: proxy, headers: httpHeaders(init));
if (html == null)
return OnError("stream_links");

View File

@ -464,7 +464,7 @@ namespace Shared
public SyncUserConf sync_user = new SyncUserConf() { enable = true, version = 2 };
public StorageConf storage = new StorageConf() { enable = true, max_size = 7_000000, brotli = false, md5name = true };
public StorageConf storage = new StorageConf() { enable = true, max_size = 7_000000, brotli = false, };
public GCConf GC { get; set; } = new GCConf()
{

View File

@ -24,10 +24,12 @@ namespace Shared
{
public class BaseController : Controller
{
public static string appversion => "154";
public static string minorversion => "3";
public static string versionTag => "ce";
public static string appversion => "155";
public static string minorversion => "1";
protected static readonly ConcurrentDictionary<string, SemaphoreSlim> _semaphoreLocks = new();

View File

@ -27,7 +27,7 @@ namespace Shared.Engine
return IsRchEnable(safety)
? rch.Get<T>(init.cors(url), headers, IgnoreDeserializeObject, useDefaultHeaders)
: Http.Get<T>(init.cors(url), timeoutSeconds: init.httptimeout, httpversion: init.httpversion, proxy: proxy, headers: headers, useDefaultHeaders: useDefaultHeaders, statusCodeOK: statusCodeOK);
: Http.Get<T>(init.cors(url), timeoutSeconds: init.GetHttpTimeout(), httpversion: init.GetHttpVersion(), proxy: proxy, headers: headers, useDefaultHeaders: useDefaultHeaders, statusCodeOK: statusCodeOK);
}
public Task<string> Get(string url, List<HeadersModel> addheaders = null, List<HeadersModel> newheaders = null, bool useDefaultHeaders = true, bool statusCodeOK = true, Encoding encoding = default, bool safety = false)
@ -36,7 +36,7 @@ namespace Shared.Engine
return IsRchEnable(safety)
? rch.Get(init.cors(url), headers, useDefaultHeaders)
: Http.Get(init.cors(url), encoding, timeoutSeconds: init.httptimeout, httpversion: init.httpversion, proxy: proxy, headers: headers, useDefaultHeaders: useDefaultHeaders, statusCodeOK: statusCodeOK);
: Http.Get(init.cors(url), encoding, timeoutSeconds: init.GetHttpTimeout(), httpversion: init.GetHttpVersion(), proxy: proxy, headers: headers, useDefaultHeaders: useDefaultHeaders, statusCodeOK: statusCodeOK);
}
#endregion
@ -47,7 +47,7 @@ namespace Shared.Engine
return IsRchEnable(safety)
? rch.GetSpan(spanAction, init.cors(url), headers, useDefaultHeaders)
: Http.GetSpan(spanAction, init.cors(url), timeoutSeconds: init.httptimeout, httpversion: init.httpversion, proxy: proxy, headers: headers, useDefaultHeaders: useDefaultHeaders, statusCodeOK: statusCodeOK);
: Http.GetSpan(spanAction, init.cors(url), timeoutSeconds: init.GetHttpTimeout(), httpversion: init.GetHttpVersion(), proxy: proxy, headers: headers, useDefaultHeaders: useDefaultHeaders, statusCodeOK: statusCodeOK);
}
#endregion
@ -58,7 +58,7 @@ namespace Shared.Engine
return IsRchEnable(safety)
? rch.Post<T>(init.cors(url), data, headers, IgnoreDeserializeObject, useDefaultHeaders)
: Http.Post<T>(init.cors(url), data, encoding: encoding, timeoutSeconds: init.httptimeout, httpversion: init.httpversion, proxy: proxy, headers: headers, useDefaultHeaders: useDefaultHeaders, statusCodeOK: statusCodeOK);
: Http.Post<T>(init.cors(url), data, encoding: encoding, timeoutSeconds: init.GetHttpTimeout(), httpversion: init.GetHttpVersion(), proxy: proxy, headers: headers, useDefaultHeaders: useDefaultHeaders, statusCodeOK: statusCodeOK);
}
public Task<string> Post(string url, string data, List<HeadersModel> addheaders = null, List<HeadersModel> newheaders = null, bool useDefaultHeaders = true, bool statusCodeOK = true, Encoding encoding = default, bool safety = false)
@ -67,7 +67,7 @@ namespace Shared.Engine
return IsRchEnable(safety)
? rch.Post(init.cors(url), data, headers, useDefaultHeaders)
: Http.Post(init.cors(url), data, encoding: encoding, timeoutSeconds: init.httptimeout, httpversion: init.httpversion, proxy: proxy, headers: headers, useDefaultHeaders: useDefaultHeaders, statusCodeOK: statusCodeOK);
: Http.Post(init.cors(url), data, encoding: encoding, timeoutSeconds: init.GetHttpTimeout(), httpversion: init.GetHttpVersion(), proxy: proxy, headers: headers, useDefaultHeaders: useDefaultHeaders, statusCodeOK: statusCodeOK);
}
#endregion
@ -78,7 +78,7 @@ namespace Shared.Engine
return IsRchEnable(safety)
? rch.PostSpan(spanAction, init.cors(url), data, headers, useDefaultHeaders)
: Http.PostSpan(spanAction, init.cors(url), data, encoding: encoding, timeoutSeconds: init.httptimeout, httpversion: init.httpversion, proxy: proxy, headers: headers, useDefaultHeaders: useDefaultHeaders, statusCodeOK: statusCodeOK);
: Http.PostSpan(spanAction, init.cors(url), data, encoding: encoding, timeoutSeconds: init.GetHttpTimeout(), httpversion: init.GetHttpVersion(), proxy: proxy, headers: headers, useDefaultHeaders: useDefaultHeaders, statusCodeOK: statusCodeOK);
}
#endregion

View File

@ -0,0 +1,161 @@
using System.Text;
using Shared.Models;
namespace Shared.Engine
{
public static class StorageManager
{
private const string TempDirectoryName = "temp";
private static readonly string BaseStoragePath =
Path.GetFullPath("database/storage");
private static readonly string BaseTempStoragePath = $"{BaseStoragePath}/{TempDirectoryName}";
static StorageManager()
{
Directory.CreateDirectory(BaseStoragePath);
Directory.CreateDirectory(BaseTempStoragePath);
}
public static string? GetFilePath(
string pathType,
bool createDirectory = false,
RequestModel? requestInfo = null,
string? profileUid = null)
{
return GetFilePath(pathType, createDirectory, requestInfo?.user_uid, profileUid);
}
public static string? GetFilePath(
string pathType,
bool createDirectory = false,
string? userUid = null,
string? profileUid = null)
{
if (string.IsNullOrWhiteSpace(userUid))
{
return null;
}
string cleanedUserId = CleanIdentifier(userUid);
if (string.IsNullOrEmpty(cleanedUserId))
{
return null;
}
string cleanedProfileUid = CleanIdentifier(profileUid ?? string.Empty);
string hashInput = cleanedUserId + cleanedProfileUid;
string md5Key = CrypTo.md5(hashInput);
string safePathType = CleanPathType(pathType);
if (string.IsNullOrEmpty(safePathType))
{
return null;
}
string fullPath;
try
{
if (safePathType == TempDirectoryName)
{
fullPath = $"{BaseStoragePath}/{TempDirectoryName}/{md5Key}";
}
else
{
string level1 = md5Key[..2];
string level2 = md5Key[2..];
string directoryPath = $"{BaseStoragePath}/{safePathType}/{level1}";
fullPath = $"{directoryPath}/{level2}";
}
}
catch
{
return null;
}
if (!fullPath.StartsWith(BaseStoragePath + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)
&& !string.Equals(fullPath, BaseStoragePath, StringComparison.OrdinalIgnoreCase))
{
return null;
}
if (!createDirectory || safePathType == TempDirectoryName)
{
return fullPath;
}
try
{
string directoryPath = Path.GetDirectoryName(fullPath);
if (!string.IsNullOrEmpty(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
}
catch
{
// ignore all exceptions
return null;
}
return fullPath;
}
private static string CleanIdentifier(string? input)
{
if (string.IsNullOrWhiteSpace(input))
return "";
var sb = new StringBuilder(input.Length);
foreach (var c in input.Where(c => char.IsLetterOrDigit(c)
|| c is '-' or '_' or '@' or '.' or '+' or '='))
{
sb.Append(c);
}
string cleaned = sb.ToString();
if (cleaned.Length is 0 or > 160
|| cleaned.StartsWith(".")
|| cleaned.EndsWith(".")
|| cleaned.Contains("..")
|| cleaned.Contains("//")
|| cleaned.Contains(@"\")
|| cleaned.Contains(":"))
{
return "";
}
return cleaned;
}
private static string CleanPathType(string? input)
{
if (string.IsNullOrWhiteSpace(input))
return "";
var sb = new StringBuilder();
foreach (var c in input.ToLowerInvariant().Where(c => char.IsLetterOrDigit(c)
|| c is '-' or '_'))
{
sb.Append(c);
}
string cleaned = sb.ToString();
if (cleaned.Length is 0 or > 40
|| cleaned.Contains("..")
|| cleaned.StartsWith("-")
|| cleaned.EndsWith("-"))
{
return "";
}
return cleaned;
}
}
}

View File

@ -7,7 +7,5 @@
public long max_size { get; set; }
public bool brotli { get; set; }
public bool md5name { get; set; }
}
}

View File

@ -138,10 +138,13 @@ namespace Shared.Models.Base
public string priorityBrowser { get; set; }
public int httptimeout { get; set; } = 8;
public int httpversion { get; set; } = 1;
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public int? httptimeout { get; set; }
public int GetHttpTimeout() => httpversion ?? 8;
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public int? httpversion { get; set; }
public int GetHttpVersion() => httpversion ?? 1;
#region proxy
public bool useproxy { get; set; }