3 次代码提交 a76642da28 ... aa6d9dd491

作者 SHA1 备注 提交日期
  Trevor Elliott aa6d9dd491 Add share target 3 年之前
  Trevor Elliott 62d4157235 Add a synonym url for /u/<user>/l 3 年之前
  Trevor Elliott 60eed346e3 Clean out debugging output for service-worker 3 年之前
共有 4 个文件被更改,包括 21 次插入18 次删除
  1. 2 7
      js/index.js
  2. 0 10
      js/serviceWorker.js
  3. 9 0
      lc/app.py
  4. 10 1
      static/manifest.json

+ 2 - 7
js/index.js

@@ -70,11 +70,6 @@ document.addEventListener("DOMContentLoaded", () => {
 });
 
 if ('serviceWorker' in navigator) {
-  navigator.serviceWorker
-    .register('/service-worker')
-    .then(function(registration) {
-      console.log("ServiceWorker registration successful with scope: ", registration.scope);
-    }).catch(function(err) {
-      console.log("ServiceWorker registration failed: ", err);
-    });
+  // TODO(trevor) does it matter if this fails?
+  navigator.serviceWorker.register('/service-worker')
 }

+ 0 - 10
js/serviceWorker.js

@@ -1,19 +1,9 @@
 
 self.addEventListener("install", event => {
-  console.log("installing...");
 });
 
 self.addEventListener("activate", event => {
-  console.log("activate!");
 });
 
 self.addEventListener("fetch", event => {
-  console.log("start service worker");
-
-  event.respondWith(
-    fetch(event.request).then(response => {
-      console.log("fetching %s", event.request.url);
-      return response;
-    })
-  );
 });

+ 9 - 0
lc/app.py

@@ -296,3 +296,12 @@ class PinboardImport(Endpoint):
 class ServiceWorker(Endpoint):
     def route(self, *args, **kwargs):
         return flask.send_file("../js/serviceWorker.js", mimetype="text/javascript")
+
+@endpoint("/add-link")
+class AddLink(Endpoint):
+    def html(self):
+        if not self.user:
+            raise e.LCRedirect("/login")
+        else:
+            args = "&".join(f"{key}={value}" for key, value in flask.request.args.items())
+            raise e.LCRedirect(f"/u/{self.user.name}/l?{args}")

+ 10 - 1
static/manifest.json

@@ -15,5 +15,14 @@
       "type": "image/png",
       "sizes": "512x512"
     }
-  ]
+  ],
+  "share_target": {
+    "action": "/add-link",
+    "method": "GET",
+    "params": {
+      "title": "name",
+      "text": "text",
+      "url": "url"
+    }
+  }
 }