7313ce5bd73f66ef010e3c8a04d212301b1cc417 — Trevor Slocum 27 days ago d629a79
Allow notebooks to be served publicly

Resolves #6
4 files changed, 30 insertions(+), 7 deletions(-)

M author.go
M stick.go
M web.go
M web/assets/stick.js
M author.go => author.go +6 -0
@@ 7,3 7,9 @@   	Notebooks []*Notebook
  }
+ 
+ var PublicAuthor = &Author{
+ 	Key:   "public",
+ 	Name:  "Anonymous",
+ 	Email: "anonymous@stick.app",
+ }

M stick.go => stick.go +10 -1
@@ 38,6 38,8 @@ for _, author := range stick.Config.Authors {
  		stick.Authors[hash(author.Email)] = &Author{Key: hash(author.Email), Email: author.Email, Name: author.Name}
  	}
+ 
+ 	stick.Authors["public"] = PublicAuthor
  }
  
  func (s *Stick) loadNotebooks() {


@@ 55,7 57,13 @@   		notebook.Serve = make(map[string]int)
  		for serveauthor, serveaccess := range nbconfig.Serve {
- 			notebook.Serve[hash(serveauthor)] = serveaccess
+ 			var servehash string
+ 			if serveauthor == "public" {
+ 				servehash = "public"
+ 			} else {
+ 				servehash = hash(serveauthor)
+ 			}
+ 			notebook.Serve[servehash] = serveaccess
  		}
  
  		stick.Notebooks[hash(nbconfig.Label)] = notebook


@@ 66,6 74,7 @@ for serveauth := range notebook.Serve {
  			author = stick.getAuthor(serveauth)
  			if author == nil {
+ 				log.Println("no author", notebook.Label, stick.getAuthor(serveauth))
  				continue
  			}
  

M web.go => web.go +8 -1
@@ 249,8 249,15 @@ continue
  		}
  
+ 		var authorName string
+ 		if authkey == "public" {
+ 			authorName = "Public"
+ 		} else {
+ 			authorName = author.Name[0:int(math.Min(10, float64(len(author.Name))))]
+ 		}
+ 
  		log.Println()
- 		log.Printf("%-10s http://%s/#login/%s", author.Name[0:int(math.Min(10, float64(len(author.Name))))], stick.Config.Serve, authkey)
+ 		log.Printf("%-10s http://%s/#login/%s", authorName, stick.Config.Serve, authkey)
  		for _, notebook := range author.Notebooks {
  			log.Printf("- %s", notebook.Label[0:int(math.Min(20, float64(len(notebook.Label))))])
  		}

M web/assets/stick.js => web/assets/stick.js +6 -5
@@ 59,9 59,6 @@ if (window.location.hash.substring(0, 7) === '#login/') {
          processHash();
          processedHash = true;
-     } else if (AuthKey === "") {
-         alert('Please sign in');
-         return;
      }
  
      $(window).on("focus blur", function (e) {


@@ 120,8 117,8 @@ clearTimeout(PauseTimeout);
          PauseTimeout = null;
      }
-     if (AuthKey === "") {
-         return;
+     if (AuthKey == "") {
+         AuthKey = "public";
      }
      if (webSocketReady() || ReconnectDelay !== -1) {
          return;


@@ 735,6 732,10 @@ }
  
  function setAuthKey(newAuthKey) {
+     if (newAuthKey == "") {
+         newAuthKey = "public";
+     }
+ 
      AuthKey = newAuthKey;
  
      db.transaction('rw', db.credentials, async () => {