using AIStudio.Tools.Media; namespace AIStudio.Assistants.BeyondFactsLab; /// /// Where the transcript of a recording waits while the lab turns it into material, cf. PersistentMediaTranscript. /// /// /// 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. /// internal sealed class BflTranscriptLocation : IMediaTranscriptLocation { /// /// The name of the transcript in its folder. /// private const string TRANSCRIPT_FILE_NAME = "transcript.md"; /// /// Gets the folder of this transcript, which no other one shares. /// public string FolderPath { get; } = TemporaryFiles.CreateDirectory(); /// public Task ResolveAsync(string mediaPath, CancellationToken token) { var path = Path.Combine(this.FolderPath, TRANSCRIPT_FILE_NAME); return Task.FromResult(new MediaTranscriptSlot(path, path)); } /// /// Deletes the transcript with its folder, without failing. /// /// False when the folder could not be deleted; the next start removes it. 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; } } }