Esempio n. 1
0
    def put(self):
        result = {"error": None, "data": []}
        choices = ("poster", "banner")

        parser = reqparse.RequestParser()
        parser.add_argument("file", type=FileStorage, location="files")
        parser.add_argument("type", type=str, choices=choices)
        parser.add_argument("slug", type=str, required=True)
        args = parser.parse_args()

        anime = AnimeService.get_by_slug(args["slug"])
        if anime is None:
            return abort("anime", "not-found")

        if args["file"] is not None:
            helper = UploadHelper(request.account, args["file"], args["type"])
            data = helper.upload_image()

            if type(data) is Response:
                return data

            if anime[args["type"]] is not None:
                FileService.destroy(anime[args["type"]])

            anime[args["type"]] = data
            anime.save()

        result["data"] = anime.dict()
        return result
Esempio n. 2
0
    def post(self):
        result = {"error": None, "data": {}}

        parser = reqparse.RequestParser()
        parser.add_argument("position", type=int, required=True)
        parser.add_argument("team", type=str, required=True)
        parser.add_argument("slug", type=str, required=True)
        args = parser.parse_args()

        team = TeamService.get_by_slug(args["team"])
        if team is None:
            return abort("team", "not-found")

        if request.account not in team.members:
            return abort("account", "not-team-member")

        anime = AnimeService.get_by_slug(args["slug"])
        if anime is None:
            return abort("anime", "not-found")

        episode = AnimeService.find_position(anime, args["position"])
        if episode is None:
            return abort("episodes", "not-found")

        FileService.destroy(episode.video)
        AnimeService.remove_episode(anime, episode)

        result["data"] = anime.dict(True)
        return result
Esempio n. 3
0
    def post(self):
        result = {"error": None, "data": {}}

        parser = reqparse.RequestParser()
        parser.add_argument("video", type=FileStorage, location="files")
        parser.add_argument("position", type=int, required=True)
        parser.add_argument("team", type=str, required=True)
        parser.add_argument("slug", type=str, required=True)
        parser.add_argument("params", type=dict, default={})
        args = parser.parse_args()

        team = TeamService.get_by_slug(args["team"])
        if team is None:
            return abort("team", "not-found")

        if request.account not in team.members:
            return abort("account", "not-team-member")

        anime = AnimeService.get_by_slug(args["slug"])
        if anime is None:
            return abort("anime", "not-found")

        episode = AnimeService.find_position(anime, args["position"])
        if episode is None:
            return abort("episodes", "not-found")

        video = episode.video
        if args["video"] is not None:
            helper = UploadHelper(request.account, args["video"], "video")
            data = helper.upload_video()

            if type(data) is Response:
                return data

            FileService.destroy(episode.video)
            video = data

        name = episode.name
        if "name" in args["params"]:
            name = args["params"]["name"]

        position = episode.position
        if "position" in args["params"]:
            if args["position"] < 0:
                return abort("general", "out-of-range")

            episode_check = AnimeService.find_position(anime, args["position"])
            if episode_check is not None:
                return abort("episodes", "position-exists")

            position = args["params"]["position"]

        AnimeService.remove_episode(anime, episode)
        episode = AnimeService.get_episode(name, position, video)
        AnimeService.add_episode(anime, episode)

        result["data"] = anime.dict(True)
        return result
Esempio n. 4
0
def anime(slug):
    anime = AnimeService.get_by_slug(slug)
    valid = False

    if anime:
        if anime.hidden is True:
            if hasattr(request, "account"):
                valid = check.member(request.account, anime.teams)
                if check.permission(request.account, "global", "admin"):
                    valid = True

        else:
            valid = True

    if not valid:
        response = abort("anime", "not-found")
        flask_abort(response)

    return anime
Esempio n. 5
0
    def post(self):
        result = {"error": None, "data": {}}

        parser = reqparse.RequestParser()
        parser.add_argument("subject",
                            type=str,
                            required=True,
                            choices=choices)
        parser.add_argument("text", type=str, required=True)
        parser.add_argument("slug", type=str, required=True)
        args = parser.parse_args()

        subject = None
        if args["subject"] == "anime":
            subject = AnimeService.get_by_slug(args["slug"])

        comment = CommentService.create(subject, request.account, args["text"])
        result["data"] = comment.dict()

        return result
Esempio n. 6
0
    def post(self):
        result = {"error": None, "data": {}}

        parser = reqparse.RequestParser()
        parser.add_argument("rating",
                            type=int,
                            required=True,
                            choices=range(1, 11))
        parser.add_argument("subject",
                            type=str,
                            required=True,
                            choices=choices)
        parser.add_argument("slug", type=str, required=True)
        args = parser.parse_args()

        subject = None
        if args["subject"] == "anime":
            subject = AnimeService.get_by_slug(args["slug"])

        vote = VoteService.submit(subject, request.account, args["rating"])
        result["data"] = vote.dict()

        return result
Esempio n. 7
0
    def get(self, slug):
        anime = AnimeService.get_by_slug(slug)
        if anime is None:
            return abort("anime", "not-found")

        return anime.dict(True)