}
okResponse(response, data)
}
- case "download":
- valid, fullPath := paths.IsValid(request.FormValue("path"))
- if valid {
- info, _ := os.Lstat(fullPath) // Error is already checked by |valid|.
- if info.IsDirectory() {
- errorResponse(response, "File is a directory")
- return
- }
- http.ServeFile(response, request, fullPath)
- } else {
- errorResponse(response, "Invalid path")
- }
default:
fmt.Printf("Invalid action: '%s'\n", request.FormValue("action"))
errorResponse(response, "Unhandled action")
return err
}
+func downloadHandler(response http.ResponseWriter, request *http.Request) {
+ valid, fullPath := paths.IsValid(request.FormValue("path"))
+ if valid {
+ info, _ := os.Lstat(fullPath) // Error is already checked by |valid|.
+ if info.IsDirectory() {
+ http.Error(response, "Path is a directory", http.StatusBadRequest)
+ } else {
+ http.ServeFile(response, request, fullPath)
+ }
+ } else {
+ http.NotFound(response, request)
+ }
+}
+
func errorResponse(response http.ResponseWriter, message string) {
message = strings.Replace(message, gConfig.JailRoot, "/", -1)
data := map[string]interface{}{
mux.HandleFunc("/", indexHandler)
mux.Handle("/fe/", http.FileServer(kFrontEndFiles, "/fe/"))
mux.HandleFunc("/service", serviceHandler)
+ mux.HandleFunc("/download", downloadHandler)
mux.HandleFunc("/proxy", proxyHandler)
gConfig = config
OPEN : 'open',
MOVE : 'move',
DELETE : 'delete',
- TV_RENAME : 'tv-rename'
+ TV_RENAME : 'tv-rename',
+ DOWNLOAD : 'download'
};
/**
'open' : 'Open',
'move' : 'Move',
'delete' : 'Delete',
- 'tv-rename' : 'Rename TV Episode'
+ 'tv-rename' : 'Rename TV Episode',
+ 'download' : 'Download'
};
/**
this.performDelete_();
} else if (option == armadillo.Actor.options_.TV_RENAME) {
this.performTVRename_();
+ } else if (option == armadillo.Actor.options_.DOWNLOAD) {
+ this.performDownload_();
}
};
renamer.run();
};
+/**
+ * Subroutine that streams a file.
+ * @private
+ */
+armadillo.Actor.prototype.performDownload_ = function() {
+ window.location = '/download?path=' + this.file_.getFullPath();
+};
+
/**
* Creates two buttons: one for OK one for Cancel and attahes them to the
* |controlContainer_|.