Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.3.2 #212

Merged
merged 3 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Raytha.Application.Common.Utils;

public static class WebTemplateExtensions
{
public const string RENDERBODY_REGEX = @"{%\s*\b(renderbody)\s*%}";
public const string RENDERBODY_REGEX = @"{%\s*\b(?:renderbody)\s*%}";

public static bool HasRenderBodyTag(string s)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,85 +31,84 @@ public RaythaFunctionScriptEngine(IRaythaFunctionApi_V1 raythaFunctionApiV1,

public async Task<object> Evaluate(string code, string method, TimeSpan executeTimeout, CancellationToken cancellationToken)
{
using (var _engine = new V8ScriptEngine())
{
_engine.AddHostObject("API_V1", _raythaFunctionApiV1);
_engine.AddHostObject("CurrentOrganization", _currentOrganization);
_engine.AddHostObject("CurrentUser", _currentUser);
_engine.AddHostObject("Emailer", _emailer);
_engine.AddHostObject("HttpClient", _httpClient);
_engine.AddHostObject("host", new HostFunctions());
_engine.AddHostObject("clr", new HostTypeCollection("mscorlib", "System", "System.Core", "System.Linq", "System.Collections"));
_engine.AddHostType(typeof(JavaScriptExtensions));
_engine.AddHostType(typeof(Enumerable));
_engine.AddHostType(typeof(ShortGuid));
_engine.AddHostType(typeof(Guid));
_engine.AddHostType(typeof(Convert));
_engine.AddHostType(typeof(EmailMessage));
_engine.Execute("var System = clr.System;");
_engine.Execute(@"
class JsonResult {
constructor(obj) {
this.body = obj;
this.contentType = 'application/json';
}
}
var _engine = new V8ScriptEngine();
_engine.AddHostObject("API_V1", _raythaFunctionApiV1);
_engine.AddHostObject("CurrentOrganization", _currentOrganization);
_engine.AddHostObject("CurrentUser", _currentUser);
_engine.AddHostObject("Emailer", _emailer);
_engine.AddHostObject("HttpClient", _httpClient);
_engine.AddHostObject("host", new HostFunctions());
_engine.AddHostObject("clr", new HostTypeCollection("mscorlib", "System", "System.Core", "System.Linq", "System.Collections"));
_engine.AddHostType(typeof(JavaScriptExtensions));
_engine.AddHostType(typeof(Enumerable));
_engine.AddHostType(typeof(ShortGuid));
_engine.AddHostType(typeof(Guid));
_engine.AddHostType(typeof(Convert));
_engine.AddHostType(typeof(EmailMessage));
_engine.Execute("var System = clr.System;");
_engine.Execute(@"
class JsonResult {
constructor(obj) {
this.body = obj;
this.contentType = 'application/json';
}
}

class HtmlResult {
constructor(html) {
this.body = html;
this.contentType = 'text/html';
}
}
class HtmlResult {
constructor(html) {
this.body = html;
this.contentType = 'text/html';
}
}

class RedirectResult {
constructor(url) {
this.body = url;
this.contentType = 'redirectToUrl';
}
}
class RedirectResult {
constructor(url) {
this.body = url;
this.contentType = 'redirectToUrl';
}
}

class StatusCodeResult {
constructor(statusCode, error) {
this.statusCode = statusCode;
this.body = error;
this.contentType = 'statusCode';
}
}");
class StatusCodeResult {
constructor(statusCode, error) {
this.statusCode = statusCode;
this.body = error;
this.contentType = 'statusCode';
}
}");

try
try
{
_engine.Execute(code);
return await Task.Run(async () =>
{
_engine.Execute(code);
return await Task.Run(async () =>
{
var result = _engine.Evaluate(method);
var result = _engine.Evaluate(method);

// The script can be synchronous or asynchronous, so this simple solution is used to convert the result
// Source: https://github.com/microsoft/ClearScript/issues/366
try
{
return await result.ToTask();
}
catch (ArgumentException)
{
return result;
}
}, cancellationToken).WaitAsync(executeTimeout, cancellationToken);
}
catch (TimeoutException)
{
throw new RaythaFunctionExecuteTimeoutException("The function execution time has exceeded the timeout");
}
catch (ScriptEngineException exception)
{
throw new RaythaFunctionScriptException(exception.ErrorDetails);
}
// The script can be synchronous or asynchronous, so this simple solution is used to convert the result
// Source: https://github.com/microsoft/ClearScript/issues/366
try
{
return await result.ToTask();
}
catch (ArgumentException)
{
return result;
}
}, cancellationToken).WaitAsync(executeTimeout, cancellationToken);
}
catch (TimeoutException)
{
throw new RaythaFunctionExecuteTimeoutException("The function execution time has exceeded the timeout");
}
catch (ScriptEngineException exception)
{
throw new RaythaFunctionScriptException(exception.ErrorDetails);
}
}

public async Task<object> EvaluateGet(string code,string query, TimeSpan executeTimeout, CancellationToken cancellationToken)
{
return await Evaluate(code, $"get({query})", executeTimeout, cancellationToken);
var result = await Evaluate(code, $"get({query})", executeTimeout, cancellationToken);
return result;
}

public async Task<object> EvaluatePost(string code, string payload, string query, TimeSpan executeTimeout, CancellationToken cancellationToken)
Expand Down
2 changes: 1 addition & 1 deletion src/Raytha.Web/Services/CurrentVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ namespace Raytha.Web.Services;

public class CurrentVersion : ICurrentVersion
{
public string Version => "1.3.1";
public string Version => "1.3.2";
}
Loading