mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-12-03 03:54:24 +00:00
40 lines
1.7 KiB
C#
40 lines
1.7 KiB
C#
namespace AIStudio.Tools.Services.Indexing;
|
|
|
|
/// <summary>
|
|
/// The files an attachment is written to while the runtime reads its text.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The runtime reads documents from disk only. An attachment therefore lands in a file of its own
|
|
/// for as long as its text is read, and is deleted right after. Their names are random: the
|
|
/// runtime logs the path it reads, and the name of an attachment may name a person.
|
|
///
|
|
/// The files lie in the temporary folder of AI Studio, see TemporaryFiles. Whatever a crash left
|
|
/// behind is deleted when AI Studio starts again.
|
|
/// </remarks>
|
|
internal static class MailAttachmentFiles
|
|
{
|
|
/// <summary>
|
|
/// Makes up the path of a file for one attachment.
|
|
/// </summary>
|
|
/// <param name="extension">The extension of the attachment, checked against the known document types beforehand, without a dot.</param>
|
|
/// <returns>The path, where no file exists yet.</returns>
|
|
/// <exception cref="InvalidOperationException">AI Studio has not set its temporary folder yet.</exception>
|
|
public static string CreatePath(string extension) => TemporaryFiles.GetFilePath($".{extension}");
|
|
|
|
/// <summary>
|
|
/// Deletes the file of one attachment, should it exist.
|
|
/// </summary>
|
|
/// <param name="path">The path from CreatePath.</param>
|
|
/// <param name="logger">The logger, for a file which cannot be deleted. The next start deletes it.</param>
|
|
public static void Delete(string path, ILogger logger)
|
|
{
|
|
try
|
|
{
|
|
File.Delete(path);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
logger.LogWarning(exception, "The temporary file '{Path}' of a mail attachment could not be deleted. It is deleted on the next start.", path);
|
|
}
|
|
}
|
|
} |