Зыков М. А., ПрИ-101 - #2
Open
0xddi wants to merge 5 commits into
Open
Conversation
MindHardt
reviewed
Jan 8, 2026
| } | ||
|
|
||
| private static bool IsValidUri(string uri) => uri.StartsWith("https://"); | ||
| private static bool IsValidUri(string uri) => Uri.TryCreate(uri, UriKind.Absolute, out _) && uri.StartsWith("https://"); |
Owner
There was a problem hiding this comment.
Нам не обязательно чтобы был https, локалхост или штуки доступные только внутри сети часто http
MindHardt
reviewed
Jan 8, 2026
| /// Считывает от пользователя путь до файла с результатом. | ||
| /// </summary> | ||
| public static FileInfo GetOutputFile() | ||
| public static FileInfo GetPathToOutputFile() |
Owner
There was a problem hiding this comment.
Ты получаешь не Path, а прям полный FileInfo, зря переименовал
MindHardt
reviewed
Jan 8, 2026
| { | ||
| Console.WriteLine("[?] Файл уже существует. Хотите ли вы его перезаписать? [y/n]"); | ||
| Console.Write(">>"); | ||
| var answer = Console.ReadLine()!.Trim().ToLower(); |
Owner
There was a problem hiding this comment.
Не обязательно считывать всю строку, можно Console.ReadKey()
MindHardt
reviewed
Jan 8, 2026
|
|
||
| using (StreamReader reader = new StreamReader(filePath.FullName)) | ||
| { | ||
| while (reader.ReadLine() != null) |
Owner
There was a problem hiding this comment.
Здесь стоит юзать асинк версию (всегда стоит юзать асинк версию)
MindHardt
reviewed
Jan 8, 2026
|
|
||
|
|
||
| // Несколько попыток удаления | ||
| for (int i = 0; i < 3; i++) |
MindHardt
reviewed
Jan 8, 2026
| await content.CopyToAsync(destStream, ct); | ||
| }); | ||
| // закрываем FileStream асинхронно | ||
| if (fileStreamIsClosed is false) |
Owner
There was a problem hiding this comment.
Эта проверка не обязательна, файлстрим можно диспозить несколько раз, он не против
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Для потокобезопасности по итогу воспользовался SemaphoreSlim, т.к. судя по всему lock не очень дружит с асинхронщиной внутри него самого (в частности, внутри должен быть await contentStream.CopyToAsync(destStream, ct)). Как-то так.
Валидация пути для сохранения файла через попытку создания одноимённого файла (при условии его несуществования) слишком прямолинейная, но зато вроде оптимальная по кол-ву кода. Проверка на разрешённые символы бесполезна, регулярки тоже, а отдельно проверять существование директории и ещё в придачу права на запись туда как-то излишне, на мой взгляд. Может я, конечно, не прав.