Пример #1
0
def capture_queue():
	current_user = db.User.find_one({'token_key':request.form['token']})
	if current_user:
		if request.method == 'POST' and 'url' in request.form:
			url = request.form['url']
			if url != '':
				hashed = uuid4()
				filename = ''.join([str(hashed), '.png'])
				local_storage = ''.join([app.config['LOCAL_STORAGE'], str(hashed), '.png'])

				new_obj = db.CaptureObj()
				new_obj.hashcode = unicode(hashed)
				new_obj.url = unicode(url)
				new_obj.is_captured = 0
				new_obj.status = 1
				new_obj.filename = unicode(filename)
				new_obj.created_by = str(current_user._id)
				new_obj.captured_at = None

				#save data then call celery tasks
				new_obj.save()

				#call celery tasks
				capture_image.delay(str(hashed), True)

				return RestHelper().build_response(200, 200, {'img_key': new_obj.hashcode}, 'Success :p')
	
		else:
			return RestHelper().build_response(412, 412, {}, 'Url required!')

	else:
		return RestHelper().build_response(403, 403, {}, 'Unauthorized!')
Пример #2
0
def auth_user():
	login_form = LoginForm(csrf_enabled = False)
	if login_form.validate_on_submit():
		user = db.User.find_one({'$or':[{'username':login_form.username.data}, {'email':login_form.username.data}]})
		if user:
			#check password hash is valid or not
			if HashHelper().check_md5_hash(login_form.password.data, user.password):
				#renew token and save and return data
				user.token_key = unicode(HashHelper().generate_random_string(32))
				user.save()
				return RestHelper().build_response(200, 200, {"token_key": user.token_key}, 'Yay... you have been authenticate, please use your token wisely')
			else:
				return RestHelper().build_response(403, 403, {}, 'So sorry, we can\'t match your password with your email account')
		else:
			return RestHelper().build_response(403, 403, {}, 'Your username or email are not found, we can\'t authenticate, so sorry')
Пример #3
0
        def decorated_function(*args, **kwargs):
            #check token is valid or not
            token = ''
            if method == 'POST' and 'token' in request.form:
                token = request.form['token']
            if method == 'GET' and request.args.get('token') != None:
                token = request.args.get('token')

            if token == '' or token == None:
                return RestHelper().build_response(412, 412, {},
                                                   'Token required')
            else:
                #check
                if token == app.config['ACCESS_TOKEN']:
                    return f(*args, **kwargs)
                else:
                    return RestHelper().build_response(403, 403, {},
                                                       'Unauthorized!')
Пример #4
0
def capturedong():
	current_user = db.User.find_one({'token_key':request.form['token']})
	if current_user:
		if request.method == 'POST' and 'url' in request.form:
			url = request.form['url']
			if url != '':
				hashed = uuid4()
				imgcapture = Captureimg()
				filename = ''.join([str(hashed), '.png'])
				local_storage = imgcapture.capture_img(url, hashed)
				if filename and filename != '':
					#create new capture image obj
					new_obj = db.CaptureObj()
					new_obj.hashcode = unicode(hashed)
					new_obj.url = unicode(url)
					new_obj.is_captured = 1
					new_obj.status = 1
					new_obj.filename = unicode(filename)
					new_obj.local_storage = unicode(local_storage)
					new_obj.created_by = str(current_user._id)
					new_obj.captured_at = datetime.now()

					#push to amazon s3
					s3helper = S3Helper()
					upload = s3helper.upload(filename, ''.join([str(hashed), '.png']), app.config['S3_UPLOAD_DIRECTORY'])

					if upload:
						new_obj.aws_path = unicode(''.join([app.config['S3_LOCATION'], app.config['S3_BUCKET'], '/', app.config['S3_UPLOAD_DIRECTORY'], '/', str(hashed), '.png']))

					print new_obj

					#save obj after push to amazon s3
					new_obj.save()

					return RestHelper().build_response(200, 200, {'img_key': new_obj.hashcode, 'aws_url':new_obj.aws_path}, 'Success :p')
				else:
					return RestHelper().build_response(500, 500, {}, 'Image not captured, damn')	
	
		else:
			return RestHelper().build_response(412, 412, {}, 'Url required!')

	else:
		return RestHelper().build_response(403, 403, {}, 'Unauthorized!')
Пример #5
0
        def decorated_function(*args, **kwargs):
            #check token is valid or not
            token = ''
            if method == 'POST' and 'token' in request.form:
                token = request.form['token']
            if method == 'GET' and request.args.get('token') != None:
                token = request.args.get('token')

            if token == '' or token == None:
                return RestHelper().build_response(412, 412, {},
                                                   'Token required')
            else:
                #check
                user = db.User.find_one({"token_key": token})
                if user:
                    return f(*args, **kwargs)
                else:
                    return RestHelper().build_response(403, 403, {},
                                                       'Unauthorized!')
Пример #6
0
def adduser():
	register_form = RegisterForm(csrf_enabled=False)
	if register_form.validate_on_submit():
		cek_user = db.User.find_one({'$or':[{"username":register_form.username.data}, {"email":register_form.email.data}]})
		if cek_user:
			return RestHelper().build_response(403, 403, {}, 'username or email already exists')
		else:
			new_user = db.User()
			#print register_form.username.data
			new_user.username = unicode(register_form.username.data)
			new_user.email = unicode(register_form.email.data)
			new_user.password = unicode(HashHelper().generate_md5_hash(register_form.password.data))
			new_user.token_key = unicode(HashHelper().generate_random_string(32))
			#print new_user
			#save
			new_user.save()

			return RestHelper().build_response(200, 200, {"token_key": new_user.token_key}, 'Success add you as user :p')
	else:
		return RestHelper().build_response(412, 412, register_form.errors, 'hmm... we missing some params')
Пример #7
0
def ambilindong():
	if request.args.get('img_key') != None:
		img_key = request.args.get('img_key')
		#get img key
		img = db.CaptureObj.find_one({'hashcode':img_key})
		if img:
			#return all capture obj data
			img_data = {
				'img_key' : img.hashcode,
				'url': img.url,
				'created_at': img.created_at,
				'is_captured': img.is_captured,
				'captured_at': img.captured_at,
				'status': img.status,
				'uploaded_to_aws': img.uploaded_to_aws,
				'aws_path': img.aws_path,
				'local_storage': img.local_storage,
				'filename': img.filename
			}
			return RestHelper().build_response(200, 200, img_data, 'we found it :p')
		else:
			return RestHelper().build_response(404, 404, {}, 'Image not found')
	else:
		return RestHelper().build_response(412, 412, {}, 'img_key params required')
Пример #8
0
def image_resize():
    file = request.files['image']
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)

        random_name = ''.join(
            random.choice(string.ascii_lowercase) for _ in range(10))

        filename = ''.join([random_name, os.path.splitext(filename)[1]])
        upload_path = os.path.abspath(
            os.path.join(app.config['UPLOAD_STORAGE'], filename))

        # Save
        file.save(upload_path)

        destination_path = os.path.abspath(
            os.path.join(app.config['IMAGE_STORAGE'], random_name))
        os.makedirs(destination_path)

        # With compress params?
        if request.form['compress'] == 'true':
            small_240x180 = ImageResizer().resize_image(
                upload_path, ImageResizer.small_240x180,
                ImageResizer.small_240x180_name, destination_path, True)
            small_320x240 = ImageResizer().resize_image(
                upload_path, ImageResizer.small_320x240,
                ImageResizer.small_320x240_name, destination_path, True)
            medium_640x480 = ImageResizer().resize_image(
                upload_path, ImageResizer.medium_640x480,
                ImageResizer.medium_640x480_name, destination_path, True)
            medium_800x600 = ImageResizer().resize_image(
                upload_path, ImageResizer.medium_800x600,
                ImageResizer.medium_800x600_name, destination_path, True)
            large_1024x768 = ImageResizer().resize_image(
                upload_path, ImageResizer.large_1024x768,
                ImageResizer.large_1024x768_name, destination_path, True)
            large_1600x1200 = ImageResizer().resize_image(
                upload_path, ImageResizer.large_1600x1200,
                ImageResizer.large_1600x1200_name, destination_path, True)
        else:
            small_240x180 = ImageResizer().resize_image(
                upload_path, ImageResizer.small_240x180,
                ImageResizer.small_240x180_name, destination_path)
            small_320x240 = ImageResizer().resize_image(
                upload_path, ImageResizer.small_320x240,
                ImageResizer.small_320x240_name, destination_path)
            medium_640x480 = ImageResizer().resize_image(
                upload_path, ImageResizer.medium_640x480,
                ImageResizer.medium_640x480_name, destination_path)
            medium_800x600 = ImageResizer().resize_image(
                upload_path, ImageResizer.medium_800x600,
                ImageResizer.medium_800x600_name, destination_path)
            large_1024x768 = ImageResizer().resize_image(
                upload_path, ImageResizer.large_1024x768,
                ImageResizer.large_1024x768_name, destination_path)
            large_1600x1200 = ImageResizer().resize_image(
                upload_path, ImageResizer.large_1600x1200,
                ImageResizer.large_1600x1200_name, destination_path)

        return_data = {
            'small_240x180': small_240x180,
            'small_320x240': small_320x240,
            'medium_640x480': medium_640x480,
            'medium_800x600': medium_800x600,
            'large_1024x768': large_1024x768,
            'large_1600x1200': large_1600x1200
        }

        return RestHelper().build_response(
            200, 200, return_data, 'Wohooo, you got many size of your image!')
Пример #9
0
def index():
    return RestHelper().build_response(
        200, 200, {}, 'Ready for resize, crop, and compress your image?')
Пример #10
0
def index():
    return RestHelper().build_response(200, 200, {}, 'Hi mate... ')
Пример #11
0
def method_not_allowed(e):
    return RestHelper().build_response(405, 405, {},
                                       "Method not method not allowed!")
Пример #12
0
def page_not_found(e):
    #return render_template('404.html'), 404
    return RestHelper().build_response(404, 404, {},
                                       'API End point not found!')
Пример #13
0
def index():
	return RestHelper().build_response(200, 200, {}, 'Umm... hi mate, want to capture some web page?')
Пример #14
0
		for img in images:
			new_obj = {
				'img_key' : img.hashcode,
				'url': img.url,
				'created_at': img.created_at,
				'is_captured': img.is_captured,
				'captured_at': img.captured_at,
				'status': img.status,
				'uploaded_to_aws': img.uploaded_to_aws,
				'aws_path': img.aws_path,
				'local_storage': img.local_storage,
				'filename': img.filename
			}

			return_data.append(new_obj)
		return RestHelper().build_response(200, 200, {"images":return_data}, 'We found it!')
			
	else:
		return RestHelper().build_response(404, 404, {}, 'Data not found!')

@apis.route('/capture', methods=['POST'])
@token_required('POST')
def capture_queue():
	current_user = db.User.find_one({'token_key':request.form['token']})
	if current_user:
		if request.method == 'POST' and 'url' in request.form:
			url = request.form['url']
			if url != '':
				hashed = uuid4()
				filename = ''.join([str(hashed), '.png'])
				local_storage = ''.join([app.config['LOCAL_STORAGE'], str(hashed), '.png'])
Пример #15
0
def index():
    return RestHelper().build_response(200, 200, {}, 'Potongin.')