/
iRumba
/
MdToDocx
Обзор
Документация
Войти
/
iRumba
/
MdToDocx
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
src/MdToDocx.Server/Services/FileValidator.cs
54 строки
2 KB
iRumba
refactor: restructure project to src/ modules, remove .opencode/
25 май 2026, 07:05
25 май 2026, 07:05
c692142
Код
Авторство
О чём код?
namespace MdToDocx.Server.Services; public class FileValidator : IFileValidator { private const int MaxMdFileSize = 10 * 1024 * 1024; // 10 MB private const int MaxDotxFileSize = 5 * 1024 * 1024; // 5 MB private static readonly string[] AllowedMdExtensions = { ".md", ".markdown" }; private static readonly string[] AllowedDotxExtensions = { ".dotx" }; public (bool IsValid, string? Error) ValidateMdFile(IFormFile file) { if (file.Length == 0) return (false, "File is empty."); if (file.Length > MaxMdFileSize) return (false, $"File exceeds maximum size of 10 MB."); var ext = Path.GetExtension(file.FileName).ToLowerInvariant(); if (!AllowedMdExtensions.Contains(ext)) return (false, "File must have .md or .markdown extension."); return (true, null); } public (bool IsValid, string? Error) ValidateDotxFile(IFormFile file) { if (file.Length == 0) return (false, "Template file is empty."); if (file.Length > MaxDotxFileSize) return (false, $"Template file exceeds maximum size of 5 MB."); var ext = Path.GetExtension(file.FileName).ToLowerInvariant(); if (!AllowedDotxExtensions.Contains(ext)) return (false, "Template file must have .dotx extension."); return (true, null); } public (bool IsValid, string? Error) ValidateUrl(string url) { if (string.IsNullOrWhiteSpace(url)) return (false, "URL is empty."); if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) return (false, "URL is not valid."); if (uri.Scheme != "http" && uri.Scheme != "https") return (false, "URL must use HTTP or HTTPS scheme."); return (true, null); } }