def post(self): parser = reqparse.RequestParser() parser.add_argument('url', required=True, help="Url is necessary") args = parser.parse_args() url_text = args['url'] urls = re.findall( 'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', url_text) if len(urls) == 0: return { 'message': 'No enviaste una url válida', 'status_code': 400 }, 400 current_user = get_jwt_identity() shorted_id = uuid.uuid1().hex url = UrlModel(current_user['id'], urls[0], shorted_id) url.save() return { 'message': 'Ok', 'status_code': 200, 'shorted': url.get_url(), 'url': url.real_url }
def get(self, urlet): urlet = UrlModel.find_by_urlet(urlet) if not urlet: return {'message': 'urlet not found.'} url = urlet.url urlet.count += 1 urlet.save_to_db() return redirect(url, code=302)
def get(self): current_user = get_jwt_identity() urls_list = UrlModel.get_by_user( current_user['id'] ) urls = [i.to_json() for i in urls_list] return { 'message' : 'Ok', 'status_code' : 200, 'data' : urls }
def get(self): parser = reqparse.RequestParser() parser.add_argument('urlet', type=str, required=True, help="This field can not be blank.") data = parser.parse_args() print(f"********************************{data}") urlet = UrlModel.find_by_urlet(data['urlet']) print(f"********************************{urlet}") return urlet.json(), 200
def post(self): parser = reqparse.RequestParser() parser.add_argument('url', type=str, required=True, help="This field can not be blank.") data = parser.parse_args() urlet = ''.join( secrets.choice(string.ascii_letters + string.digits) for _ in range(7)) while UrlModel.find_by_urlet(urlet): urlet = ''.join( secrets.choice(string.ascii_letters + string.digits) for _ in range(7)) url = UrlModel(data['url'], urlet, 0) try: url.save_to_db() except: return {'message': 'An error occurred inserting the url.'}, 500 return url.json(), 201
def post(self, ver): if UrlModel.find_by_name(ver): return {'message': "A store with ver '{}' already exists.".format(UrlModel)}, 400 data = Url.parser.parse_args() ver = UrlModel(ver, **data) # home = HomeModel(name, data['body']) try: ver.save_to_db() except: return {"message": "An error occurred creating the ver."}, 500 return ver.json(), 201
def delete(self, ver): ver = UrlModel.find_by_name(ver) if ver: ver.delete_from_db() return {'message': 'ver deleted'}
def get(self, ver): ver = UrlModel.find_by_name(ver) if ver: return ver.json() return {'message': 'ver not found'}, 404
def get(self, url): url_find = UrlModel.get_by_shorted(url) if url_find is None: return redirect("/", code=302) return redirect(url_find.get_real_url(), code=302)