Merge pull request #9340 from Bond-009/using

This commit is contained in:
Bond-009 2023-02-17 22:01:17 +01:00 committed by GitHub
commit 9979b346ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -193,43 +193,43 @@ namespace MediaBrowser.Providers.Subtitles
await stream.CopyToAsync(memoryStream).ConfigureAwait(false); await stream.CopyToAsync(memoryStream).ConfigureAwait(false);
memoryStream.Position = 0; memoryStream.Position = 0;
} }
}
var savePaths = new List<string>(); var savePaths = new List<string>();
var saveFileName = Path.GetFileNameWithoutExtension(video.Path) + "." + response.Language.ToLowerInvariant(); var saveFileName = Path.GetFileNameWithoutExtension(video.Path) + "." + response.Language.ToLowerInvariant();
if (response.IsForced) if (response.IsForced)
{
saveFileName += ".forced";
}
saveFileName += "." + response.Format.ToLowerInvariant();
if (saveInMediaFolder)
{
var mediaFolderPath = Path.GetFullPath(Path.Combine(video.ContainingFolderPath, saveFileName));
// TODO: Add some error handling to the API user: return BadRequest("Could not save subtitle, bad path.");
if (mediaFolderPath.StartsWith(video.ContainingFolderPath, StringComparison.Ordinal))
{ {
savePaths.Add(mediaFolderPath); saveFileName += ".forced";
} }
}
var internalPath = Path.GetFullPath(Path.Combine(video.GetInternalMetadataPath(), saveFileName)); saveFileName += "." + response.Format.ToLowerInvariant();
// TODO: Add some error to the user: return BadRequest("Could not save subtitle, bad path."); if (saveInMediaFolder)
if (internalPath.StartsWith(video.GetInternalMetadataPath(), StringComparison.Ordinal)) {
{ var mediaFolderPath = Path.GetFullPath(Path.Combine(video.ContainingFolderPath, saveFileName));
savePaths.Add(internalPath); // TODO: Add some error handling to the API user: return BadRequest("Could not save subtitle, bad path.");
} if (mediaFolderPath.StartsWith(video.ContainingFolderPath, StringComparison.Ordinal))
{
savePaths.Add(mediaFolderPath);
}
}
if (savePaths.Count > 0) var internalPath = Path.GetFullPath(Path.Combine(video.GetInternalMetadataPath(), saveFileName));
{
await TrySaveToFiles(memoryStream, savePaths).ConfigureAwait(false); // TODO: Add some error to the user: return BadRequest("Could not save subtitle, bad path.");
} if (internalPath.StartsWith(video.GetInternalMetadataPath(), StringComparison.Ordinal))
else {
{ savePaths.Add(internalPath);
_logger.LogError("An uploaded subtitle could not be saved because the resulting paths were invalid."); }
if (savePaths.Count > 0)
{
await TrySaveToFiles(memoryStream, savePaths).ConfigureAwait(false);
}
else
{
_logger.LogError("An uploaded subtitle could not be saved because the resulting paths were invalid.");
}
} }
} }