package redirect

import (
	"errors"
	"fmt"
	"fonchain-fiee/pkg/service"
	"github.com/gin-gonic/gin"
	"net/http"
	"time"
)

// ToRedirectRealUrl 重定向到指定位置
func ToRedirectRealUrl(c *gin.Context) {

	realUrl := c.Query("base_redirect_url")
	if realUrl == "" {
		service.Error(c, errors.New("not real url"))
		return
	}

	c.Redirect(http.StatusMovedPermanently, realUrl)
}

// ToRedirectRealUrlAdnRand 重定向到指定位置
func ToRedirectRealUrlAdnRand(c *gin.Context) {

	realUrl := c.Query("base_redirect_url")
	if realUrl == "" {
		service.Error(c, errors.New("not real url"))
		return
	}

	c.Redirect(http.StatusMovedPermanently, realUrl+fmt.Sprintf("?time=%d", time.Now().Unix()))
}
