-
-
Save rafagil/8bf03c4de4ef19dae728b61542f26861 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns clojure-sync.core | |
(:require [immutant.web :as web] | |
[compojure.core :refer :all] | |
[compojure.route :as route] | |
[ring.middleware.defaults :refer :all] | |
[ring.middleware [multipart-params :as mp]] | |
[clojure.string :as str] | |
[clojure.java.io :as io] | |
[clojure.data.json :as json]) | |
(:gen-class)) | |
(def BACKUP_FOLDER "/home/rafa/samba/public/iOSBackup/") | |
(defn send-json [contents] | |
{:status 200 | |
:headers {"Content-Type" "application/json"} | |
:body (str (json/write-str contents))}) | |
(defn ext [filename] | |
(second (str/split filename #"\."))) | |
(defn upload-file [file date] | |
(->> (str BACKUP_FOLDER date "." (ext (file :filename))) | |
io/file | |
(io/copy (file :tempfile))) | |
(send-json "OK")) | |
(defn list-files [req] | |
(->> BACKUP_FOLDER | |
io/file | |
file-seq | |
(filter #(.isFile %)) | |
(mapv #(.getName %)) | |
(mapv #(first (str/split % #"\."))) | |
(reduce #(assoc %1 %2 1) {}) | |
send-json)) | |
(defroutes app-routes | |
(GET "/processed" [] list-files) | |
(mp/wrap-multipart-params | |
(POST "/upload" {params :params} (upload-file (get params "photo") (get params "date")))) | |
(route/not-found "Not Found")) | |
(defn -main [] | |
(web/run (wrap-defaults app-routes api-defaults) :host "192.168.1.112" :port 3003)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment