Preview Handler

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:

contenttypestringThe content type extracted from the response headers
previewhtmlstringAllows you to set the HTML/CSS that will be loaded as the preview. JavaScript and TIScript are not allowed.
requestheadersstringAll the request headers
responsefilenamestringFilename of a temporary file containing the decompressed response stream
responseheadersstringAll the response headers
responsetextstringThe response as a text
urlstringThe request URL
warnemptybooleanIf set true, notifies Sandcat that the response is empty or incomplete
Page last modified on May 19, 2013, at 07:54 AM
2013 Syhunt