media more or less working

This commit is contained in:
tsmethurst
2021-03-30 16:06:08 +02:00
parent 572149fa0e
commit 362ccf5817
12 changed files with 112 additions and 363 deletions

View File

@ -155,6 +155,9 @@ type DB interface {
// By the time this function is called, it should be assumed that all the parameters have passed validation!
NewSignup(username string, reason string, requireApproval bool, email string, password string, signUpIP net.IP, locale string, appID string) (*model.User, error)
// SetHeaderOrAvatarForAccountID sets the header or avatar for the given accountID to the given media attachment.
SetHeaderOrAvatarForAccountID(mediaAttachmen *model.MediaAttachment, accountID string) error
/*
USEFUL CONVERSION FUNCTIONS
*/

View File

@ -50,9 +50,9 @@ type MediaAttachment struct {
// What is the processing status of this attachment
Processing ProcessingStatus
// metadata for the whole file
File
File File
// small image thumbnail derived from a larger image, video, or audio file.
Thumbnail
Thumbnail Thumbnail
// Is this attachment being used as an avatar?
Avatar bool
// Is this attachment being used as a header?
@ -68,7 +68,7 @@ type File struct {
// What is the size of the file in bytes.
FileSize int
// When was the file last updated.
UpdatedAt time.Time `pg:"type:timestamp,default:now()"`
UpdatedAt time.Time `pg:"type:timestamp,notnull,default:now()"`
}
// Thumbnail refers to a small image thumbnail derived from a larger image, video, or audio file.
@ -80,7 +80,7 @@ type Thumbnail struct {
// What is the size of the file in bytes
FileSize int
// When was the file last updated
UpdatedAt time.Time `pg:"type:timestamp,default:now()"`
UpdatedAt time.Time `pg:"type:timestamp,notnull,default:now()"`
// What is the remote URL of the thumbnail
RemoteURL string
}
@ -113,50 +113,12 @@ const (
FileTypeVideo FileType = "video"
)
/*
FILEMETA INTERFACES
*/
// FileMeta describes metadata about the actual contents of the file.
type FileMeta interface {
GetOriginal() OriginalMeta
GetSmall() SmallMeta
type FileMeta struct {
Original Original
Small Small
}
// OriginalMeta contains info about the originally submitted media
type OriginalMeta interface {
// GetWidth gets the width of a video or image or gif in pixels.
GetWidth() int
// GetHeight gets the height of a video or image or gif in pixels.
GetHeight() int
// GetSize gets the total area of a video or image or gif in pixels (width * height).
GetSize() int
// GetAspect gets the aspect ratio of a video or image or gif in pixels (width / height).
GetAspect() float64
// GetFrameRate gets the FPS of a video or gif.
GetFrameRate() float64
// GetDuration gets the length in seconds of a video or gif or audio file.
GetDuration() float64
// GetBitrate gets the bits per second of a video, gif, or audio file.
GetBitrate() float64
}
// SmallMeta contains info about the derived thumbnail for the submitted media
type SmallMeta interface {
// GetWidth gets the width of a video or image or gif in pixels.
GetWidth() int
// GetHeight gets the height of a video or image or gif in pixels.
GetHeight() int
// GetSize gets the total area of a video or image or gif in pixels (width * height).
GetSize() int
// GetAspect gets the aspect ratio of a video or image or gif in pixels (width / height).
GetAspect() float64
}
/*
FILE META IMPLEMENTATIONS
*/
// Small implements SmallMeta and can be used for a thumbnail of any media type
type Small struct {
Width int
@ -165,70 +127,10 @@ type Small struct {
Aspect float64
}
func (s Small) GetWidth() int {
return s.Width
}
func (s Small) GetHeight() int {
return s.Height
}
func (s Small) GetSize() int {
return s.Height * s.Width
}
func (s Small) GetAspect() float64 {
return float64(s.Width) / float64(s.Height)
}
// STILL IMAGES
// ImageFileMeta implements FileMeta for still images.
type ImageFileMeta struct {
Original ImageOriginal
Small Small
}
func (m ImageFileMeta) GetOriginal() OriginalMeta {
return m.Original
}
func (m ImageFileMeta) GetSmall() SmallMeta {
return m.Small
}
// ImageOriginal implements OriginalMeta for still images
type ImageOriginal struct {
type Original struct {
Width int
Height int
Size int
Aspect float64
}
func (o ImageOriginal) GetWidth() int {
return o.Width
}
func (o ImageOriginal) GetHeight() int {
return o.Height
}
func (o ImageOriginal) GetSize() int {
return o.Height * o.Width
}
func (o ImageOriginal) GetAspect() float64 {
return float64(o.Width) / float64(o.Height)
}
func (o ImageOriginal) GetFrameRate() float64 {
return 0
}
func (o ImageOriginal) GetDuration() float64 {
return 0
}
func (o ImageOriginal) GetBitrate() float64 {
return 0
}

View File

@ -1,42 +0,0 @@
// Code generated by mockery v2.7.4. DO NOT EDIT.
package model
import mock "github.com/stretchr/testify/mock"
// MockFileMeta is an autogenerated mock type for the FileMeta type
type MockFileMeta struct {
mock.Mock
}
// GetOriginal provides a mock function with given fields:
func (_m *MockFileMeta) GetOriginal() OriginalMeta {
ret := _m.Called()
var r0 OriginalMeta
if rf, ok := ret.Get(0).(func() OriginalMeta); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(OriginalMeta)
}
}
return r0
}
// GetSmall provides a mock function with given fields:
func (_m *MockFileMeta) GetSmall() SmallMeta {
ret := _m.Called()
var r0 SmallMeta
if rf, ok := ret.Get(0).(func() SmallMeta); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(SmallMeta)
}
}
return r0
}

View File

@ -1,108 +0,0 @@
// Code generated by mockery v2.7.4. DO NOT EDIT.
package model
import mock "github.com/stretchr/testify/mock"
// MockOriginalMeta is an autogenerated mock type for the OriginalMeta type
type MockOriginalMeta struct {
mock.Mock
}
// GetAspect provides a mock function with given fields:
func (_m *MockOriginalMeta) GetAspect() float64 {
ret := _m.Called()
var r0 float64
if rf, ok := ret.Get(0).(func() float64); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(float64)
}
return r0
}
// GetBitrate provides a mock function with given fields:
func (_m *MockOriginalMeta) GetBitrate() float64 {
ret := _m.Called()
var r0 float64
if rf, ok := ret.Get(0).(func() float64); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(float64)
}
return r0
}
// GetDuration provides a mock function with given fields:
func (_m *MockOriginalMeta) GetDuration() float64 {
ret := _m.Called()
var r0 float64
if rf, ok := ret.Get(0).(func() float64); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(float64)
}
return r0
}
// GetFrameRate provides a mock function with given fields:
func (_m *MockOriginalMeta) GetFrameRate() float64 {
ret := _m.Called()
var r0 float64
if rf, ok := ret.Get(0).(func() float64); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(float64)
}
return r0
}
// GetHeight provides a mock function with given fields:
func (_m *MockOriginalMeta) GetHeight() int {
ret := _m.Called()
var r0 int
if rf, ok := ret.Get(0).(func() int); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(int)
}
return r0
}
// GetSize provides a mock function with given fields:
func (_m *MockOriginalMeta) GetSize() int {
ret := _m.Called()
var r0 int
if rf, ok := ret.Get(0).(func() int); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(int)
}
return r0
}
// GetWidth provides a mock function with given fields:
func (_m *MockOriginalMeta) GetWidth() int {
ret := _m.Called()
var r0 int
if rf, ok := ret.Get(0).(func() int); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(int)
}
return r0
}

View File

@ -1,66 +0,0 @@
// Code generated by mockery v2.7.4. DO NOT EDIT.
package model
import mock "github.com/stretchr/testify/mock"
// MockSmallMeta is an autogenerated mock type for the SmallMeta type
type MockSmallMeta struct {
mock.Mock
}
// GetAspect provides a mock function with given fields:
func (_m *MockSmallMeta) GetAspect() float64 {
ret := _m.Called()
var r0 float64
if rf, ok := ret.Get(0).(func() float64); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(float64)
}
return r0
}
// GetHeight provides a mock function with given fields:
func (_m *MockSmallMeta) GetHeight() int {
ret := _m.Called()
var r0 int
if rf, ok := ret.Get(0).(func() int); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(int)
}
return r0
}
// GetSize provides a mock function with given fields:
func (_m *MockSmallMeta) GetSize() int {
ret := _m.Called()
var r0 int
if rf, ok := ret.Get(0).(func() int); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(int)
}
return r0
}
// GetWidth provides a mock function with given fields:
func (_m *MockSmallMeta) GetWidth() int {
ret := _m.Called()
var r0 int
if rf, ok := ret.Get(0).(func() int); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(int)
}
return r0
}

View File

@ -463,6 +463,11 @@ func (ps *postgresService) NewSignup(username string, reason string, requireAppr
return u, nil
}
func (ps *postgresService) SetHeaderOrAvatarForAccountID(mediaAttachment *model.MediaAttachment, accountID string) error {
_, err := ps.conn.Model(mediaAttachment).Insert()
return err
}
/*
CONVERSION FUNCTIONS
*/