예제 #1
0
// 上传文件
func UeditorUploadHandler(rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
	log.Println(sw.GetParameter(r, "action"), p.ByName("module"))
	op := sw.GetParameter(r, "action")
	switch op {
	case "uploadimage":
		uploadFile(rw, r, p)
	case "uploadscrawl":
		uploadScrawl(rw, r, p)
	case "uploadvideo":
		uploadFile(rw, r, p)
	case "uploadfile":
		uploadFile(rw, r, p)
	}
}
예제 #2
0
func GenJsonpResult(r *http.Request, rt *Ret) []byte {
	bs, err := json.Marshal(rt)
	if err != nil {
		panic(err)
	}
	return []byte(sw.GetParameter(r, "callback") + "(" + string(bs) + ")")
}
예제 #3
0
func DlmHandler(rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
	//	db := ConnectDB("./middle.db")
	db := ConnectMySql()

	defer func() {
		db.Close()
		err := recover()
		if err != nil {
			rw.Write(GenJsonpResult(r, &Ret{false, err.(string), nil}))
			log.Println(err)
		}
	}()

	if r.URL.Query().Get("hot_id") != "" {
		LogClient(r.RemoteAddr, GetParameter(r, "hot_id"), db)
	}

	switcher := sw.Dispatch(db)
	var ret []byte
	if Authorize(r) {
		msg, data := switcher[sw.GetParameter(r, "cmd")](r)
		log.Println("rth4")
		ret = GenJsonpResult(r, &Ret{true, msg, data})
	} else {
		panic("Not authorized!")
	}
	rw.Write(ret)
}
예제 #4
0
func UploadVideosHandler(rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
	r.ParseMultipartForm(32 << 20)
	file, handle, err := r.FormFile("upload")
	if err != nil {
		log.Println(err)
		panic("上传失败")
	}
	defer file.Close()

	// filename
	filename := handle.Filename
	log.Println(filename)
	// ext := SubString(filename, strings.LastIndex(filename, "."), 4)
	filename = GetGuid() + path.Ext(filename)

	// save file
	data, err := ioutil.ReadAll(file)
	if err != nil {
		panic("读取文件数据失败")
	}
	err = ioutil.WriteFile(sw.VIDEO_IMG_ROOT+"/"+filename, data, 0777)
	if err != nil {
		log.Println(err)
		panic("保存文件失败")
	}
	callback := sw.GetParameter(r, "CKEditorFuncNum")
	log.Println("callback: " + callback) // ----- TEST
	fmt.Fprintf(rw, "<script type=\"text/javascript\">window.parent.CKEDITOR.tools.callFunction("+callback+",'"+sw.VIDEOS_IMG_URL+filename+"','')</script>")
}
예제 #5
0
// 初始化读取配置文件
func UeditorHandler(rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
	log.Println(sw.GetParameter(r, "action"), p.ByName("module"))
	file, err := os.Open("./ueditor/config.json")
	if err != nil {
		log.Fatal(err)
		panic(err)
	}
	defer file.Close()
	buf := bytes.NewBuffer(nil)
	buf.ReadFrom(file)
	rw.Write(buf.Bytes())
}
예제 #6
0
func Authorize(r *http.Request) bool {
	token := sw.GetParameter(r, "token")
	// log.Println(token)
	return token == "Jh2044695"
}