示例#1
0
func (this *GoChromeCastHttpServer) DownloadPlay(c web.C, w http.ResponseWriter, r *http.Request) {
	if params, err := utils.GetParams(r, "id", "file_path"); err != nil {
		w.Header().Set("Content-Type", "application/json")
		r := responses.JsonResponse{}
		r.Method = "DownloadPlay"
		r.Set(nil, err)
		io.WriteString(w, utils.RenderResponse(r))
	} else {
		if sc, display_path, err := this.ds.DownloadPlay(params["id"], params["file_path"]); err != nil {
			w.Header().Set("Content-Type", "application/json")
			r := responses.JsonResponse{}
			r.Method = "DownloadPlay"
			r.Set(nil, err)
			io.WriteString(w, utils.RenderResponse(r))
		} else {
			defer func() {
				if err == nil {
					sc.Close()
				}
			}()
			w.Header().Set("Content-Disposition", "attachment; filename=\""+params["file_path"]+"\"")
			http.ServeContent(w, r, display_path, time.Now(), sc)
		}
	}
}
示例#2
0
func (this *GoChromeCastHttpServer) DownloadInfo(c *web.C, r *http.Request) (interface{}, error) {
	if params, err := utils.GetParams(r, "id"); err != nil {
		return struct{}{}, err
	} else {
		return this.ds.DownloadInfo(params["id"])
	}
}
示例#3
0
func (this *GoChromeCastHttpServer) DownloadStop(c *web.C, r *http.Request) (interface{}, error) {
	var response responses.DownloaderStopResponse

	if params, err := utils.GetParams(r, "id"); err != nil {
		return response, err
	} else {
		err := this.ds.DownloadStop(params["id"])
		if err != nil {
			return response, err
		}

		return response, nil
	}
}
示例#4
0
func (this *GoChromeCastHttpServer) DownloadAdd(c *web.C, r *http.Request) (interface{}, error) {
	var response responses.DownloaderAddResponse

	if params, err := utils.GetParams(r, "uri"); err != nil {
		return response, err

	} else {
		id, err := this.ds.DownloadAdd(params["uri"])
		response.DownloadId = id

		if err != nil {
			return response, err
		}
		return response, nil
	}
}