|
@ -4,6 +4,7 @@ import ( |
|
|
"context" |
|
|
"context" |
|
|
"crypto/rand" |
|
|
"crypto/rand" |
|
|
"encoding/binary" |
|
|
"encoding/binary" |
|
|
|
|
|
"errors" |
|
|
"io" |
|
|
"io" |
|
|
"strconv" |
|
|
"strconv" |
|
|
"time" |
|
|
"time" |
|
@ -125,12 +126,13 @@ func FindID(id string) (File, error) { |
|
|
return file, nil |
|
|
return file, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// ListFiles lists files according to the standard lookup. By default it's just the author's own files,
|
|
|
|
|
|
|
|
|
// List lists files according to the standard lookup. By default it's just the author's own files,
|
|
|
// but if `public` is true it will alos include files made public by other authors. If `mimeTypes` contains
|
|
|
// but if `public` is true it will alos include files made public by other authors. If `mimeTypes` contains
|
|
|
// any, it will limit the results to that.
|
|
|
|
|
|
func ListFiles(author string, public bool, mimeTypes []string) ([]File, error) { |
|
|
|
|
|
|
|
|
// any, it will limit the results to that. If `author` is empty, it will only list public files
|
|
|
|
|
|
func List(author string, public bool, mimeTypes []string) ([]File, error) { |
|
|
query := bson.M{} |
|
|
query := bson.M{} |
|
|
|
|
|
|
|
|
|
|
|
if author != "" { |
|
|
if public { |
|
|
if public { |
|
|
query["$or"] = []bson.M{ |
|
|
query["$or"] = []bson.M{ |
|
|
bson.M{"author": author}, |
|
|
bson.M{"author": author}, |
|
@ -139,6 +141,13 @@ func ListFiles(author string, public bool, mimeTypes []string) ([]File, error) { |
|
|
} else { |
|
|
} else { |
|
|
query["author"] = author |
|
|
query["author"] = author |
|
|
} |
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
if !public { |
|
|
|
|
|
return nil, errors.New("No author specified, and public is unset") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
query["public"] = true |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if len(mimeTypes) > 0 { |
|
|
if len(mimeTypes) > 0 { |
|
|
query["mimeTypes"] = bson.M{"$in": mimeTypes} |
|
|
query["mimeTypes"] = bson.M{"$in": mimeTypes} |
|
@ -183,5 +192,8 @@ func init() { |
|
|
fileCollection = db.C("file.headers") |
|
|
fileCollection = db.C("file.headers") |
|
|
|
|
|
|
|
|
fileCollection.EnsureIndexKey("author") |
|
|
fileCollection.EnsureIndexKey("author") |
|
|
|
|
|
fileCollection.EnsureIndexKey("public") |
|
|
|
|
|
fileCollection.EnsureIndexKey("author", "public") |
|
|
|
|
|
fileCollection.EnsureIndexKey("kind") |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |