예제 #1
0
파일: viewer.go 프로젝트: jjjjj-kun/mangle
func handleViewerView(w http.ResponseWriter, r *http.Request) {
	page_index_str := r.FormValue("page")
	session_id := r.FormValue("id")

	page_index32, err := strconv.ParseInt(page_index_str, 10, 32)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}
	page_index := int(page_index32)

	session_info, session_exists, err := sessions.GetSessionInfo(session_id)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	if !session_exists {
		http.NotFound(w, r)
		return
	}

	files, err := ioutil.ReadDir(session_info.StagingPath)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	var page_list []string

	for _, f := range files {
		// fmt.Printf(":%s\n", f.Name())
		if !f.IsDir() {
			page_list = append(page_list, f.Name())
		}
	}

	if page_index >= len(page_list) || page_index < 0 {
		http.NotFound(w, r)
		return
	}

	sort.Strings(page_list)
	target_page_name := page_list[page_index]

	session_info.LastAccessedTime = time.Now()
	session_info.LastRemoteAddr = r.RemoteAddr
	session_info.LastPageIndex = page_index

	err = sessions.UpdateSessionInfo(session_info)

	page_path := filepath.Join(session_info.StagingPath, target_page_name)
	fmt.Printf("serving up page: %s\n", page_path)
	http.ServeFile(w, r, page_path)
}
예제 #2
0
파일: viewer.go 프로젝트: jjjjj-kun/mangle
func handleViewerThumbnail(w http.ResponseWriter, r *http.Request) {
	session_id := r.FormValue("id")
	page_index_str := r.FormValue("page")

	page_index32, err := strconv.ParseInt(page_index_str, 10, 32)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}
	page_index := int(page_index32)

	session_info, session_exists, err := sessions.GetSessionInfo(session_id)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	if !session_exists {
		http.NotFound(w, r)
		return
	}

	files, err := ioutil.ReadDir(session_info.StagingPath)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	var page_list []string

	for _, f := range files {
		if !f.IsDir() {
			page_list = append(page_list, f.Name())
		}
	}

	// page_index := session_info.LastPageIndex

	if page_index >= len(page_list) || page_index < 0 {
		http.NotFound(w, r)
		return
	}

	sort.Strings(page_list)
	target_page_name := page_list[page_index]

	page_path := filepath.Join(session_info.StagingPath, target_page_name)
	fmt.Printf("serving up thumb: %s\n", page_path)
	// w.Header().Add("Cache-control", "no-cache")
	// w.Header().Add("Cache-directive", "no-cache")
	// w.Header().Add("Pragma", "no-cache")
	// w.Header().Add("Pragma-directive", "no-cache")
	// w.Header().Add("Expires", "0")
	http.ServeFile(w, r, page_path)
}