mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-12-03 03:54:24 +00:00
51 lines
1.8 KiB
C#
51 lines
1.8 KiB
C#
using AIStudio.Tools.Media;
|
|
|
|
namespace AIStudio.Assistants.BeyondFactsLab;
|
|
|
|
/// <summary>
|
|
/// Where the transcript of a recording waits while the lab turns it into material, cf. PersistentMediaTranscript.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The lab keeps only the filtered text of a transcript, as the text of the material. The transcript itself lies in
|
|
/// a folder of its own in the temporary folder of AI Studio, which the lab deletes once it has read the transcript;
|
|
/// whatever a crash leaves there is gone with the next start of AI Studio, see TemporaryFiles. Backups leave that
|
|
/// folder out.
|
|
/// </remarks>
|
|
internal sealed class BflTranscriptLocation : IMediaTranscriptLocation
|
|
{
|
|
/// <summary>
|
|
/// The name of the transcript in its folder.
|
|
/// </summary>
|
|
private const string TRANSCRIPT_FILE_NAME = "transcript.md";
|
|
|
|
/// <summary>
|
|
/// Gets the folder of this transcript, which no other one shares.
|
|
/// </summary>
|
|
public string FolderPath { get; } = TemporaryFiles.CreateDirectory();
|
|
|
|
/// <inheritdoc />
|
|
public Task<MediaTranscriptSlot> ResolveAsync(string mediaPath, CancellationToken token)
|
|
{
|
|
var path = Path.Combine(this.FolderPath, TRANSCRIPT_FILE_NAME);
|
|
return Task.FromResult(new MediaTranscriptSlot(path, path));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deletes the transcript with its folder, without failing.
|
|
/// </summary>
|
|
/// <returns>False when the folder could not be deleted; the next start removes it.</returns>
|
|
public bool TryDelete()
|
|
{
|
|
try
|
|
{
|
|
if (Directory.Exists(this.FolderPath))
|
|
Directory.Delete(this.FolderPath, true);
|
|
|
|
return true;
|
|
}
|
|
catch (Exception exception) when (exception is IOException or UnauthorizedAccessException)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
} |