mirror of
https://github.com/rclone/rclone.git
synced 2025-12-28 22:23:41 +00:00
http: add basic metadata and provide it via serve
Co-authored-by: dougal <147946567+roucc@users.noreply.github.com>
This commit is contained in:
@@ -191,11 +191,12 @@ var _ fs.Fs = MemoryFs
|
||||
|
||||
// MemoryObject is an in memory object
|
||||
type MemoryObject struct {
|
||||
remote string
|
||||
modTime time.Time
|
||||
content []byte
|
||||
meta fs.Metadata
|
||||
fs fs.Fs
|
||||
remote string
|
||||
modTime time.Time
|
||||
content []byte
|
||||
meta fs.Metadata
|
||||
fs fs.Fs
|
||||
mimeType string
|
||||
}
|
||||
|
||||
// NewMemoryObject returns an in memory Object with the modTime and content passed in
|
||||
@@ -214,6 +215,12 @@ func (o *MemoryObject) WithMetadata(meta fs.Metadata) *MemoryObject {
|
||||
return o
|
||||
}
|
||||
|
||||
// WithMimeType adds mimeType to the MemoryObject
|
||||
func (o *MemoryObject) WithMimeType(mimeType string) *MemoryObject {
|
||||
o.mimeType = mimeType
|
||||
return o
|
||||
}
|
||||
|
||||
// Content returns the underlying buffer
|
||||
func (o *MemoryObject) Content() []byte {
|
||||
return o.content
|
||||
@@ -329,8 +336,14 @@ func (o *MemoryObject) Metadata(ctx context.Context) (fs.Metadata, error) {
|
||||
return o.meta, nil
|
||||
}
|
||||
|
||||
// MimeType on the object
|
||||
func (o *MemoryObject) MimeType(ctx context.Context) string {
|
||||
return o.mimeType
|
||||
}
|
||||
|
||||
// Check interfaces
|
||||
var (
|
||||
_ fs.Object = (*MemoryObject)(nil)
|
||||
_ fs.MimeTyper = (*MemoryObject)(nil)
|
||||
_ fs.Metadataer = (*MemoryObject)(nil)
|
||||
)
|
||||
|
||||
@@ -87,6 +87,7 @@ func TestMemoryObject(t *testing.T) {
|
||||
content = content[:6] // make some extra cap
|
||||
|
||||
o := object.NewMemoryObject(remote, now, content)
|
||||
o.WithMimeType("text/plain; charset=utf-8")
|
||||
|
||||
assert.Equal(t, content, o.Content())
|
||||
assert.Equal(t, object.MemoryFs, o.Fs())
|
||||
@@ -95,6 +96,7 @@ func TestMemoryObject(t *testing.T) {
|
||||
assert.Equal(t, now, o.ModTime(context.Background()))
|
||||
assert.Equal(t, int64(len(content)), o.Size())
|
||||
assert.Equal(t, true, o.Storable())
|
||||
assert.Equal(t, "text/plain; charset=utf-8", o.MimeType(context.Background()))
|
||||
|
||||
Hash, err := o.Hash(context.Background(), hash.MD5)
|
||||
assert.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user