I need to build a plug-in. Actually I've built half of the plug-in already but I am questioning my approach. I wanted to get another point of view to see if I'm headed down the wrong path.
In my Craft control panel I want to be able to add a ZIP file to an entry or just into Assets directly. In an entry I can currently do this through an Assets field type. But I need to extend the functionality because I need to do some file validation on the zip file and then unzip it and then validate the contents of the unzipped content as well. Finally I then need to have the ability to reference the folder that contains the unzipped files.
In more concrete words, I want to be able to upload a zip file that contains an animated advertising banner. As an example, the zip file would be named "acme_banner_300x250.zip". Uploading that file would check that the banner dimensions are stated in the filename (300x250) and that the contents of the ZIP include an "index.html" plus it must contain an image file with the word "backupImage" in the file name. If all those things are true, it would unzip the file and then delete the original ZIP.
Finally, when this asset is included in an entry, I want to be able to pick it from the asset list (where it shows the backupImage file from the zip as the thumbnail) and have it be able to report the proper height and width properties along with a 'url' property that points to the folder containing the index.html file.
(Side note: These are all files I've built myself so I am not worried about malicious content being included in the upload, although if there is a way to scan them for malicious content, that would be good with me.)
My current half-finished plug-in does the following: It will intercept an uploaded asset using the "assets.onBeforeUploadAsset" event listener and then unzip the file (if the extension is "zip") in a location I can designate. I'm left with the original zip file in the Assets listing and I'm struggling with how to use the unzipped directory in my entry because that unzipped location isn't associated with the zip file listed in my assets.
I'd like to select whether this whole process happens or not. Right now, any ZIP file gets unzipped and I would prefer to be able to upload a ZIP file and have it remain a plain old ZIP file sometimes (i.e. when a client needs to get a ZIP of files from me).
Am I going down the wrong path trying to work within Assets to build this functionality? It feels like I'm creating a new type of Assets rather than just working within the existing Assets available file types.