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