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