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 below media-staging of the data directory, which the lab deletes once it has read the /// transcript; whatever a crash leaves there, TranscriptStagingCleanupService removes with the next start. Backups /// leave that folder out. /// /// The data directory of AI Studio. internal sealed class BflTranscriptLocation(string dataDirectory) : IMediaTranscriptLocation { /// /// The folder of the data directory for transcripts on their way, shared with the chat; see TranscriptStagingCleanupService. /// private const string STAGING_DIRECTORY_NAME = "media-staging"; /// /// 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; } = Path.Combine(dataDirectory, STAGING_DIRECTORY_NAME, $"bfl-{Guid.NewGuid():N}"); /// 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; } } }