Esempio n. 1
0
def create_trackout():
    try:
        user_id = current_identity.id
        track_id = request.json.get('track_id')
        type_of_track = request.json.get('type')
        name = request.json.get('name')
        settings = request.json.get('settings')
        raw_track = Track.query.filter_by(uuid=track_id).first()
        if not raw_track:
            abort(404, f"failed to find track {track_id}")

        print(f'track_id: {track_id}')
        if track_id:
            raw_trackouts = TrackOut.query.filter_by(track_id=track_id).all()
            trackouts_names = [rt.name for rt in raw_trackouts]
            # if name in trackouts_names:
            #     abort(400, f"{name} is not a unique trackout name for this track")
        raw_trackout = TrackOut(user_id=user_id,
                                track_id=track_id,
                                name=name,
                                type=type_of_track,
                                settings=settings,
                                trackouts=raw_track)
        db.session.add(raw_trackout)
        db.session.commit()
        trackout = raw_trackout.to_dict()
        response = APIResponse(trackout, 201).response
        return response
    except Exception as err:
        print(f'#### error creating trackout: {err}')
        app.logger.error("error creating trackout:", err)
        abort(500, err)
Esempio n. 2
0
def profile():
    user = User.query.filter_by(id=current_identity.id).first()
    if user is None:
        return abort(404, "User not found")
    u = user.to_dict()
    del u['password_hash']  # NB: Don't send password hash to user
    return APIResponse(u, 200).response
Esempio n. 3
0
def get_user_by_id(id):
    try:
        user = User.query.get(id)
        if not user:
            abort(404, "User not found")
        response = APIResponse(user.to_dict(), 200).response
        return response
    except Exception as e:
        abort(500, e)
Esempio n. 4
0
def update_user(id):
    try:
        db.session.query(User).filter_by(id=id).update(request.json)
        db.session.commit()
        payload = {"action": "updated", "table": "user", "id": id}
        response = APIResponse(payload, 200).response
        return response
    except Exception as e:
        abort(500, e)
Esempio n. 5
0
def get_trackout_by_id(uuid):
    try:
        raw_trackout = TrackOut.query.filter_by(uuid=uuid).first()
        if not raw_trackout:
            abort(400, "A trackout with id %s does not exist" % uuid)
        trackout = raw_trackout.to_dict()
        response = APIResponse(trackout, 200).response
        return response
    except Exception as e:
        abort(500, e)
Esempio n. 6
0
def get_users():
    try:
        raw_users = User.query.all()
        users = [raw_user.to_dict() for raw_user in raw_users]
        if not users:
            abort(404, "There aren't any users")
        response = APIResponse(users, 200).response
        return response
    except Exception as e:
        abort(500, e)
Esempio n. 7
0
def update_track(id):
    try:
        # TODO Effected by an updated trackout
        db.session.query(Track).filter_by(id=id).update(request.json)
        db.session.commit()
        payload = {"action": "update", "table": "trackouts", "id": str(id)}
        response = APIResponse(payload, 200).response
        return response
    except Exception as e:
        abort(500, e)
Esempio n. 8
0
def get_track_by_id(id):
    try:
        raw_track = Track.query.get(id)
        track = raw_track.to_dict()
        if not track:
            abort(400, "A track with id %s does not exist" % id)
        response = APIResponse(track, 200).response
        return response
    except Exception as e:
        abort(500, e)
Esempio n. 9
0
def get_tracks():
    try:
        user_id = current_identity.id
        raw_tracks = Track.query.filter_by(user_id=user_id).all()
        if not raw_tracks:
            # handle empty raw tracks list
            response = APIResponse([], 200).response
            return response
        tracks = [raw_track.to_dict() for raw_track in raw_tracks]
        if not tracks:
            # handle empty tracks list
            response = APIResponse([], 200).response
            return response

        response = APIResponse(tracks, 200).response
        print(f'responding with: ', response)
        return response
    except Exception as err:
        print(f'get_tracks error: {err}')
        app.logger.error("error getting track:", err)
        abort(500, err)
Esempio n. 10
0
def get_trackouts_by_track_id(id):
    try:
        raw_tracks = Track.query.get(id)
        raw_trackouts = raw_tracks.trackouts.all()
        trackouts = [raw_trackout.to_dict() for raw_trackout in raw_trackouts]
        if not trackouts:
            abort(400)
        response = APIResponse(trackouts, 200).response
        return response
    except Exception as err:
        app.logger.error("error getting track by ID:", err)
        abort(500, err)
Esempio n. 11
0
def delete_trackout_by_id(uuid):
    try:
        raw_trackout = TrackOut.query.filter_by(uuid=uuid).first()
        if not raw_trackout:
            abort(404, "A trackout with id %s does not exist" % uuid)
        db.session.delete(raw_trackout)
        db.session.commit()
        payload = {"action": "delete", "table": "trackouts", "id": uuid}
        response = APIResponse(payload, 200).response
        return response
    except Exception as err:
        app.logger.error(f'error deleting trackout: {err}')
        abort(500, err)
Esempio n. 12
0
def delete_track_by_id(id):
    try:
        raw_track = Track.query.get(id)
        if not raw_track:
            abort(404, "A track with id %s does not exist" % id)
        db.session.delete(raw_track)
        db.session.commit()
        payload = {"action": "delete", "table": "trackouts", "id": id}
        response = APIResponse(payload, 200).response
        return response
    except Exception as err:
        app.logger.error("error deleting track:", err)
        abort(500, err)
Esempio n. 13
0
def get_trackouts():
    try:
        track_id = request.args.get('track_id')
        print(f'###  Getting trackouts for track_id: {track_id}')

        # get trackouts by track_id
        if track_id:
            raw_trackouts = TrackOut.query.filter_by(track_id=track_id).all()
            trackouts = [rt.to_dict() for rt in raw_trackouts]
            if not trackouts:
                abort(400, "No trackouts have been created yet")
            response = APIResponse(trackouts, 200).response
            return response

        raw_trackouts = TrackOut.query.all()
        trackouts = [raw_trackout.to_dict() for raw_trackout in raw_trackouts]
        if not trackouts:
            abort(400, "No trackouts have been created yet")
        response = APIResponse(trackouts, 200).response
        return response
    except Exception as e:
        abort(500, e)
Esempio n. 14
0
def process_track(id):
    try:

        def str_to_bool(s):
            if s == 'true':
                return True
            elif s == 'false':
                return False
            else:
                return s

        # Track should contain user
        current_user = User.query.get(current_identity.id)

        # Search track by UUID
        raw_track = Track.query.filter_by(uuid=id).first()
        if not raw_track:
            abort(404, f'No trackout found for {id}')

        app.logger.info(f'raw track for processing {raw_track}')
        raw_toggle_params = request.json.get('toggle_effects_params')
        toggle_effects_params = {
            key: str_to_bool(val)
            for key, val in raw_toggle_params.items()
        }
        # TODO check all values in toggle_effects_params to evaluate to true
        app.logger.info(
            f"processing {id} with params: {toggle_effects_params}")

        if not raw_track:
            abort(404, f"There aren't any trackouts for track {id}")

        # Dispatch email processing progress, managed by queueWorker
        email_proxy(title="Initiating Processing",
                    template_type="status",
                    user_to_email_address=current_user.email,
                    user_name=current_user.name)

        # extract trackout data from track
        raw_trackouts = raw_track.trackouts.all()
        app.logger.info(f"Processing {len(raw_trackouts)}# trackouts")
        orchestrator = Orchestrator(current_user, raw_trackouts, raw_track,
                                    toggle_effects_params)
        orchestrator.orchestrate()

        payload = {"action": "processing", "table": "track", "id": id}
        response = APIResponse(payload, 200).response
        return response
    except Exception as err:
        app.logger.error(f'error processing track {id}:', err)
        abort(500, err)
Esempio n. 15
0
def delete_user_by_id(id):
    try:
        if id is not current_identity.id:
            abort(401, "Not authorized")
        user = User.query.get(id)
        if not user:
            abort(404, "User id %s does not exist" % id)
        db.session.delete(user)
        db.session.commit()
        payload = {"action": "deleted", "table": "user", "id": id}
        response = APIResponse(payload, 200).response
        return response
    except Exception as e:
        abort(500, e)
Esempio n. 16
0
def update_trackout(uuid):
    try:
        # TODO republish a process for a newly updated wavfile
        user_id = current_identity.id
        raw_user = db.session.query(User).get(id=user_id)
        user = raw_user.to_dict()
        if not user:
            abort(400, f"A User with this id {user_id} does not exist")

        db.session.query(TrackOut).filter_by(uuid=uuid).update(request.json)
        db.session.commit()
        payload = {"action": "update", "table": "trackouts", "id": uuid}
        response = APIResponse(payload, 200).response
        return response
    except Exception as e:
        abort(500, e)
Esempio n. 17
0
def create_track():
    try:
        user_id = current_identity.id
        name = request.json.get('name')
        artist = request.json.get('artist')
        info = request.json.get('info')

        raw_track = Track(user_id=user_id, name=name, artist=artist, info=info)

        db.session.add(raw_track)
        db.session.commit()

        track = raw_track.to_dict()

        response = APIResponse(track, 201).response
        return response
    except Exception as err:
        app.logger.error("error creating track:", err)
        abort(500, err)
Esempio n. 18
0
def add_update_wavfile(uuid):
    try:
        raw_file = request.files['file']
        raw_trackout = TrackOut.query.filter_by(uuid=uuid).first()
        if not raw_trackout:
            abort(404, f"There isn't a trackout id {uuid}")
        trackout_uuid = raw_trackout.uuid
        track_uuid = raw_trackout.track_id
        storage_name = f"{trackout_uuid}.wav"
        firestore_path = f"track/{track_uuid}/trackouts/{storage_name}"
        publish_to_file_store(firestore_path, raw_file)
        update_request = {"path": firestore_path}
        db.session.query(TrackOut).filter_by(uuid=uuid).update(update_request)
        db.session.commit()
        payload = {"action": "update", "table": "trackout", "id": uuid}
        response = APIResponse(payload, 200).response
        return response
    except Exception as err:
        # TODO: Need to delete trackout if this happens because the path
        # isnt' set and thus it causes errors.
        app.logger.error("error updating wav: ", err)
        abort(500, err)
Esempio n. 19
0
def signup_users():
    try:
        email = request.json.get('email')
        name = request.json.get('name')
        password = request.json.get('password')
        raw_user = User.query.filter_by(email=email).first()

        if raw_user:
            abort(403, "User already exists")

        raw_user = User(
            email=email,
            name=name,
            password_hash=generate_password_hash(password, method='sha256')
        )
        user = raw_user.to_dict()
        db.session.add(raw_user)
        db.session.commit()
        response = APIResponse(user, 201, message="Created").response
        email_proxy("welcome", email, name)
        return response
    except Exception as err:
        app.logger.error("error signing up user:", err)
        abort(500, err)
Esempio n. 20
0
def check():
    return APIResponse("OK", 200).response