def post(self): url = self.request.params['url'] if tutil.validate_url(url): new_entry = tmodels.create_new_entry(url) new_url = tutil.construct_shortened_url( self.request.application_url, new_entry.url_hash, ) else: new_url = None template = TEMPLATE_ENV.get_template("creation_confirmed.html") context = { 'new_url': new_url, 'original_url': url, } self.response.write(template.render(context))
def enqueue(): data = json.loads(request.data.decode()) if 'input_url' not in data: response = { 'error': "The Youtube URL to download must be provided as 'input_url'", } logger.warn("Rejecting /api/enqueue request missing 'input_url'") return json.dumps(response), 400 # bad request clean_url = util.validate_url(data['input_url']) if clean_url is None: response = { 'error': "I'm sorry, that doesn't really look like a Youtube URL. :-(", 'info': "Please try again using a link starting with 'https://www.youtube.com'.", } logger.warn("Rejecting /api/enqueue request for %s" % data['input_url']) return json.dumps(response), 403 # forbidden logger.info("Accepting /api/enqueue request for %s" % clean_url) job = rqueue.enqueue_call( func=util.download, args=(clean_url, ), result_ttl=900 # 15 minutes ) job_id = job.get_id() redis.lpush(joblist, job_id) redis.ltrim(joblist, 0, 9) job_details = { 'job_id': job_id, 'request_url': clean_url, 'submitted': time.time(), 'page_title': '...', # just a placeholder to keep it pretty } redis.hmset(jobkey(job_id), job_details) redis.expire(jobkey(job_id), 86400) # 24 hours response = { 'job_id': job_id, } return json.dumps(response), 201 # created
def enqueue(): data = json.loads(request.data.decode()) if 'input_url' not in data: response = { 'error': "The Youtube URL to download must be provided as 'input_url'", } logger.warn("Rejecting /api/enqueue request missing 'input_url'") return json.dumps(response), 400 # bad request clean_url = util.validate_url(data['input_url']) if clean_url is None: response = { 'error': "I'm sorry, that doesn't really look like a Youtube URL. :-(", 'info': "Please try again using a link starting with 'https://www.youtube.com'.", } logger.warn("Rejecting /api/enqueue request for %s" % data['input_url']) return json.dumps(response), 403 # forbidden logger.info("Accepting /api/enqueue request for %s" % clean_url) job = rqueue.enqueue_call( func=util.download, args=(clean_url,), result_ttl=900 # 15 minutes ) job_id = job.get_id() redis.lpush(joblist, job_id) redis.ltrim(joblist, 0, 9) job_details = { 'job_id': job_id, 'request_url': clean_url, 'submitted': time.time(), 'page_title': '...', # just a placeholder to keep it pretty } redis.hmset(jobkey(job_id), job_details) redis.expire(jobkey(job_id), 86400) # 24 hours response = { 'job_id': job_id, } return json.dumps(response), 201 # created