MCPcopy Create free account
hub / github.com/dinofizz/diskplayer / recordHandler

Function recordHandler

server.go:88–119  ·  view source on GitHub ↗

recordHandler handles requests to the server which contain a Spotify web URL to be recorded. Two values are extracted from the request: web_url and device_path: web_url is the complete Spotify web URL pointing to an album or playlist. device_path is the complete path to the disk device, i.e. /dev/sd

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

86// in the diskplayer.yaml configuration file.
87// If the recording is successful, redirection to a success page occurs, otherwise an error page is returned.
88func recordHandler(w http.ResponseWriter, r *http.Request) {
89 webUrl := r.FormValue("web_url")
90 devPath := r.FormValue("device_path")
91
92 folder := ConfigValue(RECORD_FOLDER_PATH)
93 filename := ConfigValue(RECORD_FILENAME)
94 dstPath := folder + "/" + filename
95
96 m, err := mount.Mounted(folder);
97 if err != nil {
98 errorPage(w, err)
99 }
100
101 if m == false {
102 err := mount.Mount(devPath, folder, "vfat", "");
103 if err != nil {
104 errorPage(w, err)
105 }
106 }
107
108 err = Record(webUrl, dstPath)
109 if err != nil {
110 errorPage(w, err)
111 }
112
113 err = mount.Unmount(folder);
114 if err != nil {
115 errorPage(w, err)
116 }
117
118 http.Redirect(w, r, "/static/success.html", http.StatusFound)
119}
120
121// indexHandler handles requests to the server for the root location "/".
122// A listing of the attached devices is obtained and applied to the index.html template response.

Callers

nothing calls this directly

Calls 3

ConfigValueFunction · 0.85
errorPageFunction · 0.85
RecordFunction · 0.85

Tested by

no test coverage detected