package monitor

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
	"server/global"
)

type PlayBackService struct{}

// getRewindApi 公用请求接口
func (f *PlayBackService) getRewindApi(url string) (string, error) {
	method := "GET"

	client := &http.Client{}
	req, err := http.NewRequest(method, url, nil)
	if err != nil {
		return "", nil
	}
	res, err := client.Do(req)
	if err != nil {
		return "", nil
	}
	defer res.Body.Close()

	body, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return "", nil
	}

	return string(body), err
}

// GetRewindText 请求回话加密数据
func (f *PlayBackService) GetRewindText(streamId string, date string) (string, error) {
	api := global.GVA_CONFIG.Webrtc.RewindUrl + "/list/%v/%v"
	url2 := fmt.Sprintf(api, (streamId), url.QueryEscape(date))
	return f.getRewindApi(url2)
}
