Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 package main | 1 package main |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 "bytes" | 4 "bytes" |
| 5 "crypto/md5" | 5 "crypto/md5" |
| 6 "database/sql" | 6 "database/sql" |
| 7 "encoding/base64" | 7 "encoding/base64" |
| 8 "encoding/json" | 8 "encoding/json" |
| 9 "flag" | 9 "flag" |
| 10 "fmt" | 10 "fmt" |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 match := imageLink.FindStringSubmatch(r.URL.Path) | 339 match := imageLink.FindStringSubmatch(r.URL.Path) |
| 340 if len(match) != 2 { | 340 if len(match) != 2 { |
| 341 http.NotFound(w, r) | 341 http.NotFound(w, r) |
| 342 return | 342 return |
| 343 } | 343 } |
| 344 filename := match[1] | 344 filename := match[1] |
| 345 http.ServeFile(w, r, fmt.Sprintf("../../../inout/%s", filename)) | 345 http.ServeFile(w, r, fmt.Sprintf("../../../inout/%s", filename)) |
| 346 } | 346 } |
| 347 | 347 |
| 348 type Try struct { | 348 type Try struct { |
| 349 » Hash string | 349 » Hash string `json:"hash"` |
| 350 » CreateTS string | 350 » CreateTS string `json:"create_ts"` |
| 351 } | 351 } |
| 352 | 352 |
| 353 type Recent struct { | 353 type Recent struct { |
| 354 Tries []Try | 354 Tries []Try |
| 355 } | 355 } |
| 356 | 356 |
| 357 // recentHandler shows the last 20 tries. | 357 // recentHandler shows the last 20 tries. |
| 358 func recentHandler(w http.ResponseWriter, r *http.Request) { | 358 func recentHandler(w http.ResponseWriter, r *http.Request) { |
| 359 log.Printf("Recent Handler: %q\n", r.URL.Path) | 359 log.Printf("Recent Handler: %q\n", r.URL.Path) |
| 360 | 360 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 } | 411 } |
| 412 | 412 |
| 413 func workspaceHandler(w http.ResponseWriter, r *http.Request) { | 413 func workspaceHandler(w http.ResponseWriter, r *http.Request) { |
| 414 log.Printf("Workspace Handler: %q\n", r.URL.Path) | 414 log.Printf("Workspace Handler: %q\n", r.URL.Path) |
| 415 if r.Method == "GET" { | 415 if r.Method == "GET" { |
| 416 tries := []Try{} | 416 tries := []Try{} |
| 417 match := workspaceLink.FindStringSubmatch(r.URL.Path) | 417 match := workspaceLink.FindStringSubmatch(r.URL.Path) |
| 418 name := "" | 418 name := "" |
| 419 if len(match) == 2 { | 419 if len(match) == 2 { |
| 420 name = match[1] | 420 name = match[1] |
| 421 » » » rows, err := db.Query("SELECT create_ts, hash FROM works pacetry WHERE name=? ORDER BY create_ts DESC ", name) | 421 » » » rows, err := db.Query("SELECT create_ts, hash FROM works pacetry WHERE name=? ORDER BY create_ts", name) |
| 422 if err != nil { | 422 if err != nil { |
| 423 reportError(w, r, err, "Failed to select.") | 423 reportError(w, r, err, "Failed to select.") |
| 424 return | 424 return |
| 425 } | 425 } |
| 426 for rows.Next() { | 426 for rows.Next() { |
| 427 var hash string | 427 var hash string |
| 428 var create_ts time.Time | 428 var create_ts time.Time |
| 429 if err := rows.Scan(&create_ts, &hash); err != n il { | 429 if err := rows.Scan(&create_ts, &hash); err != n il { |
| 430 log.Printf("Error: failed to fetch from database: %q", err) | 430 log.Printf("Error: failed to fetch from database: %q", err) |
| 431 continue | 431 continue |
| 432 } | 432 } |
| 433 tries = append(tries, Try{Hash: hash, CreateTS: create_ts.Format("2006-02-01")}) | 433 tries = append(tries, Try{Hash: hash, CreateTS: create_ts.Format("2006-02-01")}) |
| 434 } | 434 } |
| 435 } | 435 } |
| 436 var code string | 436 var code string |
| 437 if len(tries) == 0 { | 437 if len(tries) == 0 { |
| 438 code = DEFAULT_SAMPLE | 438 code = DEFAULT_SAMPLE |
| 439 } else { | 439 } else { |
| 440 » » » code = getCode(tries[0].Hash) | 440 » » » code = getCode(tries[len(tries)-1].Hash) |
|
mtklein
2014/04/21 16:19:01
Undo?
jcgregorio
2014/04/21 16:26:24
This was intentional, the history list is construc
mtklein
2014/04/21 16:31:14
Ah! Missed the DESC change. Thanks.
| |
| 441 } | 441 } |
| 442 if err := workspaceTemplate.Execute(w, Workspace{Tries: tries, C ode: code, Name: name}); err != nil { | 442 if err := workspaceTemplate.Execute(w, Workspace{Tries: tries, C ode: code, Name: name}); err != nil { |
| 443 log.Printf("ERROR: Failed to expand template: %q\n", err ) | 443 log.Printf("ERROR: Failed to expand template: %q\n", err ) |
| 444 } | 444 } |
| 445 } else if r.Method == "POST" { | 445 } else if r.Method == "POST" { |
| 446 name, err := newWorkspace() | 446 name, err := newWorkspace() |
| 447 if err != nil { | 447 if err != nil { |
| 448 http.Error(w, "Failed to create a new workspace.", 500) | 448 http.Error(w, "Failed to create a new workspace.", 500) |
| 449 return | 449 return |
| 450 } | 450 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 600 flag.Parse() | 600 flag.Parse() |
| 601 http.HandleFunc("/i/", imageHandler) | 601 http.HandleFunc("/i/", imageHandler) |
| 602 http.HandleFunc("/w/", workspaceHandler) | 602 http.HandleFunc("/w/", workspaceHandler) |
| 603 http.HandleFunc("/recent/", recentHandler) | 603 http.HandleFunc("/recent/", recentHandler) |
| 604 http.HandleFunc("/iframe/", iframeHandler) | 604 http.HandleFunc("/iframe/", iframeHandler) |
| 605 http.HandleFunc("/css/", cssHandler) | 605 http.HandleFunc("/css/", cssHandler) |
| 606 http.HandleFunc("/js/", jsHandler) | 606 http.HandleFunc("/js/", jsHandler) |
| 607 http.HandleFunc("/", mainHandler) | 607 http.HandleFunc("/", mainHandler) |
| 608 log.Fatal(http.ListenAndServe(*port, nil)) | 608 log.Fatal(http.ListenAndServe(*port, nil)) |
| 609 } | 609 } |
| OLD | NEW |