Skip to content

Commit

Permalink
refactor: Adding Stringer to optimize sha computation
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Oct 8, 2022
1 parent 45a06c2 commit 9c14c7f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/provider/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"fmt"
"net/http"
"strconv"
"strings"

absto "github.com/ViBiOh/absto/pkg/model"
Expand Down Expand Up @@ -82,6 +83,20 @@ type Request struct {
CanWebhook bool
}

func (r Request) String() string {
var output strings.Builder

output.WriteString(r.Path)
output.WriteString(strconv.FormatBool(r.CanEdit))
output.WriteString(r.Item)
output.WriteString(strconv.FormatBool(r.CanShare))
output.WriteString(r.Display)
output.WriteString(strconv.FormatBool(r.CanWebhook))
output.WriteString(r.Share.String())

return output.String()
}

func (r Request) UpdatePreferences() Request {
if r.Display == DefaultDisplay {
r.Preferences = r.Preferences.RemoveLayout(r.AbsoluteURL(""))
Expand Down
14 changes: 14 additions & 0 deletions pkg/provider/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"encoding/base64"
"errors"
"strconv"
"strings"
"time"

Expand All @@ -21,6 +22,19 @@ type Share struct {
File bool `json:"file"`
}

func (s Share) String() string {
var output strings.Builder

output.WriteString(s.ID)
output.WriteString(strconv.FormatBool(s.Edit))
output.WriteString(s.Path)
output.WriteString(strconv.FormatBool(s.Story))
output.WriteString(s.RootName)
output.WriteString(strconv.FormatBool(s.File))

return output.String()
}

func (s Share) IsZero() bool {
return len(s.ID) == 0
}
Expand Down
29 changes: 29 additions & 0 deletions pkg/provider/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provider

import (
"mime"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -64,6 +65,20 @@ type RenderItem struct {
IsCover bool
}

func (r RenderItem) String() string {
var output strings.Builder

output.WriteString(r.URL)
output.WriteString(strconv.FormatBool(r.HasThumbnail))
output.WriteString(r.Path)
output.WriteString(strconv.FormatBool(r.IsCover))
output.WriteString(r.ID)
output.WriteString(strconv.FormatInt(r.Size, 10))
output.WriteString(r.Date.String())

return output.String()
}

func (r RenderItem) IsZero() bool {
return r.Item.IsZero()
}
Expand Down Expand Up @@ -107,6 +122,20 @@ type StoryItem struct {
RenderItem
}

func (s StoryItem) String() string {
var output strings.Builder

output.WriteString(s.URL)
output.WriteString(strconv.FormatBool(s.HasThumbnail))
output.WriteString(s.Path)
output.WriteString(strconv.FormatBool(s.IsCover))
output.WriteString(s.ID)
output.WriteString(strconv.FormatInt(s.Size, 10))
output.WriteString(s.Date.String())

return output.String()
}

func StorageToStory(item absto.Item, request Request, exif model.Exif) StoryItem {
return StoryItem{
RenderItem: StorageToRender(item, request),
Expand Down

0 comments on commit 9c14c7f

Please sign in to comment.