mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-02-27 11:08:26 -06:00
fixing issue with jsonelements inside variables when passing to function code
This commit is contained in:
@@ -9,6 +9,7 @@ namespace FileFlows.BasicNodes.Functions
|
||||
using System.Text;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Text.Json;
|
||||
|
||||
public class Function : Node
|
||||
{
|
||||
@@ -52,6 +53,17 @@ namespace FileFlows.BasicNodes.Functions
|
||||
// so Variables.file?.Orig.Name, will be replaced to Variables["file.Orig.Name"]
|
||||
// since its just a dictionary key value
|
||||
string keyRegex = @"Variables(\?)?\." + k.Replace(".", @"(\?)?\.");
|
||||
|
||||
|
||||
object? value = args.Variables[k];
|
||||
if (value is JsonElement jElement)
|
||||
{
|
||||
if (jElement.ValueKind == JsonValueKind.String)
|
||||
value = jElement.GetString();
|
||||
if (jElement.ValueKind == JsonValueKind.Number)
|
||||
value = jElement.GetInt64();
|
||||
}
|
||||
|
||||
tcode = Regex.Replace(tcode, keyRegex, "Variables['" + k + "']");
|
||||
}
|
||||
|
||||
|
||||
@@ -403,6 +403,31 @@ return 2; // it isn't so call output 2";
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void Function_FileNameStringVariable()
|
||||
{
|
||||
Function pm = new Function();
|
||||
var logger = new TestLogger();
|
||||
var args = new FileFlows.Plugin.NodeParameters(@"D:\videos\unprocessed\movie h264.mkv", logger, false, string.Empty);
|
||||
pm.Code = @"
|
||||
let newName = Variables.file.Name;
|
||||
|
||||
if (newName.indexOf('h264') > 0)
|
||||
newName = newName.replace('h264', 'h265');
|
||||
else if (newName.indexOf('hevc') > 0)
|
||||
newName = newName.replace('hevc', 'h265');
|
||||
else
|
||||
newName += ' h265';
|
||||
if (newName == Variables.file.Name)
|
||||
return 2;
|
||||
|
||||
Variables.NewName = newName;
|
||||
return 1;
|
||||
; ";
|
||||
var result = pm.Execute(args);
|
||||
Assert.AreEqual(1, result);
|
||||
Assert.AreEqual("movie h265", args.Variables["NewName"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user