Files
tytdcompanion/ReloadingScript.cs
T
2026-03-15 22:15:34 -05:00

35 lines
918 B
C#

using Tesses.WebServer;
using Scriban;
namespace Tesses.YouTubeDownloader2025Companion
{
public class ReloadingScript(string path)
{
DateTime created=new DateTime(1970,1,1);
Template? template;
private string path = path;
public string Render(object val)
{
Template? template;
lock(this)
{
template = this.template;
var cd = File.GetLastWriteTime(path);
if(cd > created || this.template is null)
{
template = Template.Parse(File.ReadAllText(path));
this.template = template;
created = cd;
}
}
if(template is not null)
{
return template.Render(val);
}
throw new FileNotFoundException("Not found");
}
}
}