[server] Extend ObjectType instead of creating new enum

This commit is contained in:
Neeraj Gupta
2024-07-30 10:30:57 +05:30
parent dc143bbaaf
commit 3a962cfe52
3 changed files with 6 additions and 51 deletions

View File

@@ -153,8 +153,11 @@ type MultipartUploadURLs struct {
type ObjectType string
const (
FILE ObjectType = "file"
THUMBNAIL ObjectType = "thumbnail"
FILE ObjectType = "file"
THUMBNAIL ObjectType = "thumbnail"
PreviewImage ObjectType = "img_preview"
PreviewVideo ObjectType = "vid_preview"
DerivedMeta ObjectType = "derivedMeta"
)
// S3ObjectKey represents the s3 object key and corresponding fileID for it

View File

@@ -1,45 +0,0 @@
package fileobjects
import (
"database/sql/driver"
"errors"
"fmt"
)
type Type string
const (
OriginalFile Type = "file"
OriginalThumbnail Type = "thumb"
PreviewImage Type = "previewImage"
PreviewVideo Type = "previewVideo"
Derived Type = "derived"
)
func (ft Type) IsValid() bool {
switch ft {
case OriginalFile, OriginalThumbnail, PreviewImage, PreviewVideo, Derived:
return true
}
return false
}
func (ft *Type) Scan(value interface{}) error {
strValue, ok := value.(string)
if !ok {
return errors.New("type should be a string")
}
*ft = Type(strValue)
if !ft.IsValid() {
return fmt.Errorf("invalid FileType value: %s", strValue)
}
return nil
}
func (ft Type) Value() (driver.Value, error) {
if !ft.IsValid() {
return nil, fmt.Errorf("invalid FileType value: %s", ft)
}
return string(ft), nil
}

View File

@@ -1,11 +1,8 @@
-- Create the data_type enum
CREATE TYPE file_data_type AS ENUM ('img_jpg_preview', 'vid_hls_preview', 'derived');
-- Create the derived table
CREATE TABLE file_data (
file_id BIGINT NOT NULL,
user_id BIGINT NOT NULL,
data_type file_data_type NOT NULL,
data_type OBJECT_TYPE NOT NULL,
size BIGINT NOT NULL,
latest_bucket s3region NOT NULL,
replicated_buckets s3region[] NOT NULL,