195 lines
12 KiB
HTML
195 lines
12 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<link rel="stylesheet" href="../../coverage.css"/> <title> mw_ui/routes/load.clj </title>
|
|
</head>
|
|
<body>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
001 (ns ^{:doc "Route which handles the upload of worlds/rules from the client."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
002 :author "Simon Brooke"}
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
003 mw-ui.routes.load
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
004 (:require [clojure.walk :refer [keywordize-keys]]
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
005 [noir.io :as io]
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
006 [noir.session :as session]
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
007 [mw-ui.layout :as layout]))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
008
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
009 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
010 ;;;;
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
011 ;;;; mw-ui: a servlet user/visualisation interface for MicroWorld.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
012 ;;;;
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
013 ;;;; This program is free software; you can redistribute it and/or
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
014 ;;;; modify it under the terms of the GNU General Public License
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
015 ;;;; as published by the Free Software Foundation; either version 2
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
016 ;;;; of the License, or (at your option) any later version.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
017 ;;;;
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
018 ;;;; This program is distributed in the hope that it will be useful,
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
019 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
020 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
021 ;;;; GNU General Public License for more details.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
022 ;;;;
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
023 ;;;; You should have received a copy of the GNU General Public License
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
024 ;;;; along with this program; if not, write to the Free Software
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
025 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
026 ;;;; USA.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
027 ;;;;
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
028 ;;;; Copyright (C) 2014 Simon Brooke
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
029 ;;;;
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
030 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
031
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
032
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
033 (defn- upload [file]
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 4 forms covered">
|
|
034 (io/upload-file "/tmp/" file)
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 2 forms covered">
|
|
035 (cond
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 3 forms covered">
|
|
036 (session/put! :world
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 10 forms covered">
|
|
037 (with-open [_ (java.io.FileReader. (:tempfile file))] (read)))
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 6 forms covered">
|
|
038 (str "Successfully loaded your world from " (:filename file))))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
039
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
040
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
041 (defn load-page
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
042 "If no args, show the load form; with args, load a world file from the client.
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
043
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
044 *NOTE* that this reads a Clojure form from an untrusted client and should almost
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
045 certainly NOT be enabled on a public-facing site, especially not on the Internet.
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
046
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
047 *TODO* doesn't work yet."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
048 ([]
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 3 forms covered">
|
|
049 (load-page nil))
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
050 ([request]
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 4 forms covered">
|
|
051 (let [file (:file request)]
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 1 forms covered">
|
|
052 (try
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 3 forms covered">
|
|
053 (layout/render "load.html"
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 4 forms covered">
|
|
054 {:title "Load World"
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 3 forms covered">
|
|
055 :message (upload file)})
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
056
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
057 (catch Exception any
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 3 forms covered">
|
|
058 (layout/render "load.html"
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 6 forms covered">
|
|
059 {:title "Load World"
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
060 :message "Failed to load your world"
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 6 forms covered">
|
|
061 :error (str (.getName (.getClass any)) ": " (.getMessage any))}))))))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
062
|
|
</span><br/>
|
|
</body>
|
|
</html>
|