mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2024-11-27 01:13:00 +00:00
Refactor everything
This commit is contained in:
parent
57d2a4288b
commit
2af37d4778
6
main.go
6
main.go
@ -12,7 +12,7 @@ import (
|
|||||||
"bloat/config"
|
"bloat/config"
|
||||||
"bloat/kv"
|
"bloat/kv"
|
||||||
"bloat/renderer"
|
"bloat/renderer"
|
||||||
"bloat/repository"
|
"bloat/repo"
|
||||||
"bloat/service"
|
"bloat/service"
|
||||||
"bloat/util"
|
"bloat/util"
|
||||||
)
|
)
|
||||||
@ -67,8 +67,8 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionRepo := repository.NewSessionRepository(sessionDB)
|
sessionRepo := repo.NewSessionRepo(sessionDB)
|
||||||
appRepo := repository.NewAppRepository(appDB)
|
appRepo := repo.NewAppRepo(appDB)
|
||||||
|
|
||||||
customCSS := config.CustomCSS
|
customCSS := config.CustomCSS
|
||||||
if !strings.HasPrefix(customCSS, "http://") &&
|
if !strings.HasPrefix(customCSS, "http://") &&
|
||||||
|
@ -59,12 +59,12 @@ func main() {
|
|||||||
|
|
||||||
sessionRepo := repository.NewSessionRepository(sessionDB)
|
sessionRepo := repository.NewSessionRepository(sessionDB)
|
||||||
|
|
||||||
sessionIds, err := getKeys(sessionRepoPath)
|
sessionIDs, err := getKeys(sessionRepoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, id := range sessionIds {
|
for _, id := range sessionIDs {
|
||||||
s, err := sessionRepo.Get(id)
|
s, err := sessionRepo.Get(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(id, err)
|
log.Println(id, err)
|
||||||
|
@ -15,7 +15,7 @@ type App struct {
|
|||||||
ClientSecret string `json:"client_secret"`
|
ClientSecret string `json:"client_secret"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppRepository interface {
|
type AppRepo interface {
|
||||||
Add(app App) (err error)
|
Add(app App) (err error)
|
||||||
Get(instanceDomain string) (app App, err error)
|
Get(instanceDomain string) (app App, err error)
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import "mastodon"
|
import (
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"mastodon"
|
||||||
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
*mastodon.Client
|
*mastodon.Client
|
||||||
|
Writer io.Writer
|
||||||
Session Session
|
Session Session
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ type Session struct {
|
|||||||
Settings Settings `json:"settings"`
|
Settings Settings `json:"settings"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SessionRepository interface {
|
type SessionRepo interface {
|
||||||
Add(session Session) (err error)
|
Add(session Session) (err error)
|
||||||
Get(sessionID string) (session Session, err error)
|
Get(sessionID string) (session Session, err error)
|
||||||
}
|
}
|
||||||
|
@ -47,9 +47,7 @@ type TimelineData struct {
|
|||||||
*CommonData
|
*CommonData
|
||||||
Title string
|
Title string
|
||||||
Statuses []*mastodon.Status
|
Statuses []*mastodon.Status
|
||||||
HasNext bool
|
|
||||||
NextLink string
|
NextLink string
|
||||||
HasPrev bool
|
|
||||||
PrevLink string
|
PrevLink string
|
||||||
PostContext model.PostContext
|
PostContext model.PostContext
|
||||||
}
|
}
|
||||||
@ -64,7 +62,6 @@ type ThreadData struct {
|
|||||||
type NotificationData struct {
|
type NotificationData struct {
|
||||||
*CommonData
|
*CommonData
|
||||||
Notifications []*mastodon.Notification
|
Notifications []*mastodon.Notification
|
||||||
HasNext bool
|
|
||||||
NextLink string
|
NextLink string
|
||||||
DarkMode bool
|
DarkMode bool
|
||||||
}
|
}
|
||||||
@ -73,7 +70,6 @@ type UserData struct {
|
|||||||
*CommonData
|
*CommonData
|
||||||
User *mastodon.Account
|
User *mastodon.Account
|
||||||
Statuses []*mastodon.Status
|
Statuses []*mastodon.Status
|
||||||
HasNext bool
|
|
||||||
NextLink string
|
NextLink string
|
||||||
DarkMode bool
|
DarkMode bool
|
||||||
}
|
}
|
||||||
@ -90,28 +86,24 @@ type EmojiData struct {
|
|||||||
type LikedByData struct {
|
type LikedByData struct {
|
||||||
*CommonData
|
*CommonData
|
||||||
Users []*mastodon.Account
|
Users []*mastodon.Account
|
||||||
HasNext bool
|
|
||||||
NextLink string
|
NextLink string
|
||||||
}
|
}
|
||||||
|
|
||||||
type RetweetedByData struct {
|
type RetweetedByData struct {
|
||||||
*CommonData
|
*CommonData
|
||||||
Users []*mastodon.Account
|
Users []*mastodon.Account
|
||||||
HasNext bool
|
|
||||||
NextLink string
|
NextLink string
|
||||||
}
|
}
|
||||||
|
|
||||||
type FollowingData struct {
|
type FollowingData struct {
|
||||||
*CommonData
|
*CommonData
|
||||||
Users []*mastodon.Account
|
Users []*mastodon.Account
|
||||||
HasNext bool
|
|
||||||
NextLink string
|
NextLink string
|
||||||
}
|
}
|
||||||
|
|
||||||
type FollowersData struct {
|
type FollowersData struct {
|
||||||
*CommonData
|
*CommonData
|
||||||
Users []*mastodon.Account
|
Users []*mastodon.Account
|
||||||
HasNext bool
|
|
||||||
NextLink string
|
NextLink string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +113,6 @@ type SearchData struct {
|
|||||||
Type string
|
Type string
|
||||||
Users []*mastodon.Account
|
Users []*mastodon.Account
|
||||||
Statuses []*mastodon.Status
|
Statuses []*mastodon.Status
|
||||||
HasNext bool
|
|
||||||
NextLink string
|
NextLink string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package renderer
|
package renderer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -89,78 +90,100 @@ func NewRenderer(templateGlobPattern string) (r *renderer, err error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *renderer) RenderSigninPage(ctx *Context, writer io.Writer, signinData *SigninData) (err error) {
|
func (r *renderer) RenderSigninPage(ctx *Context, writer io.Writer,
|
||||||
|
signinData *SigninData) (err error) {
|
||||||
return r.template.ExecuteTemplate(writer, "signin.tmpl", WithContext(signinData, ctx))
|
return r.template.ExecuteTemplate(writer, "signin.tmpl", WithContext(signinData, ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *renderer) RenderErrorPage(ctx *Context, writer io.Writer, errorData *ErrorData) {
|
func (r *renderer) RenderErrorPage(ctx *Context, writer io.Writer,
|
||||||
|
errorData *ErrorData) {
|
||||||
r.template.ExecuteTemplate(writer, "error.tmpl", WithContext(errorData, ctx))
|
r.template.ExecuteTemplate(writer, "error.tmpl", WithContext(errorData, ctx))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *renderer) RenderTimelinePage(ctx *Context, writer io.Writer, data *TimelineData) (err error) {
|
func (r *renderer) RenderTimelinePage(ctx *Context, writer io.Writer,
|
||||||
|
data *TimelineData) (err error) {
|
||||||
return r.template.ExecuteTemplate(writer, "timeline.tmpl", WithContext(data, ctx))
|
return r.template.ExecuteTemplate(writer, "timeline.tmpl", WithContext(data, ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *renderer) RenderThreadPage(ctx *Context, writer io.Writer, data *ThreadData) (err error) {
|
func (r *renderer) RenderThreadPage(ctx *Context, writer io.Writer,
|
||||||
|
data *ThreadData) (err error) {
|
||||||
return r.template.ExecuteTemplate(writer, "thread.tmpl", WithContext(data, ctx))
|
return r.template.ExecuteTemplate(writer, "thread.tmpl", WithContext(data, ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *renderer) RenderNotificationPage(ctx *Context, writer io.Writer, data *NotificationData) (err error) {
|
func (r *renderer) RenderNotificationPage(ctx *Context, writer io.Writer,
|
||||||
|
data *NotificationData) (err error) {
|
||||||
return r.template.ExecuteTemplate(writer, "notification.tmpl", WithContext(data, ctx))
|
return r.template.ExecuteTemplate(writer, "notification.tmpl", WithContext(data, ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *renderer) RenderUserPage(ctx *Context, writer io.Writer, data *UserData) (err error) {
|
func (r *renderer) RenderUserPage(ctx *Context, writer io.Writer,
|
||||||
|
data *UserData) (err error) {
|
||||||
return r.template.ExecuteTemplate(writer, "user.tmpl", WithContext(data, ctx))
|
return r.template.ExecuteTemplate(writer, "user.tmpl", WithContext(data, ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *renderer) RenderAboutPage(ctx *Context, writer io.Writer, data *AboutData) (err error) {
|
func (r *renderer) RenderAboutPage(ctx *Context, writer io.Writer,
|
||||||
|
data *AboutData) (err error) {
|
||||||
return r.template.ExecuteTemplate(writer, "about.tmpl", WithContext(data, ctx))
|
return r.template.ExecuteTemplate(writer, "about.tmpl", WithContext(data, ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *renderer) RenderEmojiPage(ctx *Context, writer io.Writer, data *EmojiData) (err error) {
|
func (r *renderer) RenderEmojiPage(ctx *Context, writer io.Writer,
|
||||||
|
data *EmojiData) (err error) {
|
||||||
return r.template.ExecuteTemplate(writer, "emoji.tmpl", WithContext(data, ctx))
|
return r.template.ExecuteTemplate(writer, "emoji.tmpl", WithContext(data, ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *renderer) RenderLikedByPage(ctx *Context, writer io.Writer, data *LikedByData) (err error) {
|
func (r *renderer) RenderLikedByPage(ctx *Context, writer io.Writer,
|
||||||
|
data *LikedByData) (err error) {
|
||||||
return r.template.ExecuteTemplate(writer, "likedby.tmpl", WithContext(data, ctx))
|
return r.template.ExecuteTemplate(writer, "likedby.tmpl", WithContext(data, ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *renderer) RenderRetweetedByPage(ctx *Context, writer io.Writer, data *RetweetedByData) (err error) {
|
func (r *renderer) RenderRetweetedByPage(ctx *Context, writer io.Writer,
|
||||||
|
data *RetweetedByData) (err error) {
|
||||||
return r.template.ExecuteTemplate(writer, "retweetedby.tmpl", WithContext(data, ctx))
|
return r.template.ExecuteTemplate(writer, "retweetedby.tmpl", WithContext(data, ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *renderer) RenderFollowingPage(ctx *Context, writer io.Writer, data *FollowingData) (err error) {
|
func (r *renderer) RenderFollowingPage(ctx *Context, writer io.Writer,
|
||||||
|
data *FollowingData) (err error) {
|
||||||
return r.template.ExecuteTemplate(writer, "following.tmpl", WithContext(data, ctx))
|
return r.template.ExecuteTemplate(writer, "following.tmpl", WithContext(data, ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *renderer) RenderFollowersPage(ctx *Context, writer io.Writer, data *FollowersData) (err error) {
|
func (r *renderer) RenderFollowersPage(ctx *Context, writer io.Writer,
|
||||||
|
data *FollowersData) (err error) {
|
||||||
return r.template.ExecuteTemplate(writer, "followers.tmpl", WithContext(data, ctx))
|
return r.template.ExecuteTemplate(writer, "followers.tmpl", WithContext(data, ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *renderer) RenderSearchPage(ctx *Context, writer io.Writer, data *SearchData) (err error) {
|
func (r *renderer) RenderSearchPage(ctx *Context, writer io.Writer,
|
||||||
|
data *SearchData) (err error) {
|
||||||
return r.template.ExecuteTemplate(writer, "search.tmpl", WithContext(data, ctx))
|
return r.template.ExecuteTemplate(writer, "search.tmpl", WithContext(data, ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *renderer) RenderSettingsPage(ctx *Context, writer io.Writer, data *SettingsData) (err error) {
|
func (r *renderer) RenderSettingsPage(ctx *Context, writer io.Writer,
|
||||||
|
data *SettingsData) (err error) {
|
||||||
return r.template.ExecuteTemplate(writer, "settings.tmpl", WithContext(data, ctx))
|
return r.template.ExecuteTemplate(writer, "settings.tmpl", WithContext(data, ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func EmojiFilter(content string, emojis []mastodon.Emoji) string {
|
func EmojiFilter(content string, emojis []mastodon.Emoji) string {
|
||||||
var replacements []string
|
var replacements []string
|
||||||
|
var r string
|
||||||
for _, e := range emojis {
|
for _, e := range emojis {
|
||||||
replacements = append(replacements, ":"+e.ShortCode+":", "<img class=\"status-emoji\" src=\""+e.URL+"\" alt=\""+e.ShortCode+"\" title=\""+e.ShortCode+"\" />")
|
r = fmt.Sprintf("<img class=\"status-emoji\" src=\"%s\" alt=\"%s\" title=\"%s\" />",
|
||||||
|
e.URL, e.ShortCode, e.ShortCode)
|
||||||
|
replacements = append(replacements, ":"+e.ShortCode+":", r)
|
||||||
}
|
}
|
||||||
return strings.NewReplacer(replacements...).Replace(content)
|
return strings.NewReplacer(replacements...).Replace(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func StatusContentFilter(spoiler string, content string, emojis []mastodon.Emoji, mentions []mastodon.Mention) string {
|
func StatusContentFilter(spoiler string, content string,
|
||||||
|
emojis []mastodon.Emoji, mentions []mastodon.Mention) string {
|
||||||
|
|
||||||
|
var replacements []string
|
||||||
|
var r string
|
||||||
if len(spoiler) > 0 {
|
if len(spoiler) > 0 {
|
||||||
content = spoiler + "<br />" + content
|
content = spoiler + "<br />" + content
|
||||||
}
|
}
|
||||||
var replacements []string
|
|
||||||
for _, e := range emojis {
|
for _, e := range emojis {
|
||||||
replacements = append(replacements, ":"+e.ShortCode+":", "<img class=\"status-emoji\" src=\""+e.URL+"\" alt=\""+e.ShortCode+"\" title=\""+e.ShortCode+"\" />")
|
r = fmt.Sprintf("<img class=\"status-emoji\" src=\"%s\" alt=\"%s\" title=\"%s\" />",
|
||||||
|
e.URL, e.ShortCode, e.ShortCode)
|
||||||
|
replacements = append(replacements, ":"+e.ShortCode+":", r)
|
||||||
}
|
}
|
||||||
for _, m := range mentions {
|
for _, m := range mentions {
|
||||||
replacements = append(replacements, "\""+m.URL+"\"", "\"/user/"+m.ID+"\"")
|
replacements = append(replacements, "\""+m.URL+"\"", "\"/user/"+m.ID+"\"")
|
||||||
@ -177,32 +200,26 @@ func DisplayInteractionCount(c int64) string {
|
|||||||
|
|
||||||
func TimeSince(t time.Time) string {
|
func TimeSince(t time.Time) string {
|
||||||
dur := time.Since(t)
|
dur := time.Since(t)
|
||||||
|
|
||||||
s := dur.Seconds()
|
s := dur.Seconds()
|
||||||
if s < 60 {
|
if s < 60 {
|
||||||
return strconv.Itoa(int(s)) + "s"
|
return strconv.Itoa(int(s)) + "s"
|
||||||
}
|
}
|
||||||
|
|
||||||
m := dur.Minutes()
|
m := dur.Minutes()
|
||||||
if m < 60 {
|
if m < 60 {
|
||||||
return strconv.Itoa(int(m)) + "m"
|
return strconv.Itoa(int(m)) + "m"
|
||||||
}
|
}
|
||||||
|
|
||||||
h := dur.Hours()
|
h := dur.Hours()
|
||||||
if h < 24 {
|
if h < 24 {
|
||||||
return strconv.Itoa(int(h)) + "h"
|
return strconv.Itoa(int(h)) + "h"
|
||||||
}
|
}
|
||||||
|
|
||||||
d := h / 24
|
d := h / 24
|
||||||
if d < 30 {
|
if d < 30 {
|
||||||
return strconv.Itoa(int(d)) + "d"
|
return strconv.Itoa(int(d)) + "d"
|
||||||
}
|
}
|
||||||
|
|
||||||
mo := d / 30
|
mo := d / 30
|
||||||
if mo < 12 {
|
if mo < 12 {
|
||||||
return strconv.Itoa(int(mo)) + "mo"
|
return strconv.Itoa(int(mo)) + "mo"
|
||||||
}
|
}
|
||||||
|
|
||||||
y := mo / 12
|
y := mo / 12
|
||||||
return strconv.Itoa(int(y)) + "y"
|
return strconv.Itoa(int(y)) + "y"
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package repository
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -7,17 +7,17 @@ import (
|
|||||||
"bloat/model"
|
"bloat/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type appRepository struct {
|
type appRepo struct {
|
||||||
db *kv.Database
|
db *kv.Database
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAppRepository(db *kv.Database) *appRepository {
|
func NewAppRepo(db *kv.Database) *appRepo {
|
||||||
return &appRepository{
|
return &appRepo{
|
||||||
db: db,
|
db: db,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *appRepository) Add(a model.App) (err error) {
|
func (repo *appRepo) Add(a model.App) (err error) {
|
||||||
data, err := json.Marshal(a)
|
data, err := json.Marshal(a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -26,7 +26,7 @@ func (repo *appRepository) Add(a model.App) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *appRepository) Get(instanceDomain string) (a model.App, err error) {
|
func (repo *appRepo) Get(instanceDomain string) (a model.App, err error) {
|
||||||
data, err := repo.db.Get(instanceDomain)
|
data, err := repo.db.Get(instanceDomain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = model.ErrAppNotFound
|
err = model.ErrAppNotFound
|
42
repo/sessionRepo.go
Normal file
42
repo/sessionRepo.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package repo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"bloat/kv"
|
||||||
|
"bloat/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
type sessionRepo struct {
|
||||||
|
db *kv.Database
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSessionRepo(db *kv.Database) *sessionRepo {
|
||||||
|
return &sessionRepo{
|
||||||
|
db: db,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo *sessionRepo) Add(s model.Session) (err error) {
|
||||||
|
data, err := json.Marshal(s)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = repo.db.Set(s.ID, data)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo *sessionRepo) Get(id string) (s model.Session, err error) {
|
||||||
|
data, err := repo.db.Get(id)
|
||||||
|
if err != nil {
|
||||||
|
err = model.ErrSessionNotFound
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &s)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
@ -1,64 +0,0 @@
|
|||||||
package repository
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"bloat/kv"
|
|
||||||
"bloat/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
type sessionRepository struct {
|
|
||||||
db *kv.Database
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSessionRepository(db *kv.Database) *sessionRepository {
|
|
||||||
return &sessionRepository{
|
|
||||||
db: db,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (repo *sessionRepository) Add(s model.Session) (err error) {
|
|
||||||
data, err := json.Marshal(s)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = repo.db.Set(s.ID, data)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (repo *sessionRepository) Update(id string, accessToken string) (err error) {
|
|
||||||
data, err := repo.db.Get(id)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var s model.Session
|
|
||||||
err = json.Unmarshal(data, &s)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
s.AccessToken = accessToken
|
|
||||||
|
|
||||||
data, err = json.Marshal(s)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
return repo.db.Set(id, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (repo *sessionRepository) Get(id string) (s model.Session, err error) {
|
|
||||||
data, err := repo.db.Get(id)
|
|
||||||
if err != nil {
|
|
||||||
err = model.ErrSessionNotFound
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = json.Unmarshal(data, &s)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
314
service/auth.go
314
service/auth.go
@ -3,7 +3,6 @@ package service
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
|
|
||||||
"bloat/model"
|
"bloat/model"
|
||||||
@ -11,28 +10,28 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrInvalidSession = errors.New("invalid session")
|
errInvalidSession = errors.New("invalid session")
|
||||||
ErrInvalidCSRFToken = errors.New("invalid csrf token")
|
errInvalidCSRFToken = errors.New("invalid csrf token")
|
||||||
)
|
)
|
||||||
|
|
||||||
type authService struct {
|
type as struct {
|
||||||
sessionRepo model.SessionRepository
|
sessionRepo model.SessionRepo
|
||||||
appRepo model.AppRepository
|
appRepo model.AppRepo
|
||||||
Service
|
Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAuthService(sessionRepo model.SessionRepository, appRepo model.AppRepository, s Service) Service {
|
func NewAuthService(sessionRepo model.SessionRepo, appRepo model.AppRepo, s Service) Service {
|
||||||
return &authService{sessionRepo, appRepo, s}
|
return &as{sessionRepo, appRepo, s}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) getClient(ctx context.Context) (c *model.Client, err error) {
|
func (s *as) authenticateClient(ctx context.Context, c *model.Client) (err error) {
|
||||||
sessionID, ok := ctx.Value("session_id").(string)
|
sessionID, ok := ctx.Value("session_id").(string)
|
||||||
if !ok || len(sessionID) < 1 {
|
if !ok || len(sessionID) < 1 {
|
||||||
return nil, ErrInvalidSession
|
return errInvalidSession
|
||||||
}
|
}
|
||||||
session, err := s.sessionRepo.Get(sessionID)
|
session, err := s.sessionRepo.Get(sessionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ErrInvalidSession
|
return errInvalidSession
|
||||||
}
|
}
|
||||||
client, err := s.appRepo.Get(session.InstanceDomain)
|
client, err := s.appRepo.Get(session.InstanceDomain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -44,31 +43,146 @@ func (s *authService) getClient(ctx context.Context) (c *model.Client, err error
|
|||||||
ClientSecret: client.ClientSecret,
|
ClientSecret: client.ClientSecret,
|
||||||
AccessToken: session.AccessToken,
|
AccessToken: session.AccessToken,
|
||||||
})
|
})
|
||||||
c = &model.Client{Client: mc, Session: session}
|
if c == nil {
|
||||||
return c, nil
|
c = &model.Client{}
|
||||||
|
}
|
||||||
|
c.Client = mc
|
||||||
|
c.Session = session
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkCSRF(ctx context.Context, c *model.Client) (err error) {
|
func checkCSRF(ctx context.Context, c *model.Client) (err error) {
|
||||||
csrfToken, ok := ctx.Value("csrf_token").(string)
|
token, ok := ctx.Value("csrf_token").(string)
|
||||||
if !ok || csrfToken != c.Session.CSRFToken {
|
if !ok || token != c.Session.CSRFToken {
|
||||||
return ErrInvalidCSRFToken
|
return errInvalidCSRFToken
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) GetAuthUrl(ctx context.Context, instance string) (
|
func (s *as) ServeErrorPage(ctx context.Context, c *model.Client, err error) {
|
||||||
redirectUrl string, sessionID string, err error) {
|
s.authenticateClient(ctx, c)
|
||||||
return s.Service.GetAuthUrl(ctx, instance)
|
s.Service.ServeErrorPage(ctx, c, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) GetUserToken(ctx context.Context, sessionID string, c *model.Client,
|
func (s *as) ServeSigninPage(ctx context.Context, c *model.Client) (err error) {
|
||||||
|
return s.Service.ServeSigninPage(ctx, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *as) ServeTimelinePage(ctx context.Context, c *model.Client, tType string,
|
||||||
|
maxID string, minID string) (err error) {
|
||||||
|
err = s.authenticateClient(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return s.Service.ServeTimelinePage(ctx, c, tType, maxID, minID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *as) ServeThreadPage(ctx context.Context, c *model.Client, id string, reply bool) (err error) {
|
||||||
|
err = s.authenticateClient(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return s.Service.ServeThreadPage(ctx, c, id, reply)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *as) ServeLikedByPage(ctx context.Context, c *model.Client, id string) (err error) {
|
||||||
|
err = s.authenticateClient(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return s.Service.ServeLikedByPage(ctx, c, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *as) ServeRetweetedByPage(ctx context.Context, c *model.Client, id string) (err error) {
|
||||||
|
err = s.authenticateClient(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return s.Service.ServeRetweetedByPage(ctx, c, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *as) ServeFollowingPage(ctx context.Context, c *model.Client, id string,
|
||||||
|
maxID string, minID string) (err error) {
|
||||||
|
err = s.authenticateClient(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return s.Service.ServeFollowingPage(ctx, c, id, maxID, minID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *as) ServeFollowersPage(ctx context.Context, c *model.Client, id string,
|
||||||
|
maxID string, minID string) (err error) {
|
||||||
|
err = s.authenticateClient(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return s.Service.ServeFollowersPage(ctx, c, id, maxID, minID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *as) ServeNotificationPage(ctx context.Context, c *model.Client,
|
||||||
|
maxID string, minID string) (err error) {
|
||||||
|
err = s.authenticateClient(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return s.Service.ServeNotificationPage(ctx, c, maxID, minID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *as) ServeUserPage(ctx context.Context, c *model.Client, id string,
|
||||||
|
maxID string, minID string) (err error) {
|
||||||
|
err = s.authenticateClient(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return s.Service.ServeUserPage(ctx, c, id, maxID, minID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *as) ServeAboutPage(ctx context.Context, c *model.Client) (err error) {
|
||||||
|
err = s.authenticateClient(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return s.Service.ServeAboutPage(ctx, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *as) ServeEmojiPage(ctx context.Context, c *model.Client) (err error) {
|
||||||
|
err = s.authenticateClient(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return s.Service.ServeEmojiPage(ctx, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *as) ServeSearchPage(ctx context.Context, c *model.Client, q string,
|
||||||
|
qType string, offset int) (err error) {
|
||||||
|
err = s.authenticateClient(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return s.Service.ServeSearchPage(ctx, c, q, qType, offset)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *as) ServeSettingsPage(ctx context.Context, c *model.Client) (err error) {
|
||||||
|
err = s.authenticateClient(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return s.Service.ServeSettingsPage(ctx, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *as) NewSession(ctx context.Context, instance string) (redirectUrl string,
|
||||||
|
sessionID string, err error) {
|
||||||
|
return s.Service.NewSession(ctx, instance)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *as) Signin(ctx context.Context, c *model.Client, sessionID string,
|
||||||
code string) (token string, err error) {
|
code string) (token string, err error) {
|
||||||
c, err = s.getClient(ctx)
|
err = s.authenticateClient(ctx, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
token, err = s.Service.GetUserToken(ctx, c.Session.ID, c, code)
|
token, err = s.Service.Signin(ctx, c, c.Session.ID, code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -82,114 +196,10 @@ func (s *authService) GetUserToken(ctx context.Context, sessionID string, c *mod
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) ServeErrorPage(ctx context.Context, client io.Writer, c *model.Client, err error) {
|
func (s *as) Post(ctx context.Context, c *model.Client, content string,
|
||||||
c, _ = s.getClient(ctx)
|
replyToID string, format string, visibility string, isNSFW bool,
|
||||||
s.Service.ServeErrorPage(ctx, client, c, err)
|
files []*multipart.FileHeader) (id string, err error) {
|
||||||
}
|
err = s.authenticateClient(ctx, c)
|
||||||
|
|
||||||
func (s *authService) ServeSigninPage(ctx context.Context, client io.Writer) (err error) {
|
|
||||||
return s.Service.ServeSigninPage(ctx, client)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *authService) ServeTimelinePage(ctx context.Context, client io.Writer,
|
|
||||||
c *model.Client, timelineType string, maxID string, sinceID string, minID string) (err error) {
|
|
||||||
c, err = s.getClient(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return s.Service.ServeTimelinePage(ctx, client, c, timelineType, maxID, sinceID, minID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *authService) ServeThreadPage(ctx context.Context, client io.Writer, c *model.Client, id string, reply bool) (err error) {
|
|
||||||
c, err = s.getClient(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return s.Service.ServeThreadPage(ctx, client, c, id, reply)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *authService) ServeNotificationPage(ctx context.Context, client io.Writer, c *model.Client, maxID string, minID string) (err error) {
|
|
||||||
c, err = s.getClient(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return s.Service.ServeNotificationPage(ctx, client, c, maxID, minID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *authService) ServeUserPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
|
|
||||||
c, err = s.getClient(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return s.Service.ServeUserPage(ctx, client, c, id, maxID, minID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *authService) ServeAboutPage(ctx context.Context, client io.Writer, c *model.Client) (err error) {
|
|
||||||
c, err = s.getClient(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return s.Service.ServeAboutPage(ctx, client, c)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *authService) ServeEmojiPage(ctx context.Context, client io.Writer, c *model.Client) (err error) {
|
|
||||||
c, err = s.getClient(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return s.Service.ServeEmojiPage(ctx, client, c)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *authService) ServeLikedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
|
||||||
c, err = s.getClient(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return s.Service.ServeLikedByPage(ctx, client, c, id)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *authService) ServeRetweetedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
|
||||||
c, err = s.getClient(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return s.Service.ServeRetweetedByPage(ctx, client, c, id)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *authService) ServeFollowingPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
|
|
||||||
c, err = s.getClient(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return s.Service.ServeFollowingPage(ctx, client, c, id, maxID, minID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *authService) ServeFollowersPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
|
|
||||||
c, err = s.getClient(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return s.Service.ServeFollowersPage(ctx, client, c, id, maxID, minID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *authService) ServeSearchPage(ctx context.Context, client io.Writer, c *model.Client, q string, qType string, offset int) (err error) {
|
|
||||||
c, err = s.getClient(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return s.Service.ServeSearchPage(ctx, client, c, q, qType, offset)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *authService) ServeSettingsPage(ctx context.Context, client io.Writer, c *model.Client) (err error) {
|
|
||||||
c, err = s.getClient(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return s.Service.ServeSettingsPage(ctx, client, c)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *authService) SaveSettings(ctx context.Context, client io.Writer, c *model.Client, settings *model.Settings) (err error) {
|
|
||||||
c, err = s.getClient(ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -197,11 +207,11 @@ func (s *authService) SaveSettings(ctx context.Context, client io.Writer, c *mod
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return s.Service.SaveSettings(ctx, client, c, settings)
|
return s.Service.Post(ctx, c, content, replyToID, format, visibility, isNSFW, files)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) Like(ctx context.Context, client io.Writer, c *model.Client, id string) (count int64, err error) {
|
func (s *as) Like(ctx context.Context, c *model.Client, id string) (count int64, err error) {
|
||||||
c, err = s.getClient(ctx)
|
err = s.authenticateClient(ctx, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -209,11 +219,11 @@ func (s *authService) Like(ctx context.Context, client io.Writer, c *model.Clien
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return s.Service.Like(ctx, client, c, id)
|
return s.Service.Like(ctx, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) UnLike(ctx context.Context, client io.Writer, c *model.Client, id string) (count int64, err error) {
|
func (s *as) UnLike(ctx context.Context, c *model.Client, id string) (count int64, err error) {
|
||||||
c, err = s.getClient(ctx)
|
err = s.authenticateClient(ctx, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -221,11 +231,11 @@ func (s *authService) UnLike(ctx context.Context, client io.Writer, c *model.Cli
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return s.Service.UnLike(ctx, client, c, id)
|
return s.Service.UnLike(ctx, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) Retweet(ctx context.Context, client io.Writer, c *model.Client, id string) (count int64, err error) {
|
func (s *as) Retweet(ctx context.Context, c *model.Client, id string) (count int64, err error) {
|
||||||
c, err = s.getClient(ctx)
|
err = s.authenticateClient(ctx, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -233,11 +243,11 @@ func (s *authService) Retweet(ctx context.Context, client io.Writer, c *model.Cl
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return s.Service.Retweet(ctx, client, c, id)
|
return s.Service.Retweet(ctx, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) UnRetweet(ctx context.Context, client io.Writer, c *model.Client, id string) (count int64, err error) {
|
func (s *as) UnRetweet(ctx context.Context, c *model.Client, id string) (count int64, err error) {
|
||||||
c, err = s.getClient(ctx)
|
err = s.authenticateClient(ctx, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -245,11 +255,11 @@ func (s *authService) UnRetweet(ctx context.Context, client io.Writer, c *model.
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return s.Service.UnRetweet(ctx, client, c, id)
|
return s.Service.UnRetweet(ctx, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) PostTweet(ctx context.Context, client io.Writer, c *model.Client, content string, replyToID string, format string, visibility string, isNSFW bool, files []*multipart.FileHeader) (id string, err error) {
|
func (s *as) Follow(ctx context.Context, c *model.Client, id string) (err error) {
|
||||||
c, err = s.getClient(ctx)
|
err = s.authenticateClient(ctx, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -257,11 +267,11 @@ func (s *authService) PostTweet(ctx context.Context, client io.Writer, c *model.
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return s.Service.PostTweet(ctx, client, c, content, replyToID, format, visibility, isNSFW, files)
|
return s.Service.Follow(ctx, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) Follow(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
func (s *as) UnFollow(ctx context.Context, c *model.Client, id string) (err error) {
|
||||||
c, err = s.getClient(ctx)
|
err = s.authenticateClient(ctx, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -269,11 +279,11 @@ func (s *authService) Follow(ctx context.Context, client io.Writer, c *model.Cli
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return s.Service.Follow(ctx, client, c, id)
|
return s.Service.UnFollow(ctx, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) UnFollow(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
func (s *as) SaveSettings(ctx context.Context, c *model.Client, settings *model.Settings) (err error) {
|
||||||
c, err = s.getClient(ctx)
|
err = s.authenticateClient(ctx, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -281,5 +291,5 @@ func (s *authService) UnFollow(ctx context.Context, client io.Writer, c *model.C
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return s.Service.UnFollow(ctx, client, c, id)
|
return s.Service.SaveSettings(ctx, c, settings)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
|
||||||
"log"
|
"log"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"time"
|
"time"
|
||||||
@ -10,206 +9,215 @@ import (
|
|||||||
"bloat/model"
|
"bloat/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type loggingService struct {
|
type ls struct {
|
||||||
logger *log.Logger
|
logger *log.Logger
|
||||||
Service
|
Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLoggingService(logger *log.Logger, s Service) Service {
|
func NewLoggingService(logger *log.Logger, s Service) Service {
|
||||||
return &loggingService{logger, s}
|
return &ls{logger, s}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) GetAuthUrl(ctx context.Context, instance string) (
|
func (s *ls) ServeErrorPage(ctx context.Context, c *model.Client, err error) {
|
||||||
redirectUrl string, sessionID string, err error) {
|
|
||||||
defer func(begin time.Time) {
|
|
||||||
s.logger.Printf("method=%v, instance=%v, took=%v, err=%v\n",
|
|
||||||
"GetAuthUrl", instance, time.Since(begin), err)
|
|
||||||
}(time.Now())
|
|
||||||
return s.Service.GetAuthUrl(ctx, instance)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *loggingService) GetUserToken(ctx context.Context, sessionID string, c *model.Client,
|
|
||||||
code string) (token string, err error) {
|
|
||||||
defer func(begin time.Time) {
|
|
||||||
s.logger.Printf("method=%v, session_id=%v, code=%v, took=%v, err=%v\n",
|
|
||||||
"GetUserToken", sessionID, code, time.Since(begin), err)
|
|
||||||
}(time.Now())
|
|
||||||
return s.Service.GetUserToken(ctx, sessionID, c, code)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *loggingService) ServeErrorPage(ctx context.Context, client io.Writer, c *model.Client, err error) {
|
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, err=%v, took=%v\n",
|
s.logger.Printf("method=%v, err=%v, took=%v\n",
|
||||||
"ServeErrorPage", err, time.Since(begin))
|
"ServeErrorPage", err, time.Since(begin))
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
s.Service.ServeErrorPage(ctx, client, c, err)
|
s.Service.ServeErrorPage(ctx, c, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) ServeSigninPage(ctx context.Context, client io.Writer) (err error) {
|
func (s *ls) ServeSigninPage(ctx context.Context, c *model.Client) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, took=%v, err=%v\n",
|
||||||
"ServeSigninPage", time.Since(begin), err)
|
"ServeSigninPage", time.Since(begin), err)
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
return s.Service.ServeSigninPage(ctx, client)
|
return s.Service.ServeSigninPage(ctx, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) ServeTimelinePage(ctx context.Context, client io.Writer,
|
func (s *ls) ServeTimelinePage(ctx context.Context, c *model.Client, tType string,
|
||||||
c *model.Client, timelineType string, maxID string, sinceID string, minID string) (err error) {
|
maxID string, minID string) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, timeline_type=%v, max_id=%v, since_id=%v, min_id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, type=%v, took=%v, err=%v\n",
|
||||||
"ServeTimelinePage", timelineType, maxID, sinceID, minID, time.Since(begin), err)
|
"ServeTimelinePage", tType, time.Since(begin), err)
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
return s.Service.ServeTimelinePage(ctx, client, c, timelineType, maxID, sinceID, minID)
|
return s.Service.ServeTimelinePage(ctx, c, tType, maxID, minID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) ServeThreadPage(ctx context.Context, client io.Writer, c *model.Client, id string, reply bool) (err error) {
|
func (s *ls) ServeThreadPage(ctx context.Context, c *model.Client, id string,
|
||||||
|
reply bool) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, reply=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
"ServeThreadPage", id, reply, time.Since(begin), err)
|
"ServeThreadPage", id, time.Since(begin), err)
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
return s.Service.ServeThreadPage(ctx, client, c, id, reply)
|
return s.Service.ServeThreadPage(ctx, c, id, reply)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) ServeNotificationPage(ctx context.Context, client io.Writer, c *model.Client, maxID string, minID string) (err error) {
|
func (s *ls) ServeLikedByPage(ctx context.Context, c *model.Client, id string) (err error) {
|
||||||
defer func(begin time.Time) {
|
|
||||||
s.logger.Printf("method=%v, max_id=%v, min_id=%v, took=%v, err=%v\n",
|
|
||||||
"ServeNotificationPage", maxID, minID, time.Since(begin), err)
|
|
||||||
}(time.Now())
|
|
||||||
return s.Service.ServeNotificationPage(ctx, client, c, maxID, minID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *loggingService) ServeUserPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
|
|
||||||
defer func(begin time.Time) {
|
|
||||||
s.logger.Printf("method=%v, id=%v, max_id=%v, min_id=%v, took=%v, err=%v\n",
|
|
||||||
"ServeUserPage", id, maxID, minID, time.Since(begin), err)
|
|
||||||
}(time.Now())
|
|
||||||
return s.Service.ServeUserPage(ctx, client, c, id, maxID, minID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *loggingService) ServeAboutPage(ctx context.Context, client io.Writer, c *model.Client) (err error) {
|
|
||||||
defer func(begin time.Time) {
|
|
||||||
s.logger.Printf("method=%v, took=%v, err=%v\n",
|
|
||||||
"ServeAboutPage", time.Since(begin), err)
|
|
||||||
}(time.Now())
|
|
||||||
return s.Service.ServeAboutPage(ctx, client, c)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *loggingService) ServeEmojiPage(ctx context.Context, client io.Writer, c *model.Client) (err error) {
|
|
||||||
defer func(begin time.Time) {
|
|
||||||
s.logger.Printf("method=%v, took=%v, err=%v\n",
|
|
||||||
"ServeEmojiPage", time.Since(begin), err)
|
|
||||||
}(time.Now())
|
|
||||||
return s.Service.ServeEmojiPage(ctx, client, c)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *loggingService) ServeLikedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
"ServeLikedByPage", id, time.Since(begin), err)
|
"ServeLikedByPage", id, time.Since(begin), err)
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
return s.Service.ServeLikedByPage(ctx, client, c, id)
|
return s.Service.ServeLikedByPage(ctx, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) ServeRetweetedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
func (s *ls) ServeRetweetedByPage(ctx context.Context, c *model.Client, id string) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
"ServeRetweetedByPage", id, time.Since(begin), err)
|
"ServeRetweetedByPage", id, time.Since(begin), err)
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
return s.Service.ServeRetweetedByPage(ctx, client, c, id)
|
return s.Service.ServeRetweetedByPage(ctx, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) ServeFollowingPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
|
func (s *ls) ServeFollowingPage(ctx context.Context, c *model.Client, id string,
|
||||||
|
maxID string, minID string) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, max_id=%v, min_id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
"ServeFollowingPage", id, maxID, minID, time.Since(begin), err)
|
"ServeFollowingPage", id, time.Since(begin), err)
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
return s.Service.ServeFollowingPage(ctx, client, c, id, maxID, minID)
|
return s.Service.ServeFollowingPage(ctx, c, id, maxID, minID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) ServeFollowersPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
|
func (s *ls) ServeFollowersPage(ctx context.Context, c *model.Client, id string,
|
||||||
|
maxID string, minID string) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, max_id=%v, min_id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
"ServeFollowersPage", id, maxID, minID, time.Since(begin), err)
|
"ServeFollowersPage", id, time.Since(begin), err)
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
return s.Service.ServeFollowersPage(ctx, client, c, id, maxID, minID)
|
return s.Service.ServeFollowersPage(ctx, c, id, maxID, minID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) ServeSearchPage(ctx context.Context, client io.Writer, c *model.Client, q string, qType string, offset int) (err error) {
|
func (s *ls) ServeNotificationPage(ctx context.Context, c *model.Client,
|
||||||
|
maxID string, minID string) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, q=%v, type=%v, offset=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, took=%v, err=%v\n",
|
||||||
"ServeSearchPage", q, qType, offset, time.Since(begin), err)
|
"ServeNotificationPage", time.Since(begin), err)
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
return s.Service.ServeSearchPage(ctx, client, c, q, qType, offset)
|
return s.Service.ServeNotificationPage(ctx, c, maxID, minID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) ServeSettingsPage(ctx context.Context, client io.Writer, c *model.Client) (err error) {
|
func (s *ls) ServeUserPage(ctx context.Context, c *model.Client, id string,
|
||||||
|
maxID string, minID string) (err error) {
|
||||||
|
defer func(begin time.Time) {
|
||||||
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
|
"ServeUserPage", id, time.Since(begin), err)
|
||||||
|
}(time.Now())
|
||||||
|
return s.Service.ServeUserPage(ctx, c, id, maxID, minID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ls) ServeAboutPage(ctx context.Context, c *model.Client) (err error) {
|
||||||
|
defer func(begin time.Time) {
|
||||||
|
s.logger.Printf("method=%v, took=%v, err=%v\n",
|
||||||
|
"ServeAboutPage", time.Since(begin), err)
|
||||||
|
}(time.Now())
|
||||||
|
return s.Service.ServeAboutPage(ctx, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ls) ServeEmojiPage(ctx context.Context, c *model.Client) (err error) {
|
||||||
|
defer func(begin time.Time) {
|
||||||
|
s.logger.Printf("method=%v, took=%v, err=%v\n",
|
||||||
|
"ServeEmojiPage", time.Since(begin), err)
|
||||||
|
}(time.Now())
|
||||||
|
return s.Service.ServeEmojiPage(ctx, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ls) ServeSearchPage(ctx context.Context, c *model.Client, q string,
|
||||||
|
qType string, offset int) (err error) {
|
||||||
|
defer func(begin time.Time) {
|
||||||
|
s.logger.Printf("method=%v, took=%v, err=%v\n",
|
||||||
|
"ServeSearchPage", time.Since(begin), err)
|
||||||
|
}(time.Now())
|
||||||
|
return s.Service.ServeSearchPage(ctx, c, q, qType, offset)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ls) ServeSettingsPage(ctx context.Context, c *model.Client) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, took=%v, err=%v\n",
|
||||||
"ServeSettingsPage", time.Since(begin), err)
|
"ServeSettingsPage", time.Since(begin), err)
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
return s.Service.ServeSettingsPage(ctx, client, c)
|
return s.Service.ServeSettingsPage(ctx, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) SaveSettings(ctx context.Context, client io.Writer, c *model.Client, settings *model.Settings) (err error) {
|
func (s *ls) NewSession(ctx context.Context, instance string) (redirectUrl string,
|
||||||
|
sessionID string, err error) {
|
||||||
|
defer func(begin time.Time) {
|
||||||
|
s.logger.Printf("method=%v, instance=%v, took=%v, err=%v\n",
|
||||||
|
"NewSession", instance, time.Since(begin), err)
|
||||||
|
}(time.Now())
|
||||||
|
return s.Service.NewSession(ctx, instance)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ls) Signin(ctx context.Context, c *model.Client, sessionID string,
|
||||||
|
code string) (token string, err error) {
|
||||||
|
defer func(begin time.Time) {
|
||||||
|
s.logger.Printf("method=%v, session_id=%v, took=%v, err=%v\n",
|
||||||
|
"Signin", sessionID, time.Since(begin), err)
|
||||||
|
}(time.Now())
|
||||||
|
return s.Service.Signin(ctx, c, sessionID, code)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ls) Post(ctx context.Context, c *model.Client, content string,
|
||||||
|
replyToID string, format string, visibility string, isNSFW bool,
|
||||||
|
files []*multipart.FileHeader) (id string, err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, took=%v, err=%v\n",
|
||||||
"SaveSettings", time.Since(begin), err)
|
"Post", time.Since(begin), err)
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
return s.Service.SaveSettings(ctx, client, c, settings)
|
return s.Service.Post(ctx, c, content, replyToID, format,
|
||||||
|
visibility, isNSFW, files)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) Like(ctx context.Context, client io.Writer, c *model.Client, id string) (count int64, err error) {
|
func (s *ls) Like(ctx context.Context, c *model.Client, id string) (count int64, err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
"Like", id, time.Since(begin), err)
|
"Like", id, time.Since(begin), err)
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
return s.Service.Like(ctx, client, c, id)
|
return s.Service.Like(ctx, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) UnLike(ctx context.Context, client io.Writer, c *model.Client, id string) (count int64, err error) {
|
func (s *ls) UnLike(ctx context.Context, c *model.Client, id string) (count int64, err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
"UnLike", id, time.Since(begin), err)
|
"UnLike", id, time.Since(begin), err)
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
return s.Service.UnLike(ctx, client, c, id)
|
return s.Service.UnLike(ctx, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) Retweet(ctx context.Context, client io.Writer, c *model.Client, id string) (count int64, err error) {
|
func (s *ls) Retweet(ctx context.Context, c *model.Client, id string) (count int64, err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
"Retweet", id, time.Since(begin), err)
|
"Retweet", id, time.Since(begin), err)
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
return s.Service.Retweet(ctx, client, c, id)
|
return s.Service.Retweet(ctx, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) UnRetweet(ctx context.Context, client io.Writer, c *model.Client, id string) (count int64, err error) {
|
func (s *ls) UnRetweet(ctx context.Context, c *model.Client, id string) (count int64, err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
"UnRetweet", id, time.Since(begin), err)
|
"UnRetweet", id, time.Since(begin), err)
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
return s.Service.UnRetweet(ctx, client, c, id)
|
return s.Service.UnRetweet(ctx, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) PostTweet(ctx context.Context, client io.Writer, c *model.Client, content string, replyToID string, format string, visibility string, isNSFW bool, files []*multipart.FileHeader) (id string, err error) {
|
func (s *ls) Follow(ctx context.Context, c *model.Client, id string) (err error) {
|
||||||
defer func(begin time.Time) {
|
|
||||||
s.logger.Printf("method=%v, content=%v, reply_to_id=%v, format=%v, visibility=%v, is_nsfw=%v, took=%v, err=%v\n",
|
|
||||||
"PostTweet", content, replyToID, format, visibility, isNSFW, time.Since(begin), err)
|
|
||||||
}(time.Now())
|
|
||||||
return s.Service.PostTweet(ctx, client, c, content, replyToID, format, visibility, isNSFW, files)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *loggingService) Follow(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
"Follow", id, time.Since(begin), err)
|
"Follow", id, time.Since(begin), err)
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
return s.Service.Follow(ctx, client, c, id)
|
return s.Service.Follow(ctx, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) UnFollow(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
func (s *ls) UnFollow(ctx context.Context, c *model.Client, id string) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
"UnFollow", id, time.Since(begin), err)
|
"UnFollow", id, time.Since(begin), err)
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
return s.Service.UnFollow(ctx, client, c, id)
|
return s.Service.UnFollow(ctx, c, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ls) SaveSettings(ctx context.Context, c *model.Client, settings *model.Settings) (err error) {
|
||||||
|
defer func(begin time.Time) {
|
||||||
|
s.logger.Printf("method=%v, took=%v, err=%v\n",
|
||||||
|
"SaveSettings", time.Since(begin), err)
|
||||||
|
}(time.Now())
|
||||||
|
return s.Service.SaveSettings(ctx, c, settings)
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
1014
service/transport.go
1014
service/transport.go
File diff suppressed because it is too large
Load Diff
@ -1,3 +0,0 @@
|
|||||||
html {
|
|
||||||
background: #000000;
|
|
||||||
}
|
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
{{template "userlist.tmpl" (WithContext .Users $.Ctx)}}
|
{{template "userlist.tmpl" (WithContext .Users $.Ctx)}}
|
||||||
<div class="pagination">
|
<div class="pagination">
|
||||||
{{if .HasNext}}
|
{{if .NextLink}}
|
||||||
<a href="{{.NextLink}}">next</a>
|
<a href="{{.NextLink}}">next</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
{{template "userlist.tmpl" (WithContext .Users $.Ctx)}}
|
{{template "userlist.tmpl" (WithContext .Users $.Ctx)}}
|
||||||
<div class="pagination">
|
<div class="pagination">
|
||||||
{{if .HasNext}}
|
{{if .NextLink}}
|
||||||
<a href="{{.NextLink}}">next</a>
|
<a href="{{.NextLink}}">next</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<meta name="csrf_token" content="{{.CSRFToken}}">
|
<meta name="csrf_token" content="{{.CSRFToken}}">
|
||||||
{{end}}
|
{{end}}
|
||||||
<title>{{if gt .NotificationCount 0}}({{.NotificationCount}}) {{end}}{{.Title}}</title>
|
<title>{{if gt .NotificationCount 0}}({{.NotificationCount}}) {{end}}{{.Title}}</title>
|
||||||
<link rel="stylesheet" href="/static/main.css">
|
<link rel="stylesheet" href="/static/style.css">
|
||||||
{{if .CustomCSS}}
|
{{if .CustomCSS}}
|
||||||
<link rel="stylesheet" href="{{.CustomCSS}}">
|
<link rel="stylesheet" href="{{.CustomCSS}}">
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -65,7 +65,7 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
<div class="pagination">
|
<div class="pagination">
|
||||||
{{if .HasNext}}
|
{{if .NextLink}}
|
||||||
<a href="{{.NextLink}}">next</a>
|
<a href="{{.NextLink}}">next</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
<div class="pagination">
|
<div class="pagination">
|
||||||
{{if .HasNext}}
|
{{if .NextLink}}
|
||||||
<a href="{{.NextLink}}">next</a>
|
<a href="{{.NextLink}}">next</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -10,10 +10,10 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
<div class="pagination">
|
<div class="pagination">
|
||||||
{{if .HasPrev}}
|
{{if .PrevLink}}
|
||||||
<a href="{{.PrevLink}}">prev</a>
|
<a href="{{.PrevLink}}">prev</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .HasNext}}
|
{{if .NextLink}}
|
||||||
<a href="{{.NextLink}}">next</a>
|
<a href="{{.NextLink}}">next</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
<div class="pagination">
|
<div class="pagination">
|
||||||
{{if .HasNext}}
|
{{if .NextLink}}
|
||||||
<a href="{{.NextLink}}">next</a>
|
<a href="{{.NextLink}}">next</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -10,7 +10,7 @@ var (
|
|||||||
runes_length = len(runes)
|
runes_length = len(runes)
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewRandId(n int) (string, error) {
|
func NewRandID(n int) (string, error) {
|
||||||
data := make([]rune, n)
|
data := make([]rune, n)
|
||||||
for i := range data {
|
for i := range data {
|
||||||
num, err := rand.Int(rand.Reader, big.NewInt(int64(runes_length)))
|
num, err := rand.Int(rand.Reader, big.NewInt(int64(runes_length)))
|
||||||
@ -22,10 +22,10 @@ func NewRandId(n int) (string, error) {
|
|||||||
return string(data), nil
|
return string(data), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSessionId() (string, error) {
|
func NewSessionID() (string, error) {
|
||||||
return NewRandId(24)
|
return NewRandID(24)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCSRFToken() (string, error) {
|
func NewCSRFToken() (string, error) {
|
||||||
return NewRandId(24)
|
return NewRandID(24)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user