示例#1
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
示例#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