mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-06 11:39:42 -06:00
37 lines
876 B
Go
37 lines
876 B
Go
package core
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/shroff/phylum/server/internal/core/storage"
|
|
)
|
|
|
|
// VersionInfo represents a single version of a resource
|
|
// json tags are needed for unmarshalling the json object in sql queries
|
|
type VersionInfo struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Created int `json:"created"`
|
|
Deleted int `json:"deleted"`
|
|
Size int64 `json:"size"`
|
|
MimeType string `json:"mime_type"`
|
|
SHA256 string `json:"sha256"`
|
|
}
|
|
|
|
type Version struct {
|
|
VersionInfo
|
|
Storage string
|
|
}
|
|
|
|
func (v Version) OpenRead(start, length int) (io.ReadCloser, error) {
|
|
if v.Storage == "" {
|
|
return nil, errors.New("unknown storage backend")
|
|
}
|
|
if b := storage.GetBackend(v.Storage); b == nil {
|
|
return nil, errors.New("storage backend not found: " + v.Storage)
|
|
} else {
|
|
return b.OpenRead(v.ID, start, length)
|
|
}
|
|
}
|