2020-10-12 23:12:46 +00:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2021-05-03 03:09:46 +00:00
|
|
|
"path/filepath"
|
2020-10-12 23:12:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Image stores the metadata for a single image.
|
|
|
|
type Image struct {
|
2020-11-04 23:26:51 +00:00
|
|
|
ID int `db:"id" json:"id"`
|
|
|
|
Checksum string `db:"checksum" json:"checksum"`
|
|
|
|
Path string `db:"path" json:"path"`
|
|
|
|
Title sql.NullString `db:"title" json:"title"`
|
|
|
|
Rating sql.NullInt64 `db:"rating" json:"rating"`
|
2020-12-17 21:06:49 +00:00
|
|
|
Organized bool `db:"organized" json:"organized"`
|
2020-11-04 23:26:51 +00:00
|
|
|
OCounter int `db:"o_counter" json:"o_counter"`
|
|
|
|
Size sql.NullInt64 `db:"size" json:"size"`
|
|
|
|
Width sql.NullInt64 `db:"width" json:"width"`
|
|
|
|
Height sql.NullInt64 `db:"height" json:"height"`
|
|
|
|
StudioID sql.NullInt64 `db:"studio_id,omitempty" json:"studio_id"`
|
|
|
|
FileModTime NullSQLiteTimestamp `db:"file_mod_time" json:"file_mod_time"`
|
|
|
|
CreatedAt SQLiteTimestamp `db:"created_at" json:"created_at"`
|
|
|
|
UpdatedAt SQLiteTimestamp `db:"updated_at" json:"updated_at"`
|
2020-10-12 23:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImagePartial represents part of a Image object. It is used to update
|
|
|
|
// the database entry. Only non-nil fields will be updated.
|
|
|
|
type ImagePartial struct {
|
2020-11-04 23:26:51 +00:00
|
|
|
ID int `db:"id" json:"id"`
|
|
|
|
Checksum *string `db:"checksum" json:"checksum"`
|
|
|
|
Path *string `db:"path" json:"path"`
|
|
|
|
Title *sql.NullString `db:"title" json:"title"`
|
|
|
|
Rating *sql.NullInt64 `db:"rating" json:"rating"`
|
2020-12-17 21:06:49 +00:00
|
|
|
Organized *bool `db:"organized" json:"organized"`
|
2020-11-04 23:26:51 +00:00
|
|
|
Size *sql.NullInt64 `db:"size" json:"size"`
|
|
|
|
Width *sql.NullInt64 `db:"width" json:"width"`
|
|
|
|
Height *sql.NullInt64 `db:"height" json:"height"`
|
|
|
|
StudioID *sql.NullInt64 `db:"studio_id,omitempty" json:"studio_id"`
|
|
|
|
FileModTime *NullSQLiteTimestamp `db:"file_mod_time" json:"file_mod_time"`
|
|
|
|
CreatedAt *SQLiteTimestamp `db:"created_at" json:"created_at"`
|
|
|
|
UpdatedAt *SQLiteTimestamp `db:"updated_at" json:"updated_at"`
|
2020-10-12 23:12:46 +00:00
|
|
|
}
|
|
|
|
|
2021-05-03 03:09:46 +00:00
|
|
|
// GetTitle returns the title of the image. If the Title field is empty,
|
|
|
|
// then the base filename is returned.
|
|
|
|
func (s Image) GetTitle() string {
|
|
|
|
if s.Title.String != "" {
|
|
|
|
return s.Title.String
|
|
|
|
}
|
|
|
|
|
|
|
|
return filepath.Base(s.Path)
|
|
|
|
}
|
|
|
|
|
2020-10-12 23:12:46 +00:00
|
|
|
// ImageFileType represents the file metadata for an image.
|
|
|
|
type ImageFileType struct {
|
|
|
|
Size *int `graphql:"size" json:"size"`
|
|
|
|
Width *int `graphql:"width" json:"width"`
|
|
|
|
Height *int `graphql:"height" json:"height"`
|
|
|
|
}
|
2021-01-18 01:23:20 +00:00
|
|
|
|
|
|
|
type Images []*Image
|
|
|
|
|
|
|
|
func (i *Images) Append(o interface{}) {
|
|
|
|
*i = append(*i, o.(*Image))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Images) New() interface{} {
|
|
|
|
return &Image{}
|
|
|
|
}
|