mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-04-29 00:30:09 -05:00
[server] Fix build
This commit is contained in:
@@ -95,7 +95,7 @@ func serveCollection(w http.ResponseWriter, r *http.Request, file fs.Resource) {
|
||||
fmt.Fprintln(w, "</body></html>")
|
||||
}
|
||||
|
||||
func formatSize(size int64) string {
|
||||
func formatSize(size int) string {
|
||||
suffix := []string{"", "K", "M", "G", "T"}
|
||||
si := 0
|
||||
for ; size >= 1000 && si < len(suffix); si, size = si+1, size/1000 {
|
||||
@@ -154,26 +154,26 @@ func serveResource(w http.ResponseWriter, r *http.Request, file fs.Resource) {
|
||||
}
|
||||
|
||||
w.Header().Set("Accept-Ranges", "bytes")
|
||||
w.Header().Set("Content-Length", strconv.FormatInt(sendSize, 10))
|
||||
w.Header().Set("Content-Length", strconv.Itoa(sendSize))
|
||||
w.WriteHeader(code)
|
||||
|
||||
if r.Method != "HEAD" {
|
||||
io.CopyN(w, reader, sendSize)
|
||||
io.CopyN(w, reader, int64(sendSize))
|
||||
}
|
||||
}
|
||||
|
||||
// httpRange specifies the byte range to be sent to the client.
|
||||
type httpRange struct {
|
||||
start, length int64
|
||||
start, length int
|
||||
}
|
||||
|
||||
func (r httpRange) contentRange(size int64) string {
|
||||
func (r httpRange) contentRange(size int) string {
|
||||
return fmt.Sprintf("bytes %d-%d/%d", r.start, r.start+r.length-1, size)
|
||||
}
|
||||
|
||||
// parseRange parses a Range header string as per RFC 7233.
|
||||
// errNoOverlap is returned if none of the ranges overlap.
|
||||
func parseRange(s string, size int64) ([]httpRange, error) {
|
||||
func parseRange(s string, size int) ([]httpRange, error) {
|
||||
if s == "" {
|
||||
return nil, nil // header not present
|
||||
}
|
||||
@@ -203,7 +203,7 @@ func parseRange(s string, size int64) ([]httpRange, error) {
|
||||
if end == "" || end[0] == '-' {
|
||||
return nil, errors.New("invalid range")
|
||||
}
|
||||
i, err := strconv.ParseInt(end, 10, 64)
|
||||
i, err := strconv.Atoi(end)
|
||||
if i < 0 || err != nil {
|
||||
return nil, errors.New("invalid range")
|
||||
}
|
||||
@@ -213,7 +213,7 @@ func parseRange(s string, size int64) ([]httpRange, error) {
|
||||
r.start = size - i
|
||||
r.length = size - r.start
|
||||
} else {
|
||||
i, err := strconv.ParseInt(start, 10, 64)
|
||||
i, err := strconv.Atoi(start)
|
||||
if err != nil || i < 0 {
|
||||
return nil, errors.New("invalid range")
|
||||
}
|
||||
@@ -228,7 +228,7 @@ func parseRange(s string, size int64) ([]httpRange, error) {
|
||||
// If no end is specified, range extends to end of the file.
|
||||
r.length = size - r.start
|
||||
} else {
|
||||
i, err := strconv.ParseInt(end, 10, 64)
|
||||
i, err := strconv.Atoi(end)
|
||||
if err != nil || r.start > i {
|
||||
return nil, errors.New("invalid range")
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
func (r Resource) OpenRead(start, length int64) (io.ReadCloser, error) {
|
||||
func (r Resource) OpenRead(start, length int) (io.ReadCloser, error) {
|
||||
if !r.hasPermission(PermissionRead) {
|
||||
return nil, ErrInsufficientPermissions
|
||||
}
|
||||
|
||||
@@ -30,12 +30,12 @@ func (l localStorage) Name() string {
|
||||
return l.name
|
||||
}
|
||||
|
||||
func (l localStorage) OpenRead(id uuid.UUID, start, length int64) (io.ReadCloser, error) {
|
||||
func (l localStorage) OpenRead(id uuid.UUID, start, length int) (io.ReadCloser, error) {
|
||||
file, err := os.OpenFile(l.path(id), os.O_RDONLY, 0640)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = file.Seek(start, io.SeekStart)
|
||||
_, err = file.Seek(int64(start), io.SeekStart)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ func (s minioStorage) Name() string {
|
||||
return s.name
|
||||
}
|
||||
|
||||
func (s minioStorage) OpenRead(id uuid.UUID, start, length int64) (io.ReadCloser, error) {
|
||||
func (s minioStorage) OpenRead(id uuid.UUID, start, length int) (io.ReadCloser, error) {
|
||||
// TODO: Range
|
||||
if r, err := s.client.GetObject(context.Background(), s.bucketName, s.prefix+id.String(), minio.GetObjectOptions{}); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
type Storage interface {
|
||||
CreateBackend(ctx context.Context, name string, driver string, params map[string]string) error
|
||||
ListBackends() map[string]Backend
|
||||
OpenRead(id uuid.UUID, start, length int64) (io.ReadCloser, error)
|
||||
OpenRead(id uuid.UUID, start, length int) (io.ReadCloser, error)
|
||||
OpenWrite(id uuid.UUID, h func() hash.Hash, callback func(int, string, string) error) (io.WriteCloser, error)
|
||||
CopyContents(src, dest uuid.UUID) error
|
||||
Delete(id uuid.UUID) error
|
||||
@@ -58,7 +58,7 @@ func create(ctx context.Context, db *db.DbHandler, defaultStorageDir string) (St
|
||||
}
|
||||
}
|
||||
|
||||
func (s storage) OpenRead(id uuid.UUID, start, length int64) (io.ReadCloser, error) {
|
||||
func (s storage) OpenRead(id uuid.UUID, start, length int) (io.ReadCloser, error) {
|
||||
if backend, err := s.findStorageBackend(id); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
type Backend interface {
|
||||
Name() string
|
||||
OpenRead(id uuid.UUID, start, length int64) (io.ReadCloser, error)
|
||||
OpenRead(id uuid.UUID, start, length int) (io.ReadCloser, error)
|
||||
OpenWrite(id uuid.UUID) (io.WriteCloser, error)
|
||||
Delete(id uuid.UUID) error
|
||||
DeleteAll(ids uuid.UUIDs) []error
|
||||
|
||||
Reference in New Issue
Block a user