Sandcat 4.0 comes with response preview handlers for the most common web file formats. This includes CSS, Flash, HTML, common image formats (bmp, gif, ico, jpg, png and svg), JavaScript, JSON, text and XML files. This page explains how you can add support for additional response formats.
How to create a preview handler extension
In order to add a new preview handler, you must use the Sandcat:RegisterPreviewHandler() method. This method needs three parameters:
- uniqueid - A string to serve as the unique ID for your preview handler extension
- function - A Lua function to be called by Sandcat before displaying the preview. The function must have a single parameter for receiving the preview handling variable (which will be a Lua table containing details about the request being previewed).
- extensions - The file extension of the format you want to handle. Can be multiple extensions separated by commas.
- mimetypes (optional) - Mime type of the format you want to handle. Can be multiple mime types separated by comma.
{
"name": "My Preview Handler Extension",
"version": "1.0",
"author": "Syhunt Team",
"script": {
"filename": "mypreview.lua",
"init": "MyPreview:register()",
}
}
mypreview.lua:
MyPreview = {}
function MyPreview:register() -- will be called during startup
Sandcat:RegisterPreviewHandler('mypreviewforfoo',self.HandleFoo,'foo','text/foo')
end
function MyPreview:HandleFoo(data)
local source = data.responsetext
-- do something with source here --
data.previewhtml = '<b>Your preview html code</b>'
end
data will contain the following keys with details about the request being previewed:
contenttype | string | The content type extracted from the response headers |
previewhtml | string | Allows you to set the HTML/CSS that will be loaded as the preview. JavaScript and TIScript are not allowed. |
requestheaders | string | All the request headers |
responsefilename | string | Filename of a temporary file containing the decompressed response stream |
responseheaders | string | All the response headers |
responsetext | string | The response as a text |
url | string | The request URL |
warnempty | boolean | If set true, notifies Sandcat that the response is empty or incomplete |