start work on media storage
This commit is contained in:
parent
cb67b6e2fb
commit
3964c32438
5 changed files with 64 additions and 1 deletions
|
@ -1,3 +1,24 @@
|
|||
package mediaprovider
|
||||
|
||||
import "io"
|
||||
|
||||
// TODO: Implement me
|
||||
|
||||
type FileProvider interface {
|
||||
// Return the filepath (including name) to every file in the given folder
|
||||
ListFiles(folder string) (filePaths []string)
|
||||
// Check whether a given filepath exists
|
||||
HasFile(filePath string) (ok bool)
|
||||
// Read the content of a file
|
||||
ReadFile(filePath string) (data io.Reader, err error)
|
||||
// Write the given data to a file.
|
||||
// If it exists, overwrite it
|
||||
// It it doesn't exist, create it
|
||||
WriteFile(filePath string, data io.Reader) (err error)
|
||||
// Delete a given file. If it doesn't exist, do nothing
|
||||
DeleteFile(filePath string)
|
||||
}
|
||||
|
||||
type MediaStorage struct {
|
||||
provider FileProvider
|
||||
}
|
||||
|
|
36
storage/mediaProvider/preprocessor.go
Normal file
36
storage/mediaProvider/preprocessor.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package mediaprovider
|
||||
|
||||
import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
)
|
||||
|
||||
func Compress(dataReader io.Reader, mimeType *string) (io.Reader, error) {
|
||||
data, err := io.ReadAll(dataReader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if mimeType == nil {
|
||||
*mimeType = mimetype.Detect(data).String()
|
||||
}
|
||||
uberType, subType, _ := strings.Cut(*mimeType, "/")
|
||||
var dataOut []byte
|
||||
switch uberType {
|
||||
case "text":
|
||||
case "application":
|
||||
case "image":
|
||||
case "video":
|
||||
dataOut, err = compressVideo(data, subType)
|
||||
case "audio":
|
||||
case "font":
|
||||
default:
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func compressVideo(dataIn []byte, subType string) (dataOut []byte, err error) {
|
||||
// TODO: Implement me
|
||||
panic("Implement me")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue