media

package
v3.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: MIT Imports: 27 Imported by: 0

README

Cropping logic explanation

The principles of cropping are as follows

  1. Users get what they see in the media library selector after selecting an image. No matter it is in the PageBuilder or in SEO or other places
  2. Cropping an image won't affect any other places that use the same image
  • Crop will always create a new file with rule {file}_{size}_{crop_id}.ext
    • original file is file.png after crop will be file_{uuid}.png
    • original file is file_thumb.png after crop will be file_thumb_{uuid}.png
  • cropOption will not be saved in the media library table; cropOption will be saved where the image is used.
    • If the image is used in the SEO configuration. cropOption will be saved in the SEO record, the field name is OpenGraphImageFromMediaLibrary. it is a MediaBox
    • If the image is used in the PageBuilder. cropOption will be saved in the PageBuilder record, it is a MediaBox

To cleanup unused file copies

The cropping logic might leave some unused file copies. If we need to clean them up. We have to fetch all MediaBox records and compare it with the file names in the file system. Then remove the unused files.

Documentation

Index

Constants

View Source
const (
	OpenFileChooserEvent = "mediaLibrary_OpenFileChooserEvent"

	ImageSearchEvent   = "mediaLibrary_ImageSearchEvent"
	ImageJumpPageEvent = "mediaLibrary_ImageJumpPageEvent"
	UploadFileEvent    = "mediaLibrary_UploadFileEvent"

	UpdateDescriptionEvent       = "mediaLibrary_UpdateDescriptionEvent"
	DeleteConfirmationEvent      = "mediaLibrary_DeleteConfirmationEvent"
	DoDeleteEvent                = "mediaLibrary_DoDelete"
	CreateFolderEvent            = "mediaLibrary_CreateFolderEvent"
	RenameDialogEvent            = "mediaLibrary_RenameDialogEvent"
	RenameEvent                  = "mediaLibrary_RenameEvent"
	UpdateDescriptionDialogEvent = "mediaLibrary_UpdateDescriptionDialogEvent"
	NewFolderDialogEvent         = "mediaLibrary_NewFolderDialogEvent"
	MoveToFolderDialogEvent      = "mediaLibrary_MoveToFolderDialogEvent"
	MoveToFolderEvent            = "mediaLibrary_MoveToFolderEvent"
	NextFolderEvent              = "mediaLibrary_NextFolderEvent"
)
View Source
const (
	MediaBoxConfig      MediaBoxConfigKey = iota
	I18nMediaLibraryKey i18n.ModuleKey    = "I18nMediaLibraryKey"

	ParamName               = "name"
	ParamParentID           = "parent_id"
	ParamSelectFolderID     = "select_folder_id"
	ParamSelectIDS          = "select_ids"
	ParamField              = "field"
	ParamCurrentDescription = "current_description"
	ParamCfg                = "cfg"
)
View Source
const (
	PermUpload      = "perm_media_library_upload"
	PermDelete      = "perm_media_library_delete"
	PermUpdateDesc  = "perm_media_library_update_desc"
	PermUpdateName  = "perm_media_library_update_name"
	PermMovieTo     = "perm_media_library_move_to"
	PermCopyURL     = "perm_media_library_copy_url"
	PermNewFolder   = "perm_media_library_new_folder"
	PermListFolders = "perm_media_library_list_folders"
)

DO NOT associate media_library permissions with parent resources WRONG: permPolicy.On("*:post:*") right: permPolicy.On("*") right: permPolicy.On("*:media_libraries:*") right: permPolicy.On("*:media_libraries:1")

View Source
const ParamMediaIDS = "media_ids"

Variables

View Source
var Messages_en_US = &Messages{
	Crop:                        "Crop",
	CropImage:                   "Crop Image",
	ChooseFile:                  "Choose File",
	Delete:                      "Delete",
	ChooseAFile:                 "Choose a File",
	Search:                      "Search",
	UploadFiles:                 "Upload files",
	Cropping:                    "Cropping",
	DescriptionUpdated:          "Description Updated",
	DescriptionForAccessibility: "description for accessibility",
	OrderBy:                     "Order By",
	UploadedAt:                  "Date Uploaded",
	UploadedAtDESC:              "Date Uploaded (DESC)",
	All:                         "All",
	Images:                      "Images",
	Videos:                      "Videos",
	Files:                       "Files",

	Copy:                                  "Copy",
	CopyUpdated:                           "Copy Updated",
	Rename:                                "Rename",
	RenameUpdated:                         "Rename Updated",
	Name:                                  "Name",
	NewFolder:                             "New Folder",
	UpdateDescription:                     "Update Description",
	UpdateDescriptionTextFieldPlaceholder: "Description",
	ChooseFolder:                          "Choose Folder",
	MoveTo:                                "Move to",
	MovedFailed:                           "Moved Failed",
	MovedSuccess:                          "Moved Success",
	Folders:                               "Folders",
	UploadFile:                            "Upload File",
	DeleteObjects: func(v int) string {
		return fmt.Sprintf(`Are you sure you want to delete %v objects`, v)
	},

	MediaLibrary:      "Media Library",
	UnSupportFileType: "UnSupport FileType",
	CopyImageURL:      "copy image URL",
}
View Source
var Messages_ja_JP = &Messages{
	Crop:                        "トリミング",
	CropImage:                   "画像をトリミング",
	ChooseFile:                  "ファイルを選択",
	Delete:                      "削除",
	ChooseAFile:                 "ファイルを選択",
	Search:                      "検索",
	UploadFiles:                 "ファイルをアップロード",
	Cropping:                    "トリミング中",
	DescriptionUpdated:          "説明を更新しました",
	DescriptionForAccessibility: "画像の説明",
	OrderBy:                     "並び替え",
	UploadedAt:                  "アップロード日時",
	UploadedAtDESC:              "アップロード日時 (降順)",
	All:                         "すべて",
	Images:                      "画像",
	Videos:                      "動画",
	Files:                       "ファイル",

	Copy:                                  "コピー",
	CopyUpdated:                           "コピーが更新されました",
	Rename:                                "名前を変更する",
	RenameUpdated:                         "名前の変更が成功しました",
	Name:                                  "名称",
	NewFolder:                             "新規フォルダ",
	UpdateDescription:                     "画像の説明を編集する",
	UpdateDescriptionTextFieldPlaceholder: "画像の説明",
	ChooseFolder:                          "フォルダを選択",
	MoveTo:                                "移動する",
	MovedFailed:                           "移動に失敗しました",
	MovedSuccess:                          "移動に成功しました",
	Folders:                               "フォルダ",
	UploadFile:                            "ファイルをアップロード",
	DeleteObjects: func(v int) string {
		return fmt.Sprintf(`Are you sure you want to delete %v objects`, v)
	},
	MediaLibrary:      "メディアライブラリ",
	UnSupportFileType: "サポートされていないファイル形式",
	CopyImageURL:      "画像のURLをコピー",
}
View Source
var Messages_zh_CN = &Messages{
	Crop:                        "剪裁",
	CropImage:                   "剪裁图片",
	ChooseFile:                  "选择文件",
	Delete:                      "删除",
	ChooseAFile:                 "选择一个文件",
	Search:                      "搜索",
	UploadFiles:                 "上传多个文件",
	Cropping:                    "正在剪裁...",
	DescriptionUpdated:          "描述更新成功",
	DescriptionForAccessibility: "图片描述",
	OrderBy:                     "排序",
	UploadedAt:                  "上传时间",
	UploadedAtDESC:              "上传时间 (降序)",
	All:                         "全部",
	Images:                      "图片",
	Videos:                      "视频",
	Files:                       "文件",

	Copy:                                  "拷贝",
	CopyUpdated:                           "拷贝成功",
	Rename:                                "重命名",
	RenameUpdated:                         "重命名成功",
	Name:                                  "名称",
	NewFolder:                             "新文件夹",
	UpdateDescription:                     "更新描述",
	UpdateDescriptionTextFieldPlaceholder: "描述",
	ChooseFolder:                          "选择文件夹",
	MoveTo:                                "移动到",
	MovedFailed:                           "移动失败",
	MovedSuccess:                          "移动成功",
	Folders:                               "文件夹",
	UploadFile:                            "上传文件",
	DeleteObjects: func(v int) string {
		return fmt.Sprintf(`是否删除 %v 个条目`, v)
	},
	MediaLibrary:      "媒体库",
	UnSupportFileType: "不支持的文件类型",
	CopyImageURL:      "拷贝图片链接",
}

Functions

func AutoMigrate

func AutoMigrate(db *gorm.DB) (err error)

func ChooseFileButtonID

func ChooseFileButtonID(field string) string

func MediaBoxComponentFunc

func MediaBoxComponentFunc(db *gorm.DB, readonly bool) presets.FieldComponentFunc

func MediaBoxListFunc

func MediaBoxListFunc() presets.FieldComponentFunc

func MediaBoxSetterFunc

func MediaBoxSetterFunc(db *gorm.DB) presets.FieldSetterFunc

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func New

func New(db *gorm.DB) *Builder

func (*Builder) Activity

func (b *Builder) Activity(v *activity.Builder) *Builder

func (*Builder) AllowTypes

func (b *Builder) AllowTypes(v ...string) *Builder

func (*Builder) AutoMigrate

func (b *Builder) AutoMigrate() *Builder

func (*Builder) CurrentUserID

func (b *Builder) CurrentUserID(v UserIDFunc) *Builder

func (*Builder) FileAccept

func (b *Builder) FileAccept(v string) *Builder

func (*Builder) GetPresetsModelBuilder

func (b *Builder) GetPresetsModelBuilder() *presets.ModelBuilder

func (*Builder) Install

func (b *Builder) Install(pb *presets.Builder) error

func (*Builder) MediaLibraryPerPage

func (b *Builder) MediaLibraryPerPage(v int) *Builder

func (*Builder) Searcher

func (b *Builder) Searcher(v SearchFunc) *Builder

func (*Builder) WrapSaverFunc

func (b *Builder) WrapSaverFunc(w func(in SaverFunc) SaverFunc) (r *Builder)

type MediaBoxConfigKey

type MediaBoxConfigKey int

type Messages

type Messages struct {
	Crop                        string
	CropImage                   string
	ChooseFile                  string
	Delete                      string
	ChooseAFile                 string
	Search                      string
	UploadFiles                 string
	Cropping                    string
	DescriptionUpdated          string
	DescriptionForAccessibility string
	OrderBy                     string
	UploadedAt                  string
	UploadedAtDESC              string
	All                         string
	Images                      string
	Videos                      string
	Files                       string
	SampleArgsText              func(id string) string

	Copy                                  string
	CopyUpdated                           string
	Rename                                string
	RenameUpdated                         string
	Name                                  string
	NewFolder                             string
	UpdateDescription                     string
	UpdateDescriptionTextFieldPlaceholder string
	ChooseFolder                          string
	MoveTo                                string
	MovedFailed                           string
	MovedSuccess                          string
	Folders                               string
	UploadFile                            string
	DeleteObjects                         func(v int) string
	MediaLibrary                          string
	UnSupportFileType                     string
	CopyImageURL                          string
}

type QMediaBoxBuilder

type QMediaBoxBuilder struct {
	// contains filtered or unexported fields
}

func QMediaBox

func QMediaBox(db *gorm.DB) (r *QMediaBoxBuilder)

func SimpleMediaBox

func SimpleMediaBox(url, fieldName string, readOnly bool, cfg *media_library.MediaBoxConfig, db *gorm.DB) *QMediaBoxBuilder

func (*QMediaBoxBuilder) Config

func (*QMediaBoxBuilder) Disabled

func (b *QMediaBoxBuilder) Disabled(v bool) (r *QMediaBoxBuilder)

func (*QMediaBoxBuilder) ErrorMessages

func (b *QMediaBoxBuilder) ErrorMessages(v ...string) (r *QMediaBoxBuilder)

func (*QMediaBoxBuilder) FieldName

func (b *QMediaBoxBuilder) FieldName(v string) (r *QMediaBoxBuilder)

func (*QMediaBoxBuilder) Label

func (b *QMediaBoxBuilder) Label(v string) (r *QMediaBoxBuilder)

func (*QMediaBoxBuilder) MarshalHTML

func (b *QMediaBoxBuilder) MarshalHTML(c context.Context) (r []byte, err error)

func (*QMediaBoxBuilder) Readonly

func (b *QMediaBoxBuilder) Readonly(v bool) (r *QMediaBoxBuilder)

func (*QMediaBoxBuilder) Value

type SaverFunc

type SaverFunc func(db *gorm.DB, obj interface{}, id string, ctx *web.EventContext) error

type SearchFunc

type SearchFunc func(db *gorm.DB, ctx *web.EventContext) *gorm.DB

type UserIDFunc

type UserIDFunc func(ctx *web.EventContext) uint

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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