1 ;;; 013-org-export-service.el --- upload and export Org-mode files
4 (with-slots (process headers) request
5 (let ((file (cdr (assoc "file" headers)))
6 (type (cdr (assoc 'content (cdr (assoc "type" headers))))))
7 (if (not (and file type))
9 (ws-response-header process 200 '("Content-type" . "text/html"))
10 (process-send-string process "
11 <html><body><form action=\"\" method=\"post\" enctype=\"multipart/form-data\">
12 Export file: <input type=\"file\" name=\"file\"> to type
13 <select name=\"type\">
14 <option value=\"txt\">Text</option>
15 <option value=\"html\">HTML</option>
16 <option value=\"tex\">TeX</option>
18 <input type=\"submit\" value=\"submit\">.
19 </form></body></html>"))
20 (let* ((orig (cdr (assoc 'filename file)))
21 (base (file-name-nondirectory
22 (file-name-sans-extension orig)))
23 (backend (case (intern (downcase type))
27 (t (ws-error process "%S export not supported"
29 (path (concat base "." type)))
30 (let ((default-directory temporary-file-directory))
31 (when (or (file-exists-p orig) (file-exists-p path))
33 "File already exists on the server, try a new file."))
34 (with-temp-file orig (insert (cdr (assoc 'content file))))
35 (save-window-excursion (find-file orig)
36 ;; TODO: Steal personal data and
37 ;; ideas from uploaded Org-mode
38 ;; text. Web services aren't free!
39 (org-export-to-file backend path)
41 (ws-send-file process path)
43 (delete-file orig)))))))