Пример #1
0
def add_episode():
    result = {"error": None, "data": {}}

    parser = RequestParser()
    parser.argument("opening", type=helpers.opening, location="json")
    parser.argument("position", type=helpers.position, required=True)
    parser.argument("slug", type=helpers.anime, required=True)
    parser.argument("ending", type=int)
    parser.argument("name", type=str)
    args = parser.parse()

    anime = args["slug"]
    helpers.is_member(request.account, anime.teams)

    index = AnimeService.position_index(anime, args["position"])
    if index is None:
        episode = AnimeService.get_episode(args["position"])
        AnimeService.add_episode(anime, episode)
    else:
        episode = anime.episodes[index]

    fields = ["name", "opening", "ending"]
    for field in fields:
        if args[field]:
            episode[field] = args[field]

    anime.save()
    result["data"] = anime.dict(True)

    return result
Пример #2
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