Commits

Matthew Turk committed 67b489c

Adding a shorturl for notebooks

  • Participants
  • Parent commits d7068da

Comments (0)

Files changed (2)

ythub/uploader.py

             url = "https://hub.yt-project.org/go/%s" % (
                 self.metadata['shorturl'])
             return jsonify({'status' : "COMPLETE",
-                            'url' : url})
+                            'url' : url,
+                            'hub_id' : self.metadata['hub_id']})
         return make_response("Short URL not found!", 404)
     return redirect(data[0]._url)
 
+@app.route("/nb/<shorturl>")
+def nb_shorturl(shorturl):
+    data = shorturl_query(shorturl)
+    if len(data) > 1:
+        return make_response("Something is not right.", 400)
+    elif len(data) == 0:
+        return make_response("Short URL not found!", 404)
+    elif data[0].obj_type != "notebook":
+        return make_response("This is not a notebook.", 404)
+    return redirect(data[0]._nburl)
+
 @app.route("/project/<project_descr>")
 def project_view(project_descr):
     project = project_query(project_descr)