now images are lower cased, and searching for names is insensitive.

for your mongo db set, run:
db.fs.files.find().forEach(
  function(e) {
    e.filename = e.filename.toLowerCase();
    db.fs.files.save(e);
  }
)
This commit is contained in:
Vincent Batts 2013-08-06 10:37:58 -04:00
parent 80e9381754
commit 5eab319c6c
4 changed files with 33 additions and 25 deletions

View File

@ -65,7 +65,7 @@ func (u Util) HasFileByKeyword(keyword string) (exists bool, err error) {
/*
get a list of keywords and their frequency count
*/
func (u Util) GetKeywords() (kp []types.KeywordCount, err error) {
func (u Util) GetKeywords() (kp []types.IdCount, err error) {
job := &mgo.MapReduce{
Map: `
function() {

View File

@ -51,7 +51,6 @@ var navbarTemplateHTML = `
<li><a href="/k/">Keywords</a></li>
<li><a href="/ext/">File ext</a></li>
<li><a href="/md5/">MD5s</a></li>
<li><a href="/ip/">IPs</a></li>
</ul>
</div> <!-- dropdown -->
</div> <!-- nav-collapse -->
@ -178,7 +177,7 @@ var listTemplateHTML = `
var tagcloudTemplate = template.Must(template.New("tagcloud").Parse(tagcloudTemplateHTML))
var tagcloudTemplateHTML = `
{{if .}}
<div id="keywordTagCloud">
<div id="tagCloud">
{{range .}}
<a href="/k/{{.Id}}" rel="{{.Value}}">{{.Id}}</a>
{{end}}
@ -393,7 +392,7 @@ func ListFilesPage(w io.Writer, files []types.File) (err error) {
return
}
func ListKeywordsPage(w io.Writer, kc []types.KeywordCount) (err error) {
func ListTagCloudPage(w io.Writer, ic []types.IdCount) (err error) {
err = headTemplate.Execute(w, map[string]string{"title": "FileSrv"})
if err != nil {
return err
@ -408,7 +407,7 @@ func ListKeywordsPage(w io.Writer, kc []types.KeywordCount) (err error) {
}
// main context of this page
err = tagcloudTemplate.Execute(w, kc)
err = tagcloudTemplate.Execute(w, ic)
if err != nil {
return err
}

View File

@ -52,9 +52,9 @@ func runServer(c *config.Config) {
http.HandleFunc("/f/", routeFiles)
http.HandleFunc("/v/", routeViews)
http.HandleFunc("/k/", routeKeywords)
http.HandleFunc("/ip/", routeIPs)
http.HandleFunc("/ext/", routeExt)
http.HandleFunc("/md5/", routeMD5s)
http.HandleFunc("/ext/", routeExt)
http.HandleFunc("/ip/", routeIPs)
addr := fmt.Sprintf("%s:%s", c.Ip, c.Port)
log.Printf("Serving on %s ...", addr)
@ -119,7 +119,7 @@ func routeViewsGET(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
if len(uriChunks) == 2 && len(uriChunks[1]) > 0 {
var file types.File
err := gfs.Find(bson.M{"filename": uriChunks[1]}).One(&file)
err := gfs.Find(bson.M{"filename": strings.ToLower(uriChunks[1])}).One(&file)
if err != nil {
serverErr(w, r, err)
return
@ -157,6 +157,8 @@ func routeFilesGET(w http.ResponseWriter, r *http.Request) {
return
}
filename := strings.ToLower(uriChunks[1])
// if the Request got here by a delete request, confirm it
if (len(r.Form["delete"]) > 0 && r.Form["delete"][0] == "true") && (len(r.Form["confirm"]) > 0 && r.Form["confirm"][0] == "true") {
httplog.LogRequest(r, 200)
@ -164,7 +166,7 @@ func routeFilesGET(w http.ResponseWriter, r *http.Request) {
return
} else if len(r.Form["delete"]) > 0 && r.Form["delete"][0] == "true" {
httplog.LogRequest(r, 200)
err = DeleteFilePage(w, uriChunks[1])
err = DeleteFilePage(w, filename)
if err != nil {
serverErr(w, r, err)
return
@ -172,9 +174,9 @@ func routeFilesGET(w http.ResponseWriter, r *http.Request) {
return
}
if len(uriChunks) == 2 && len(uriChunks[1]) > 0 {
log.Printf("Searching for [%s] ...", uriChunks[1])
query := gfs.Find(bson.M{"filename": uriChunks[1]})
if len(uriChunks) == 2 && len(filename) > 0 {
log.Printf("Searching for [%s] ...", filename)
query := gfs.Find(bson.M{"filename": filename})
c, err := query.Count()
// preliminary checks, if they've passed an image name
@ -182,19 +184,19 @@ func routeFilesGET(w http.ResponseWriter, r *http.Request) {
serverErr(w, r, err)
return
}
log.Printf("Results for [%s] = %d", uriChunks[1], c)
log.Printf("Results for [%s] = %d", filename, c)
if c == 0 {
httplog.LogRequest(r, 404)
http.NotFound(w, r)
return
}
ext := filepath.Ext(uriChunks[1])
ext := filepath.Ext(filename)
w.Header().Set("Content-Type", mime.TypeByExtension(ext))
w.Header().Set("Cache-Control", "max-age=315360000")
w.WriteHeader(http.StatusOK)
file, err := gfs.Open(uriChunks[1])
file, err := gfs.Open(filename)
if err != nil {
serverErr(w, r, err)
return
@ -233,7 +235,7 @@ func routeFilesPOST(w http.ResponseWriter, r *http.Request) {
filename = r.FormValue("filename")
if len(filename) == 0 && len(uriChunks) == 2 && len(uriChunks[1]) != 0 {
filename = uriChunks[1]
filename = strings.ToLower(uriChunks[1])
}
log.Printf("%s\n", filename)
@ -462,7 +464,7 @@ func routeKeywords(w http.ResponseWriter, r *http.Request) {
serverErr(w, r, err)
return
}
err = ListKeywordsPage(w, kc)
err = ListTagCloudPage(w, kc)
if err != nil {
serverErr(w, r, err)
}
@ -506,8 +508,16 @@ func routeMD5s(w http.ResponseWriter, r *http.Request) {
http.NotFound(w, r)
return
} else if len(uriChunks) != 2 {
// they didn't give an MD5, re-route
routeRoot(w, r)
// Path: /md5/
kc, err := du.GetKeywords()
if err != nil {
serverErr(w, r, err)
return
}
err = ListTagCloudPage(w, kc)
if err != nil {
serverErr(w, r, err)
}
return
}
@ -604,7 +614,7 @@ func routeGetFromUrl(w http.ResponseWriter, r *http.Request) {
log.Printf("WARN: not sure what to do with param [%s = %s]", k, v)
}
}
exists, err := du.HasFileByFilename(filepath.Base(local_filename))
exists, err := du.HasFileByFilename(filepath.Base(strings.ToLower(local_filename)))
if err != nil {
serverErr(w, r, err)
return
@ -618,7 +628,7 @@ func routeGetFromUrl(w http.ResponseWriter, r *http.Request) {
stored_filename = filepath.Base(local_filename)
}
file, err := gfs.Create(stored_filename)
file, err := gfs.Create(strings.ToLower(stored_filename))
defer file.Close()
if err != nil {
serverErr(w, r, err)

View File

@ -44,10 +44,9 @@ func (f *File) IsAudio() bool {
}
/*
Structure used for collecting the keyword usage for the tag cloud
Structure used for collecting values from mongo for a tag cloud
*/
type KeywordCount struct {
Id string "_id"
type IdCount struct {
Id string "_id"
Value int
}