feat: image variants engine
This commit is contained in:
1 parent
f0845de643
commit
f1d56ef50e
80 files changed
+7312
-84
No files matched your search
@@ -2,6 +2,7 @@ package audit
|
||||
|
||||
import (
|
||||
"RenewCMS/internal/domain/article"
|
||||
"RenewCMS/internal/domain/image"
|
||||
"strconv"
|
||||
"unicode/utf8"
|
||||
)
|
||||
@@ -28,3 +29,34 @@ func ArticleChanges(before article.Article, after article.Article) []Change {
|
||||
}
|
||||
return changes
|
||||
}
|
||||
|
||||
func VariantChanges(before image.VariantSettings, after image.VariantSettings) []Change {
|
||||
changes := []Change{}
|
||||
changes = appendChange(changes, FieldWidth, image.DimensionText(before.Width), image.DimensionText(after.Width))
|
||||
changes = appendChange(changes, FieldHeight, image.DimensionText(before.Height), image.DimensionText(after.Height))
|
||||
changes = appendChange(changes, FieldFit, string(before.Fit), string(after.Fit))
|
||||
changes = appendChange(changes, FieldFormat, string(before.Format), string(after.Format))
|
||||
changes = appendChange(changes, FieldQuality, image.QualityText(before.Quality), image.QualityText(after.Quality))
|
||||
return changes
|
||||
}
|
||||
|
||||
func appendChange(changes []Change, field string, before string, after string) []Change {
|
||||
if before == after {
|
||||
return changes
|
||||
}
|
||||
return append(changes, TextChange(field, before, after))
|
||||
}
|
||||
|
||||
func VariantParams(settings image.VariantSettings) map[string]any {
|
||||
params := map[string]any{ParamFit: string(settings.Fit), ParamFormat: string(settings.Format)}
|
||||
if settings.Width != nil {
|
||||
params[ParamWidth] = *settings.Width
|
||||
}
|
||||
if settings.Height != nil {
|
||||
params[ParamHeight] = *settings.Height
|
||||
}
|
||||
if settings.Quality != nil {
|
||||
params[ParamQuality] = *settings.Quality
|
||||
}
|
||||
return params
|
||||
}
|
||||
@@ -76,6 +76,12 @@ const (
|
||||
ActionMediaDelete = "media.delete"
|
||||
ActionMediaMerge = "media.merge"
|
||||
ActionMediaPurge = "media.purge"
|
||||
ActionVariantCreate = "media.variant_create"
|
||||
ActionVariantUpdate = "media.variant_update"
|
||||
ActionVariantDelete = "media.variant_delete"
|
||||
ActionVariantEnable = "media.variant_enable"
|
||||
ActionVariantDisable = "media.variant_disable"
|
||||
ActionVariantPurge = "media.variant_purge"
|
||||
ActionUserRegister = "user.register"
|
||||
ActionUserVerify = "user.verify"
|
||||
ActionUserUpdateProfile = "user.update_profile"
|
||||
@@ -94,6 +100,7 @@ const (
|
||||
TargetUser = "user"
|
||||
TargetArticle = "article"
|
||||
TargetImage = "image"
|
||||
TargetVariant = "image_variant"
|
||||
TargetInvite = "invite"
|
||||
TargetRelease = "release"
|
||||
)
|
||||
@@ -112,12 +119,24 @@ const (
|
||||
ParamFailedGroups = "failed_groups"
|
||||
ParamUpdateAvailable = "update_available"
|
||||
ParamKind = "kind"
|
||||
ParamPurgedFiles = "purged_files"
|
||||
ParamPurgedBytes = "purged_bytes"
|
||||
ParamWidth = "width"
|
||||
ParamHeight = "height"
|
||||
ParamFit = "fit"
|
||||
ParamFormat = "format"
|
||||
ParamQuality = "quality"
|
||||
ParamTag = "tag"
|
||||
FieldTitle = "title"
|
||||
FieldOnline = "online"
|
||||
FieldBody = "body"
|
||||
FieldFilename = "filename"
|
||||
FieldDisplayName = "display_name"
|
||||
FieldWidth = "width"
|
||||
FieldHeight = "height"
|
||||
FieldFit = "fit"
|
||||
FieldFormat = "format"
|
||||
FieldQuality = "quality"
|
||||
maxNameLength = 255
|
||||
maxActionLength = 64
|
||||
maxFailureReasonSize = 255
|
||||
|
||||
@@ -9,3 +9,7 @@ func NewTarget(targetType string, id uint32, name string) Target {
|
||||
func ReleaseTarget(tag string) Target {
|
||||
return Target{Type: TargetRelease, ID: tag, Name: tag}
|
||||
}
|
||||
|
||||
func VariantTarget(name string) Target {
|
||||
return Target{Type: TargetVariant, ID: name, Name: name}
|
||||
}
|
||||
Reference in new issue
Block a user