Have got session creation working
This commit is contained in:
parent
18f9f49c0a
commit
036b683eab
10 changed files with 438 additions and 3 deletions
|
|
@ -8,3 +8,4 @@ var NotFoundError = errors.New("not found")
|
|||
var SiteRequiredError = errors.New("site required")
|
||||
var DeleteDebounceError = errors.New("permanent delete too soon, try again in a few seconds")
|
||||
var SlugConflictError = errors.New("a record with this slug already exists")
|
||||
var UnsupportedImageFormat = errors.New("unsupported image format")
|
||||
|
|
|
|||
59
models/imgedit.go
Normal file
59
models/imgedit.go
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ImageEditSession struct {
|
||||
GUID string `json:"guid"`
|
||||
SiteID int64 `json:"siteId"`
|
||||
UserID int64 `json:"userId"`
|
||||
BaseUploadID int64 `json:"baseUploadId"`
|
||||
ImageExt string `json:"imageExt"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
Processors []ImageEditProcessor `json:"processors"`
|
||||
}
|
||||
|
||||
func (ieh ImageEditSession) PreviewURL() string {
|
||||
return fmt.Sprintf("/sites/%v/imageedit/%v/preview/%v", ieh.SiteID, ieh.GUID, ieh.Processors[len(ieh.Processors)-1].VersionID)
|
||||
}
|
||||
|
||||
func (ieh *ImageEditSession) RecalcVersionIDs() {
|
||||
for i, p := range ieh.Processors {
|
||||
if i == 0 {
|
||||
p.SetVersionID("")
|
||||
} else {
|
||||
p.SetVersionID(ieh.Processors[i-1].VersionID)
|
||||
}
|
||||
|
||||
ieh.Processors[i] = p
|
||||
}
|
||||
}
|
||||
|
||||
type ImageEditProcessor struct {
|
||||
Type string `json:"type"`
|
||||
Props json.RawMessage `json:"props"`
|
||||
|
||||
// VersionID is a unique hash of the particular processor. This includes the version ID of the previous processor,
|
||||
// thereby causing a change of one processor to affect the version IDs of processors down the line.
|
||||
VersionID string `json:"versionId"`
|
||||
}
|
||||
|
||||
func (ieh *ImageEditProcessor) SetVersionID(previousVersionID string) {
|
||||
var sb strings.Builder
|
||||
sb.WriteString(previousVersionID)
|
||||
sb.WriteString("-")
|
||||
sb.WriteString(ieh.Type)
|
||||
sb.WriteString("-")
|
||||
sb.WriteString(string(ieh.Props))
|
||||
ieh.VersionID = fmt.Sprintf("%x", md5.Sum([]byte(sb.String())))
|
||||
}
|
||||
|
||||
type CopyUploadProps struct {
|
||||
UploadID int64 `json:"uploadId"`
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue