diff --git a/server/api_channel.py b/server/api_channel.py index 2b342d1..1b73e2d 100644 --- a/server/api_channel.py +++ b/server/api_channel.py @@ -84,6 +84,12 @@ def register_channel(): if not params: return invalid_request('The request body is not valid JSON') + # Hosted By: The name of the hoster + if 'hosted-by' not in params: + return invalid_parameter('hosted-by', 'Hosted by is required') + if len(params['hosted-by']) > 80: + return invalid_parameter('hosted-by', 'Hosted by is too long (max 80 chars)') + # name: The channel name, required. Can contain any letters. if 'name' not in params: return invalid_parameter('name', 'A channel name is required') @@ -115,7 +121,7 @@ def register_channel(): return invalid_parameter('password', 'A password is required') try: - create_channel(params['name'], params['slug'], params['url'], params['password']) + create_channel(params['name'], params['slug'], params['url'], params['password'], params['hosted-by']) except ChannelExistsError: return invalid_parameter('slug', 'The slug is already in use') diff --git a/server/api_public.py b/server/api_public.py index 149e30b..e49ccb8 100644 --- a/server/api_public.py +++ b/server/api_public.py @@ -38,6 +38,17 @@ def list_channels(page=1): }) return jsonify(dict(base_resp, channels=channel_list)) +@app.route('/api/channel/') +def channel_by_url(id): + ch = Channel.query.filter_by(id=id).first() + + return jsonify({ + 'channel': ch.name, + 'slug': ch.slug, + 'url': ch.url, + 'hosted-by': ch.hosted_by + }) + @app.route('/api/videos/') @app.route('/api/videos/') def list_videos(page=1): diff --git a/server/channel.py b/server/channel.py index fa913b9..7bc0aee 100644 --- a/server/channel.py +++ b/server/channel.py @@ -31,8 +31,8 @@ def authenticate_channel(slug, password): return channel -def create_channel(name, slug, url, password): - channel = Channel(name, slug, url, password) +def create_channel(name, slug, url, password, hosted_by): + channel = Channel(name, slug, url, password, hosted_by) db.session.add(channel) @@ -60,15 +60,17 @@ class Channel(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80)) slug = db.Column(db.String(80), unique=True) + hosted_by = db.Column(db.String(80)) url = db.Column(db.String(256)) password = db.Column(db.LargeBinary(256), unique=True) videos = db.relationship('Video', backref='channel') - def __init__(self, name, slug, url, password): + def __init__(self, name, slug, url, password, hosted_by): self.name = name self.password = hash_password(password) self.url = url self.slug = slug + self.hosted_by = hosted_by class Video(db.Model):