def apiServiceVideo(id=None): funMap = {'GET':db_video.get_all, 'DELETE':''} if 'username' in session and request.is_xhr: doc_return = {} if request.method == 'GET': if id == None: #doc = request db_return = db_video.get_all() doc_count = db_video.count() for doc in db_return: doc['_id']=doc.eid; doc_return = {'count':doc_count,'result':db_return} #print doc_return else: db_return = db_video.get(id) db_return['_id']=db_return.eid doc_return = {'result':[db_return]} elif request.method == 'POST': doc = request.get_json(force=True) db_video.add_video(doc) doc_return = {'result':{'status':'ok'},} elif request.method == 'DELETE': db_video.remove(id) doc_return = {'result':{'status':'ok','_id':id},} return jsonify(doc_return) elif request.is_xhr: return "{'result':{'status':'error','message':'login is required'}}" else: return redirect(url_for('login'))
def apiServiceDownload(id=None): return_value = "{'status':'error','message':'login is required'}"; if 'username' in session and request.is_xhr: doc = db_video.get(id) newThread = threading.Thread(target=download_video, args=(doc,)) threadList.append(newThread) newThread.start() doc_return = {'status':'ok','message':'video will be downloaded','result':''} return_value = jsonify(doc_return) elif not(request.is_xhr): return_value = redirect(url_for('login')) return return_value