Running a Pascal Script on the start of a profile

English Support for Syncovery on Linux etc.
Post Reply
semaj4712
Posts: 3
Joined: Mon Mar 06, 2023 5:04 am

Running a Pascal Script on the start of a profile

Post by semaj4712 »

I think I have this code correct, but It does not seem to be triggering or maybe it is, but I cannot tell, ultimately I am not getting the result I would expect on the other end of this request.

Code: Select all

function OnCanRunProfile(const ProfileName: UnicodeString; var PostponeBySeconds: Integer): Boolean;
var
  ntfy_username, ntfy_password, PostData, AdditionalHeaders, URL, Response, ErrorResponse: AnsiString;
  ResultCode: Int64;
begin
  ntfy_username := 'username';
  ntfy_password := 'password';

  PostData := 'Backup of the Master Output share is starting';
  AdditionalHeaders := 'Title: Syncovery Backup Starting...'+#10#13+
                     'Priority: default'+#10#13+
                     'Tags: arrows_counterclockwise'+#10#13+
                     'Authorization: Basic ' + EncodeBase64(ntfy_username + ':' + ntfy_password)+#10#13+
                     'Content-Type: application/x-www-form-urlencoded';

  URL := 'https://ntfy.url.com/Beltzer';

  ResultCode := 0;
  Response := '';
  ErrorResponse := '';
  if SendHTTPRequest('POST', '', AdditionalHeaders, URL, PostData, ResultCode, Response, ErrorResponse) then
  begin
    // HTTP request was successful, do something with the response
  end
  else
  begin
    // HTTP request failed, do something with the error response
  end;

  Result := True; // or False, depending on your requirements
end;
Obviously username, password, and url have been redacted

Please let me know if there is any obvious issues with this code

tobias
Posts: 1603
Joined: Tue Mar 31, 2020 7:37 pm

Re: Running a Pascal Script on the start of a profile

Post by tobias »

Hello,
can you try the following hook instead?

Code: Select all

function OnGetProfilePathBeforeListing(const isRightSide:Boolean;
        var Path,UserName,Password:UnicodeString;
        var AuthKey,AuthKeyPassword:AnsiString;
        var Port:Integer):Boolean;
This will be called as one of the first things when the profile runs. It has the advantage of being able to use the Log function like this:

Log('Calling HTTP Request Now.');

The hook you used is called by the scheduler, which means you can't use the Log function.

semaj4712
Posts: 3
Joined: Mon Mar 06, 2023 5:04 am

Re: Running a Pascal Script on the start of a profile

Post by semaj4712 »

Is there something I should be looking for in the logs, I see the Pascal script in the summary, but nothing referencing it other than that

tobias
Posts: 1603
Joined: Tue Mar 31, 2020 7:37 pm

Re: Running a Pascal Script on the start of a profile

Post by tobias »

There should be a line saying:

"Successfully compiled the profile's script."

Other than that, you need to add logging to the script by calling the Log function.

The lines will be in the log file.

semaj4712
Posts: 3
Joined: Mon Mar 06, 2023 5:04 am

Re: Running a Pascal Script on the start of a profile

Post by semaj4712 »

I figured out the issue,

+#10#13+

should be

+#13#10+

tobias
Posts: 1603
Joined: Tue Mar 31, 2020 7:37 pm

Re: Running a Pascal Script on the start of a profile

Post by tobias »

True! Should have spotted that myself ...

Post Reply