router

package
v0.0.0-...-5607d3c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2017 License: MIT Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const UploadFormCategory = "c"
View Source
const UploadFormDescription = "desc"
View Source
const UploadFormMagnet = "magnet"
View Source
const UploadFormName = "name"

form names

View Source
const UploadFormRemake = "remake"
View Source
const UploadFormStatus = "status"
View Source
const UploadFormTorrent = "torrent"

Variables

View Source
var ErrInvalidTorrentCategory = errors.New("torrent category is invalid")

error indicating a torrent's category is invalid

View Source
var ErrInvalidTorrentDescription = errors.New("torrent description is invalid")

error indicating a torrent's description is invalid

View Source
var ErrInvalidTorrentName = errors.New("torrent name is invalid")

error indicating a torrent's name is invalid

View Source
var ErrPrivateTorrent = errors.New("torrent is private")

error indicating a torrent is private

View Source
var ErrTorrentPlusMagnet = errors.New("upload either a torrent file or magnet link, not both")

error indicating that you can't send both a magnet link and torrent

View Source
var ErrTrackerProblem = errors.New("torrent does not have any (working) trackers: https://" + config.WebAddress + "/faq#trackers")

error indicating a problem with its trackers

View Source
var FuncMap = template.FuncMap{
	"min": math.Min,
	"genRoute": func(name string, params ...string) string {
		url, err := Router.Get(name).URL(params...)
		if err == nil {
			return url.String()
		}
		return "error"
	},
	"genRouteWithQuery": func(name string, currentUrl *url.URL, params ...string) template.URL {
		url, err := Router.Get(name).URL(params...)
		if err == nil {
			return template.URL(url.String() + "?" + currentUrl.RawQuery)
		}
		return "error"
	},
	"genViewTorrentRoute": func(torrent_id uint) string {

		s := strconv.FormatUint(uint64(torrent_id), 10)
		url, err := Router.Get("view_torrent").URL("id", s)
		if err == nil {
			return url.String()
		}
		return "error"
	},
	"genNav": func(nav Navigation, currentUrl *url.URL, pagesSelectable int) template.HTML {
		var ret = ""
		if nav.TotalItem > 0 {
			maxPages := math.Ceil(float64(nav.TotalItem) / float64(nav.MaxItemPerPage))

			if nav.CurrentPage-1 > 0 {
				url, _ := Router.Get(nav.Route).URL("page", "1")
				ret = ret + "<li><a id=\"page-prev\" href=\"" + url.String() + "?" + currentUrl.RawQuery + "\" aria-label=\"Previous\"><span aria-hidden=\"true\">&laquo;</span></a></li>"
			}
			startValue := 1
			if nav.CurrentPage > pagesSelectable/2 {
				startValue = (int(math.Min((float64(nav.CurrentPage)+math.Floor(float64(pagesSelectable)/2)), maxPages)) - pagesSelectable + 1)
			}
			endValue := (startValue + pagesSelectable - 1)
			if endValue > int(maxPages) {
				endValue = int(maxPages)
			}
			log.Println(nav.TotalItem)
			for i := startValue; i <= endValue; i++ {
				pageNum := strconv.Itoa(i)
				url, _ := Router.Get(nav.Route).URL("page", pageNum)
				ret = ret + "<li"
				if i == nav.CurrentPage {
					ret = ret + " class=\"active\""
				}

				ret = ret + "><a href=\"" + url.String() + "?" + currentUrl.RawQuery + "\">" + strconv.Itoa(i) + "</a></li>"
			}
			if nav.CurrentPage < int(maxPages) {
				url, _ := Router.Get(nav.Route).URL("page", strconv.Itoa(nav.CurrentPage+1))
				ret = ret + "<li><a id=\"page-next\" href=\"" + url.String() + "?" + currentUrl.RawQuery + "\" aria-label=\"Next\"><span aria-hidden=\"true\">&raquo;</span></a></li>"
			}
		}
		return template.HTML(ret)
	},
	"T":  i18n.IdentityTfunc,
	"Ts": i18n.IdentityTfunc,
	"getAvatar": func(hash string, size int) string {
		return "https://www.gravatar.com/avatar/" + hash + "?s=" + strconv.Itoa(size)
	},
	"CurrentOrAdmin":       userPermission.CurrentOrAdmin,
	"CurrentUserIdentical": userPermission.CurrentUserIdentical,
	"HasAdmin":             userPermission.HasAdmin,
	"NeedsCaptcha":         userPermission.NeedsCaptcha,
	"GetRole":              userPermission.GetRole,
	"IsFollower":           userPermission.IsFollower,
	"NoEncode": func(str string) template.HTML {
		return template.HTML(str)
	},
	"calcWidthSeed": func(seed uint32, leech uint32) float64 {
		return float64(float64(seed)/(float64(seed)+float64(leech))) * 100
	},
	"calcWidthLeech": func(seed uint32, leech uint32) float64 {
		return float64(float64(leech)/(float64(seed)+float64(leech))) * 100
	},
}
View Source
var Router *mux.Router
View Source
var TemplateDir = "templates"

Functions

func ApiHandler

func ApiHandler(w http.ResponseWriter, r *http.Request)

func ApiUpdateHandler

func ApiUpdateHandler(w http.ResponseWriter, r *http.Request)

func ApiUploadHandler

func ApiUploadHandler(w http.ResponseWriter, r *http.Request)

func ApiViewHandler

func ApiViewHandler(w http.ResponseWriter, r *http.Request)

func ChangeLanguageHandler

func ChangeLanguageHandler(w http.ResponseWriter, r *http.Request)

func CommentDeleteModPanel

func CommentDeleteModPanel(w http.ResponseWriter, r *http.Request)

func CommentsListPanel

func CommentsListPanel(w http.ResponseWriter, r *http.Request)

func FaqHandler

func FaqHandler(w http.ResponseWriter, r *http.Request)

func GetUser

func GetUser(r *http.Request) *model.User

func HomeHandler

func HomeHandler(w http.ResponseWriter, r *http.Request)

func IndexModPanel

func IndexModPanel(w http.ResponseWriter, r *http.Request)

func NotFoundHandler

func NotFoundHandler(w http.ResponseWriter, r *http.Request)

func PostCommentHandler

func PostCommentHandler(w http.ResponseWriter, r *http.Request)

func RSSHandler

func RSSHandler(w http.ResponseWriter, r *http.Request)

func ReloadTemplates

func ReloadTemplates()

ReloadTemplates reloads templates on runtime

func ReportTorrentHandler

func ReportTorrentHandler(w http.ResponseWriter, r *http.Request)

func SearchHandler

func SearchHandler(w http.ResponseWriter, r *http.Request)

func SeeLanguagesHandler

func SeeLanguagesHandler(w http.ResponseWriter, r *http.Request)

func TorrentDeleteModPanel

func TorrentDeleteModPanel(w http.ResponseWriter, r *http.Request)

func TorrentEditModPanel

func TorrentEditModPanel(w http.ResponseWriter, r *http.Request)

func TorrentPostEditModPanel

func TorrentPostEditModPanel(w http.ResponseWriter, r *http.Request)

func TorrentReportDeleteModPanel

func TorrentReportDeleteModPanel(w http.ResponseWriter, r *http.Request)

func TorrentReportListPanel

func TorrentReportListPanel(w http.ResponseWriter, r *http.Request)

func TorrentsListPanel

func TorrentsListPanel(w http.ResponseWriter, r *http.Request)

func UploadHandler

func UploadHandler(w http.ResponseWriter, r *http.Request)

func UserDetailsHandler

func UserDetailsHandler(w http.ResponseWriter, r *http.Request)

Getting User Profile Details View

func UserFollowHandler

func UserFollowHandler(w http.ResponseWriter, r *http.Request)

func UserLoginFormHandler

func UserLoginFormHandler(w http.ResponseWriter, r *http.Request)

Getting View User Login

func UserLoginPostHandler

func UserLoginPostHandler(w http.ResponseWriter, r *http.Request)

Post Login controller

func UserLogoutHandler

func UserLogoutHandler(w http.ResponseWriter, r *http.Request)

Logout

func UserProfileFormHandler

func UserProfileFormHandler(w http.ResponseWriter, r *http.Request)

Getting View User Profile Update

func UserProfileHandler

func UserProfileHandler(w http.ResponseWriter, r *http.Request)

Getting User Profile

func UserRegisterFormHandler

func UserRegisterFormHandler(w http.ResponseWriter, r *http.Request)

Getting View User Registration

func UserRegisterPostHandler

func UserRegisterPostHandler(w http.ResponseWriter, r *http.Request)

Post Registration controller, we do some check on the form here, the rest on user service

func UserVerifyEmailHandler

func UserVerifyEmailHandler(w http.ResponseWriter, r *http.Request)

func UsersListPanel

func UsersListPanel(w http.ResponseWriter, r *http.Request)

func ViewHandler

func ViewHandler(w http.ResponseWriter, r *http.Request)

func WriteTorrentToDisk

func WriteTorrentToDisk(file multipart.File, name string, fullpath *string) error

Types

type ChangeLanguageVariables

type ChangeLanguageVariables struct {
	Search     SearchForm
	Navigation Navigation
	Language   string
	Languages  map[string]string
	User       *model.User
	URL        *url.URL
	Route      *mux.Route
}

type FaqTemplateVariables

type FaqTemplateVariables struct {
	Navigation Navigation
	Search     SearchForm
	User       *model.User
	URL        *url.URL   // For parsing Url in templates
	Route      *mux.Route // For getting current route in templates
}

type HomeTemplateVariables

type HomeTemplateVariables struct {
	ListTorrents []model.TorrentJSON
	Search       SearchForm
	Navigation   Navigation
	User         *model.User
	URL          *url.URL   // For parsing Url in templates
	Route        *mux.Route // For getting current route in templates
}

type LanguagesJSONResponse

type LanguagesJSONResponse struct {
	Current   string            `json:"current"`
	Languages map[string]string `json:"languages"`
}
type Navigation struct {
	TotalItem      int
	MaxItemPerPage int
	CurrentPage    int
	Route          string
}

* Variables used by the upper ones

type NotFoundTemplateVariables

type NotFoundTemplateVariables struct {
	Navigation Navigation
	Search     SearchForm
	User       *model.User
	URL        *url.URL   // For parsing Url in templates
	Route      *mux.Route // For getting current route in templates
}

type PanelCommentListVbs

type PanelCommentListVbs struct {
	Comments   []model.Comment
	Search     SearchForm
	Navigation Navigation
	User       *model.User
	URL        *url.URL // For parsing Url in templates
}

type PanelIndexVbs

type PanelIndexVbs struct {
	Torrents       []model.Torrent
	TorrentReports []model.TorrentReportJson
	Users          []model.User
	Comments       []model.Comment
	Search         SearchForm
	User           *model.User
	URL            *url.URL // For parsing Url in templates
}

type PanelTorrentEdVbs

type PanelTorrentEdVbs struct {
	Upload     UploadForm
	Search     SearchForm
	User       *model.User
	FormErrors map[string][]string
	FormInfos  map[string][]string
	URL        *url.URL // For parsing Url in templates
}

type PanelTorrentListVbs

type PanelTorrentListVbs struct {
	Torrents   []model.Torrent
	Search     SearchForm
	Navigation Navigation
	User       *model.User
	URL        *url.URL // For parsing Url in templates
}

type PanelTorrentReportListVbs

type PanelTorrentReportListVbs struct {
	TorrentReports []model.TorrentReportJson
	Search         SearchForm
	Navigation     Navigation
	User           *model.User
	URL            *url.URL // For parsing Url in templates
}

type PanelUserListVbs

type PanelUserListVbs struct {
	Users      []model.User
	Search     SearchForm
	Navigation Navigation
	User       *model.User
	URL        *url.URL // For parsing Url in templates
}

type SearchForm

type SearchForm struct {
	common.SearchParam
	Category           string
	HideAdvancedSearch bool
}

func NewSearchForm

func NewSearchForm() SearchForm

Some Default Values to ease things out

type UploadForm

type UploadForm struct {
	Name        string
	Magnet      string
	Category    string
	Remake      bool
	Description string
	Status      int
	CaptchaID   string

	Infohash      string
	CategoryID    int
	SubCategoryID int
	Filesize      int64
	Filepath      string
}

UploadForm serializing HTTP form for torrent upload

func NewUploadForm

func NewUploadForm(params ...string) (uploadForm UploadForm)

NewUploadForm creates a new upload form given parameters as list

func (*UploadForm) ExtractEditInfo

func (f *UploadForm) ExtractEditInfo(r *http.Request) error

func (*UploadForm) ExtractInfo

func (f *UploadForm) ExtractInfo(r *http.Request) error

* UploadForm.ExtractInfo takes an http request and computes all fields for this form

type UploadTemplateVariables

type UploadTemplateVariables struct {
	Upload     UploadForm
	Search     SearchForm
	Navigation Navigation
	User       *model.User
	URL        *url.URL
	Route      *mux.Route
}

type UserLoginFormVariables

type UserLoginFormVariables struct {
	LoginForm  userForms.LoginForm
	FormErrors map[string][]string
	Search     SearchForm
	Navigation Navigation
	User       *model.User
	URL        *url.URL   // For parsing Url in templates
	Route      *mux.Route // For getting current route in templates
}

type UserProfileEditVariables

type UserProfileEditVariables struct {
	UserProfile *model.User
	UserForm    userForms.UserForm
	FormErrors  map[string][]string
	FormInfos   map[string][]string
	Languages   map[string]string
	Search      SearchForm
	Navigation  Navigation
	User        *model.User
	URL         *url.URL   // For parsing Url in templates
	Route       *mux.Route // For getting current route in templates
}

type UserProfileVariables

type UserProfileVariables struct {
	UserProfile *model.User
	FormInfos   map[string][]string
	Search      SearchForm
	Navigation  Navigation
	User        *model.User
	URL         *url.URL   // For parsing Url in templates
	Route       *mux.Route // For getting current route in templates
}

type UserRegisterTemplateVariables

type UserRegisterTemplateVariables struct {
	RegistrationForm userForms.RegistrationForm
	FormErrors       map[string][]string
	Search           SearchForm
	Navigation       Navigation
	User             *model.User
	URL              *url.URL   // For parsing Url in templates
	Route            *mux.Route // For getting current route in templates
}

type UserVerifyTemplateVariables

type UserVerifyTemplateVariables struct {
	FormErrors map[string][]string
	Search     SearchForm
	Navigation Navigation
	User       *model.User
	URL        *url.URL   // For parsing Url in templates
	Route      *mux.Route // For getting current route in templates
}

type ViewTemplateVariables

type ViewTemplateVariables struct {
	Torrent    model.TorrentJSON
	CaptchaID  string
	Search     SearchForm
	Navigation Navigation
	User       *model.User
	URL        *url.URL   // For parsing Url in templates
	Route      *mux.Route // For getting current route in templates
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL