rejetto forum

Events scripts of in more ( ACCEPTED BY THE BOSS)

Mars · 12 · 7977

0 Members and 1 Guest are viewing this topic.

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
actually in hfs.events, it is possible to do
Quote
[download name]
%user%.%item-name%
The downloaded file can be renamed before sending to the user

*************************************************

With what follows it is also possible to influence the name of files sent by the user at the time of the reception to the server and before recording

Quote
procedure Tmainfrm.httpEvent(event:ThttpEvent; conn:ThttpConn);
.....
  function runEventScript(event: string; table: array of string):string;overload;     //mod by mars
  var
    s: string;
    md: TmacroData;
  begin
  result:='';
  s:=trim(xtpl(eventScripts[event],table));      //mod by mars
  if s = '' then exit;
  fillchar(md, sizeof(md), 0);
  md.cd:=data;
  try
    if assigned(data.f) then // a file has been uploaded
      begin
      // this exposes file properties to the script. it must be encapsulated in a Tfile. we don't need to cache the object because we need it only once.
      md.f:=Tfile.create(getFilename(data.f^));
      include(md.f.flags, FA_TEMP)
      end
    else if assigned(f) then
      md.f:=f
    else
      md.f:=data.lastFile;
    tryApplyMacrosAndSymbols(s, md);
    result:=s;
  except md.f.free end;
  end; // runEventScript

  function runEventScript(event:string):string;overload;      //add by mars   download name compatibility
  begin
  result:=runEventScript(event,[]);
  end; // runEventScript

.......
  function getUploadDestinationFileName():string;
  var
    i: integer;
    fn, ext: string;
  begin
  fn:=or_(trim( runEventScript( 'upload name', ['%item-name%', data.uploadSrc]) ), data.uploadSrc);      //mod by by mars
  fn:=xtpl(fn,['"','_', '?','_', '*','_', '|','_', '<','_', '>','_', '\','_', '/','-', ':','''']); //add by by mars  convert invalid characters
  result:=f.resource+'\'+fn;
  if not numberFilesOnUploadChk.checked then exit;
  ext:=extractFileExt(fn);
  setLength(fn, length(fn)-length(ext));
  i:=0;
  while fileExists(result) do
    begin
    inc(i);
    result:=format('%s\%s (%d)%s', [f.resource, fn, i, ext]);
    end;
  end; // getUploadDestinationFileName


Quote
[upload name]
%user%.%item-name%
The uploaded file can be renamed before regeistered in the server.
it is not possible to delete or move the file in this section with a macro, you can only change the actual upload name.
« Last Edit: April 11, 2009, 03:59:25 PM by mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
it's a good suggestion mars.
i just opted for a slightly different implementation:
the uploading file (data.f) was already accessible by event macros, so i just made assignFile() before runEventScript().


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
if you notice , i replace some invalid characters,  all by a _ , except  / by a - and, : by a '

it is necessary to do as this because when you insert a date %item-modified% in the section 'download name' the result should be   13/03/2009 18:00:00 , but it is not what it is proposed to the user (result is very strange)

Quote
[download name]
{.set|name|mars.%item-modified%.%item-name%.}
{.^name.}
{.add to log|{.^name.}.}

the add to log give a good result but IE can't convert prohibited characters, firefox replace all of them by a _ .

My choice is accordind to firefox and result of a date become mars.13-03-2009 18'00'00.file.ext , work very nice and is better butifull than mars.13_03_2009 18_00_00.file.ext
« Last Edit: March 13, 2009, 05:23:35 PM by mars »


Offline AYEHAN

  • Occasional poster
  • *
    • Posts: 92
    • View Profile
muaaahhh mars

bro u did it, i really wanted that
 i did it this way

Code: [Select]
[download name]
SmS_Share_Server.%item-name%
and it works fine :D


Offline Dragon_Hunter

  • Occasional poster
  • *
    • Posts: 52
    • View Profile
Mars can you explane more about that you put out, and what it is for ?


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
when a user select a file to been downloaded, before the file is sent to him, you can personalize the name which will be used inside the user's computer:

if by example you have two files with the same name ( not the same date or not the same size), but each of them in two different folders, after downloaded the first in a local folder (for the user), download the second will replace the first if the user make no change.

But you , you know that they are the same files with different version, it is possible to include in the name some information about this file before the download begin.

it is the job of the section [download name] in hfs.events

Furthermore, i create the same job with uploaded file with section [upload name],
then you can attach the name of the user with %user% to the real upload name

If a file is named 'martin.exe' at a user 'lambda', then the final upload name is  lambda.martin.exe with the section

[upload name]
%user%.%item-name%

but It is not implemented in the last version yet ;)


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile

Quote
  procedure serveTar();
......
    if f.name > '' then
      begin
      data.lastFN:=if_(f.name='/', 'home/', f.name)+'.'+if_(selection, 'selection', 'folder')+'.tar';
      data.lastFN:=or_(trim(runEventScript('archive name',[
            '%item-name%',data.lastFN,
            '%folder%',if_(f.name='/', 'home', f.name),
            '%selection%',if_(selection, 'selection', 'folder')
           ])), data.lastFN); // a script can eventually decide the name
      data.lastFN:=xtpl(data.lastFN,['"','_', '?','_', '*','_', '|','_', '<','_', '>','_', '\','_', '/','-', ':','''']);

      conn.addHeader('Content-Disposition: filename="'+data.lastFN+'";');
      end;
  except tar.free end;
  end; // serveTar

hfs.events 
Quote
[archive name]
%folder%.%selection%.tar

the exact default name used by rejetto is fully registered in the var %item-name%.
%folder% and %selection% give you the choice to select a name. Dont forget '.tar' at the end in this case.

If the section does not exist, the value by default is equivalent to %item-name%

Any bad character is automatically converted in a valid equivalent for a name of file.
     all by a _ , except  / by a - and, : by a '
« Last Edit: March 13, 2009, 08:11:03 PM by mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
if you notice , i replace some invalid characters,  all by a _ , except  / by a - and, : by a '

right mars.
i did the same, but with the following changes:

i allow ":" and "\" so that you can redirect the upload to another drive or folder.

i changed the way to pass symbols to the script: your method doesn't actually pass the symbols, just replaces at the end, and you cannot use macros on them.

i renamed %selection% to %mode% because "%selection% = selection" is not very elegant.

i renamed %item-name% to %archive-name% to avoid confusion: people may think they are using %item-name% so they can relay on other %item-properties% (while they exists and are related to another file).


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
Quote
i changed the way to pass symbols to the script: your method doesn't actually pass the symbols, just replaces at the end, and you cannot use macros on them.

I maybe badly understood, but kept silent let imply that the passed on information can contain macro or other 'dangerous' symbols. You should not forget that this event is intended to influence a name of file, thus with valid characters in return.

 Filename---> invisible  Action(s) - > new valid filename

I base my thoughts on the manners of the names of file current under Windows, because hfs turn under it  ;)


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
i didn't understand your comment mars.
if it is very hard to translate try with french.


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
Quote
Quote
i changed the way to pass symbols to the script:

1)your method doesn't actually pass the symbols,

2) just replaces at the end,

3) and you cannot use macros on them.

runeventscript accept two params : name event   + [one array of symbols]


Quote
function runEventScript(event:string; table:array of string):string; overload;
  var
    sa: TStringDynArray;
....
  sa:=NIL;
  addArray(sa, table);

......
  tryApplyMacrosAndSymbols(result, md, sa);





1)  function runEventScript(event: string; table: array of string):string;overload;     //mod by mars
.....
 begin
  result:='';
2)   s:=trim(xtpl(eventScripts[event],table));      //mod by mars
  if s = '' then exit;
......
3)    tryApplyMacrosAndSymbols(s, md);
    result:=s;
  except md.f.free end;
  end; // runEventScript 



n'est ce pas suffisant pour l'usage que l'on veut en faire?? 



data.lastFN:=or_(trim(runEventScript('archive name',[
            '%item-name%',data.lastFN,
            '%folder%',if_(f.name='/', 'home', f.name),
            '%selection%',if_(selection, 'selection', 'folder')
           ])
), data.lastFN); // a script can eventually decide the name

c'est pourtant une méthode d'appel de fonction des plus classique.
« Last Edit: March 18, 2009, 11:33:15 AM by mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
you are right, i misread your code.
you are replacing at first, it works 99% the same as my method.