예제 #1
0
    def post(self):
        json_data = request.get_json(silent=True)
        if not json_data:
            return response.bad_request("Problems parsing JSON.")
        errors = self._check_post_params(json_data)
        if errors:
            return response.unprocessable_entity(errors=errors)

        notices_cached = self.cache_get("notices")
        if not notices_cached:
            notices_cached = {}

        notices_created = notices_cached
        for notice_meta in json_data["targets"]:
            id_str = str(notice_meta["id"])
            if id_str in notices_cached.keys():
                continue
            notices_created[id_str] = self._build_notice(notice_meta)
        if notices_created:
            self.cache_set("notices", notices_created)
            return response.created()
        else:
            return response.ok("Nothing changed.")
예제 #2
0
    def post(self):
        json_data = request.get_json(silent=True)
        if not json_data:
            return response.bad_request("Problems parsing JSON.")
        errors = self._check_post_params(json_data)
        if errors:
            return response.unprocessable_entity(errors=errors)

        mirrors_cached = self.cache_get("mirrors")
        if not mirrors_cached:
            mirrors_cached = {}

        mirrors_created = mirrors_cached.copy()
        for mirror_meta in json_data["targets"]:
            cname = mirror_meta["cname"]
            # Just pass existed items and don't update it here!
            if cname in mirrors_cached.keys():
                continue
            mirrors_created[cname] = self._build_mirror(mirror_meta)
        if mirrors_created:
            self.cache_set("mirrors", mirrors_created)
            return response.created()
        else:
            return response.ok("Nothing changed.")