def init_routes(self): wr_api_spec.set_curr_tag('WASAPI (Downloads)') @self.app.get('/<user>/<coll>/<rec>/$download') def logged_in_download_rec_warc(user, coll, rec): self.redir_host() return self.handle_download(user, coll, rec) @self.app.get('/<user>/<coll>/$download') def logged_in_download_coll_warc(user, coll): self.redir_host() return self.handle_download(user, coll, '*') @self.app.get('/api/v1/download/webdata') @self.api( query=['?user', '?collection'], resp='wasapi_list', description= 'List all files available for download, their locations and checksums, per WASAPI spec' ) def wasapi_list_api(): return self.wasapi_list() @self.app.get('/api/v1/download/<user>/<coll>/<filename>') @self.api( resp='wasapi_download', description= 'Download the specified WARC from a users collection, per WASAPI spec' ) def wasapi_download_api(user, coll, filename): return self.wasapi_download(user, coll, filename) wr_api_spec.set_curr_tag(None)
def init_routes(self): wr_api_spec.set_curr_tag('Behaviors') @self.app.get('/api/v1/behavior/info-list') def info_list(): # for non-desktop proxy mode, proxy to behaviors server if not self.behaviors_root: query = dict(request.query) res = requests.get(self.behaviors_api + '/info-list', params=query) response.content_type = 'application/json; charset=utf-8' return res.content url = request.query.getunicode('url') behavior = self.find_match(url) behavior_list = [] if behavior: behavior_list.append(behavior) behavior_list.append(self.default_behavior) return {'behaviors': behavior_list} @self.app.get('/api/v1/behavior/behavior') def get_behavior(): # for non-desktop proxy mode, proxy to behaviors server if not self.behaviors_root: query = dict(request.query) res = requests.get(self.behaviors_api + '/behavior', params=query) response.content_type = 'application/json; charset=utf-8' return res.content url = request.query.getunicode('url') name = request.query.getunicode('name') behavior = None if name: res = self.behaviors.get(name) if res: behavior = res[0] elif url: behavior = self.find_match(url) if not behavior: behavior = self.default_behavior res = static_file(behavior['fileName'], root=self.behaviors_data) return res wr_api_spec.set_curr_tag(None)
def init_routes(self): wr_api_spec.set_curr_tag('Uploads') @self.app.put(['/_upload', '/api/v1/upload']) def upload_file(): user = self.access.session_user force_coll_name = request.query.getunicode('force-coll', '') if force_coll_name: collection = user.get_collection_by_name(force_coll_name) else: collection = None # allow uploading to external collections if not collection or not collection.is_external(): if user.is_anon(): return self._raise_error(400, 'not_logged_in') user.create_collection(force_coll_name, title=force_coll_name, public=False) expected_size = int(request.headers['Content-Length']) if not expected_size: return self._raise_error(400, 'no_file_specified') filename = request.query.getunicode('filename') stream = request.environ['wsgi.input'] res = self.uploader.upload_file(user, stream, expected_size, filename, force_coll_name) if 'error' in res: print("Error acceured on the old uploader") return self._raise_error(400, res['error']) Stats(self.redis).incr_upload(user, expected_size) return res @self.app.get(['/_upload/<upload_id>', '/api/v1/upload/<upload_id>']) def get_upload_status(upload_id): user = self.get_user(api=True) props = self.uploader.get_upload_status(user, upload_id) if not props: return self._raise_error(400, 'upload_expired') return props
def init_routes(self): wr_api_spec.set_curr_tag('Automation') # CREATE AUTO @self.app.post('/api/v1/auto') def create_auto(): user, collection = self.load_user_coll() autoid = collection.create_auto(request.json) return {'auto': autoid} # QUEUE URLS @self.app.post('/api/v1/auto/<autoid>/queue_urls') def add_urls(autoid): user, collection, auto = self.load_user_coll_auto(autoid) data = request.json or {} return auto.queue_urls(data.get('urls')) # START @self.app.post('/api/v1/auto/<autoid>/start') def add_urls(autoid): user, collection, auto = self.load_user_coll_auto(autoid) data = request.json or {} return auto.start(timeout=data.get('timeout', 0), headless=data.get('headless', False), screenshot_uri=data.get('screenshot_uri')) # STOP @self.app.post('/api/v1/auto/<autoid>/stop') def add_urls(autoid): user, collection, auto = self.load_user_coll_auto(autoid) return auto.stop() # GET AUTO @self.app.get('/api/v1/auto/<autoid>') def get_auto(autoid): user, collection, auto = self.load_user_coll_auto(autoid) return {'auto': auto.serialize()} # GET AUTO IS DONE @self.app.get('/api/v1/auto/<autoid>/done') def get_auto_done(autoid): user, collection, auto = self.load_user_coll_auto(autoid) return {'done': auto.is_done()} # DELETE AUTO @self.app.delete('/api/v1/auto/<autoid>') def delete_auto(autoid): user, collection, auto = self.load_user_coll_auto(autoid) auto.delete_me() return {'deleted_id': auto.my_id} wr_api_spec.set_curr_tag(None)