2 * Written by Richard W.M. Jones <rich@merjis.com>.
3 * Copyright (C) 2004 Merjis Ltd.
4 * $Id: image.ml,v 1.1 2004/09/07 10:14:09 rich Exp $
16 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _) _ =
17 let image = q#param "image" in
18 let is_thumbnail = q#param_true "thumbnail" in
20 try Some (int_of_string (q#param "version")) with Not_found -> None in
22 (* Get the image and its MIME type. *)
24 if not is_thumbnail then "image, mime_type"
25 else "thumbnail, tn_mime_type" in
28 None -> "hostid = ? and name = ?", [`Int hostid; `String image]
30 "hostid = ? and (name = ? or name_deleted = ?) and id = ?",
31 [`Int hostid; `String image; `String image; `Int version] in
33 let sth = dbh#prepare_cached
34 ("select " ^ what ^ " from images where " ^ where) in
38 match sth#fetch1 () with
39 [ `Binary data; `String mime_type ] ->
41 | _ -> assert false in
43 if version <> None then
44 (* Set a medium-length expiry time on this resource. *)
45 Table.set (Request.headers_out r) "Expires" (Cgi_expires.expires_medium());
47 q#header ~content_type:mime_type ();