Esempio n. 1
0
def export(id):
    try:
        picture = Picture.get(Picture.id==id)
    except Picture.DoesNotExist:
        return 'Not found', 404

    result = ImageHelper.compile_image(picture)
    return send_file(result, mimetype='image/png')
Esempio n. 2
0
def export(id):
    try:
        picture = Picture.get(Picture.id == id)
    except Picture.DoesNotExist:
        return 'Not found', 404

    result = ImageHelper.compile_image(picture)
    return send_file(result, mimetype='image/png')
Esempio n. 3
0
def upload():
    if not g.authorized or g.user.pictures.count() >= current_app.config['MAX_UPLOADS']:
        return 'error', 500

    f = request.files['pic']
    if f and allowed_file(f.filename):
        with get_db().atomic() as txn:
            pic, size = ImageHelper.resize(f, current_app.config['IMAGE_WIDTH'])
            picture = Picture.create(
                user=g.user,
                width=size[0],
                height=size[1],
                image=pic.getvalue())
        return jsonify(result='ok', url=url_for('render', _external=True, id=picture.id))
    else:
        return jsonify(result='error'), 500
Esempio n. 4
0
def upload():
    if not g.authorized or g.user.pictures.count(
    ) >= current_app.config['MAX_UPLOADS']:
        return 'error', 500

    f = request.files['pic']
    if f and allowed_file(f.filename):
        with get_db().atomic() as txn:
            pic, size = ImageHelper.resize(f,
                                           current_app.config['IMAGE_WIDTH'])
            picture = Picture.create(user=g.user,
                                     width=size[0],
                                     height=size[1],
                                     image=pic.getvalue())
        return jsonify(result='ok',
                       url=url_for('render', _external=True, id=picture.id))
    else:
        return jsonify(result='error'), 500
Esempio n. 5
0
def img(id):
    try:
        picture = Picture.get(Picture.id == id)
    except Picture.DoesNotExist:
        return 'Not found', 404

    if not g.authorized or picture.user.id != g.user.id: return 'error', 500

    insta_img = request.args.get('insta_img')  # check root!
    insta_id = request.args.get('insta_id')
    insta_url = request.args.get('insta_url').split('/')[-2]  # remain just id
    insta_user = request.args.get('insta_user')

    insta_url_re = re.compile(current_app.config['ALLOWED_INSTA_URL'])
    if not insta_url_re.match(insta_url):
        return 'Wrong url', 500

    free_fragments = picture.fragments.where(Fragment.x == None)
    overcome = free_fragments.count() - current_app.config['MAX_CACHED_PHOTOS']

    if overcome >= 0:
        to_remove = [f.id for f in free_fragments.limit(overcome + 1)]
        Fragment.delete().where(Fragment.id << to_remove,
                                Fragment.x == None).execute()

    result = ImageHelper.get_new_image(insta_img)

    if result != None:
        fragment = Fragment.create(picture=picture,
                                   insta_img=insta_img,
                                   insta_id=insta_id,
                                   insta_url=insta_url,
                                   insta_user=insta_user,
                                   high_pic=result[0],
                                   low_pic=result[1])

        return jsonify(fragment.to_hash())
    else:
        return 'Cannot download image', 500
Esempio n. 6
0
def img(id):
    try:
        picture = Picture.get(Picture.id==id)
    except Picture.DoesNotExist:
        return 'Not found', 404

    if not g.authorized or picture.user.id != g.user.id: return 'error', 500
    
    insta_img = request.args.get('insta_img') # check root!
    insta_id = request.args.get('insta_id')
    insta_url = request.args.get('insta_url').split('/')[-2] # remain just id
    insta_user = request.args.get('insta_user')

    insta_url_re = re.compile(current_app.config['ALLOWED_INSTA_URL'])
    if not insta_url_re.match(insta_url):
        return 'Wrong url', 500

    free_fragments = picture.fragments.where(Fragment.x == None)
    overcome = free_fragments.count() - current_app.config['MAX_CACHED_PHOTOS']

    if overcome >= 0:
        to_remove = [f.id for f in free_fragments.limit(overcome + 1)]
        Fragment.delete().where(Fragment.id << to_remove, Fragment.x == None).execute()

    result = ImageHelper.get_new_image(insta_img)

    if result != None:
        fragment = Fragment.create(picture=picture,
                                   insta_img=insta_img,
                                   insta_id=insta_id,
                                   insta_url=insta_url,
                                   insta_user=insta_user,
                                   high_pic=result[0],
                                   low_pic=result[1])

        return jsonify(fragment.to_hash())
    else:
        return 'Cannot download image', 500