vertigis / workflow-activities-zip

Activities for working with zip archives in VertiGIS Studio Workflow
MIT License
0 stars 0 forks source link

Individual file names in the zipped file always show numbers #12

Open jianingliu opened 4 months ago

jianingliu commented 4 months ago

Hi Team,

We found a bug in the code causing index numbers (0, 1, 2... ), rather than the actual names, to be written as the file name inside the zip.

We've reviewed the code here: https://github.com/vertigis/workflow-activities-zip/blob/main/src/activities/Zip.ts At line 35, the 'path' variable is the index number in the files. At line 37, the number is written to the zip as the file name.

The fix should be easy. Should be good if we just change line 37 to the following:

zip.file(content.name, content);

Would like to get this issue fixed sooner than later.

Thanks, Johnny

rcooney commented 4 months ago

What are you providing as the files input to the activity? The activity accepts an object whose keys are the desired paths in the zip file, and whose values are the file content.

Something like this:

={
 "file1.txt": "content1",
 "folder1/file2.txt": "content2"
}

From what you've described it sounds like you are providing an array of File objects.

oparfrey-aamgroup commented 4 months ago

Yes correct the input was an array of File Objects created by the Create File activity. e.g. = [$file1.result, $file2.result, $file3.result]

I've tried adding the files to this activity using the following syntax, but it's not accepted. ={ $file1.result.name: $file1.result, $file2.result.name: $file2.result, $file3.result.name: $file3.result }

The following does work however and produces the desired output. ={ "file1": $file1.result, "file2": $file2.result, "file3": $file3.result }

Is there a reason the syntax $file1.result.name is not valid for the path?

rcooney commented 4 months ago

You can't use something like $file1.result.name in the left-hand side of a JavaScript expression. You'd need to wrap it in [] like [$file1.result.name] to make it legal JS. However, Workflow doesn't accept that syntax.

You'll need to assemble the object a little more manually. You could use a Create Value and For Each with an Add Item to do this.

Or, you could use an expression like this to do it all in a single input:

=((files) => {
    var obj = {};
    for (let file of files) {
        obj[file.name] = file;
    }
    return obj;
})([$file1.result, $file2.result, $file3.result])