Ejemplo n.º 1
0
    def actionSitePublish(self, to, privatekey=None, inner_path="content.json", sign=True):
        if sign:
            inner_path = self.actionSiteSign(to, privatekey, inner_path, response_ok=False)
            if not inner_path:
                return
        # Publishing
        if not self.site.settings["serving"]:  # Enable site if paused
            self.site.settings["serving"] = True
            self.site.saveSettings()
            self.site.announce()

        event_name = "publish %s %s" % (self.site.address, inner_path)
        called_instantly = RateLimit.isAllowed(event_name, 30)
        thread = RateLimit.callAsync(event_name, 30, self.doSitePublish, self.site, inner_path)  # Only publish once in 30 seconds
        notification = "linked" not in dir(thread)  # Only display notification on first callback
        thread.linked = True
        if called_instantly:  # Allowed to call instantly
            # At the end callback with request id and thread
            self.cmd("progress", ["publish", _["Content published to {0}/{1} peers."].format(0, 5), 0])
            thread.link(lambda thread: self.cbSitePublish(to, self.site, thread, notification, callback=notification))
        else:
            self.cmd(
                "notification",
                ["info", _["Content publish queued for {0:.0f} seconds."].format(RateLimit.delayLeft(event_name, 30)), 5000]
            )
            self.response(to, "ok")
            # At the end display notification
            thread.link(lambda thread: self.cbSitePublish(to, self.site, thread, notification, callback=False))
Ejemplo n.º 2
0
    def actionSitePublish(self,
                          to,
                          privatekey=None,
                          inner_path="content.json",
                          sign=True):
        if sign:
            inner_path = self.actionSiteSign(to,
                                             privatekey,
                                             inner_path,
                                             response_ok=False)
            if not inner_path:
                return
        # Publishing
        if not self.site.settings["serving"]:  # Enable site if paused
            self.site.settings["serving"] = True
            self.site.saveSettings()
            self.site.announce()

        if inner_path not in self.site.content_manager.contents:
            return self.response(to,
                                 {"error": "File %s not found" % inner_path})

        event_name = "publish %s %s" % (self.site.address, inner_path)
        called_instantly = RateLimit.isAllowed(event_name, 30)
        thread = RateLimit.callAsync(
            event_name, 30, self.doSitePublish, self.site,
            inner_path)  # Only publish once in 30 seconds
        notification = "linked" not in dir(
            thread)  # Only display notification on first callback
        thread.linked = True
        if called_instantly:  # Allowed to call instantly
            # At the end callback with request id and thread
            self.cmd("progress", [
                "publish", _["Content published to {0}/{1} peers."].format(
                    0, 5), 0
            ])
            thread.link(lambda thread: self.cbSitePublish(
                to, self.site, thread, notification, callback=notification))
        else:
            self.cmd("notification", [
                "info",
                _["Content publish queued for {0:.0f} seconds."].format(
                    RateLimit.delayLeft(event_name, 30)), 5000
            ])
            self.response(to, "ok")
            # At the end display notification
            thread.link(lambda thread: self.cbSitePublish(
                to, self.site, thread, notification, callback=False))
Ejemplo n.º 3
0
    def actionSitePublish(self,
                          to,
                          privatekey=None,
                          inner_path="content.json",
                          sign=True):
        if sign:
            inner_path = self.actionSiteSign(to,
                                             privatekey,
                                             inner_path,
                                             response_ok=False)
            if not inner_path:
                return
        # Publishing
        if not self.site.settings["serving"]:  # Enable site if paused
            self.site.settings["serving"] = True
            self.site.saveSettings()
            self.site.announce()

        event_name = "publish %s %s" % (self.site.address, inner_path)
        called_instantly = RateLimit.isAllowed(event_name, 30)
        thread = RateLimit.callAsync(
            event_name, 30, self.site.publish, 5,
            inner_path)  # Only publish once in 30 seconds to 5 peer
        notification = "linked" not in dir(
            thread)  # Only display notification on first callback
        thread.linked = True
        if called_instantly:  # Allowed to call instantly
            # At the end callback with request id and thread
            thread.link(lambda thread: self.cbSitePublish(
                to, thread, notification, callback=notification))
        else:
            self.cmd("notification", [
                "info",
                "Content publish queued for %.0f seconds." %
                RateLimit.delayLeft(event_name, 30), 5000
            ])
            self.response(to, "ok")
            # At the end display notification
            thread.link(lambda thread: self.cbSitePublish(
                to, thread, notification, callback=False))