예제 #1
0
파일: test_api.py 프로젝트: imgtl/imgtl
 def setUpClass(cls):
     os.environ['TESTING'] = 'true'
     from api import app, db
     cls.app = app.test_client()
     db.create_all()
     # add default user
     db.session.add(User(email='*****@*****.**', name='tests', password=pw_hash('password1234'), token='THISISTESTTOKEN'))
     db.session.commit()
예제 #2
0
 def setUpClass(cls):
     os.environ['TESTING'] = 'true'
     from web import app, db
     cls.app = app.test_client()
     db.create_all()
     # add default user
     db.session.add(User(email='*****@*****.**', name='tests', password=pw_hash('password1234')))
     db.session.commit()
예제 #3
0
            'uploads_count': user.uploads.count()
        }
        if args['with_uploads'] == 1:
            uploads = []
            for upload in user.uploads:
                uploads.append({
                    'type': upload.object.__tablename__,
                    'url': {
                        'page': BASE_URL % upload.url,
                        'direct': upload.direct_url
                    },
                    'title': upload.title,
                    'desc': upload.desc,
                    'upload_at': upload.time.strftime('%s'),
                    'view_count': upload.view_count,
                    'properties': upload.object.prop
                })
            res['uploads'] = uploads
        return success({'user': res})


api.add_resource(Index, '/')
api.add_resource(Upload, '/upload')
api.add_resource(TweetbotUpload, '/tweetbot')
api.add_resource(Url, '/url/<string:url>')
api.add_resource(UserInfo, '/user/info')

if __name__ == '__main__':
    db.create_all()
    app.run(host='127.0.0.1', port=2561)
예제 #4
0
파일: web.py 프로젝트: imgtl/imgtl
    upload = get_upload(current_user, url)
    if isinstance(upload, int):
        abort(upload)
    obj = upload.object
    if isinstance(obj, Image):
        if obj.ext != ext:
            abort(404)
        r = make_response()
        r.headers['Cache-Control'] = 'public'
        r.headers['Content-Type'] = ''
        r.headers['Content-Disposition'] = 'inline; filename="%s"' % upload.title.encode('utf8')
        r.headers['X-Accel-Redirect'] = imgtl.lib.get_spath('/x', obj.code)
        return r

@app.route('/thumb/<url>')
def show_thumbnail(url):
    upload = get_upload(current_user, url)
    if isinstance(upload, int):
        abort(upload)
    obj = upload.object
    r = make_response()
    r.headers['Cache-Control'] = 'public'
    r.headers['Content-Type'] = ''
    r.headers['Content-Disposition'] = 'inline; filename="%s"' % upload.title.encode('utf8')
    r.headers['X-Accel-Redirect'] = imgtl.lib.get_spath('/x/thumb', obj.code)
    return r

if __name__ == '__main__':
    db.create_all()
    app.run(host='127.0.0.1', port=2560)