Ejemplo n.º 1
0
def store_ebook(user_id, sdbkey, filehash, fmt):
    user = User.query.get(user_id)

    filepath = "%s/%s%s" % (app.config['UPLOADED_EBOOKS_DEST'], filehash, fmt)

    print "store_ebook: %s %s%s" % (sdbkey, filehash, fmt)

    # store the file into S3
    ds = DataStore(user)
    ds.store_ebook(sdbkey, filehash, filepath)

    # handle badge and reputation changes
    r = Reputation(user)
    r.earn_badges()
Ejemplo n.º 2
0
def post():
    try:
        # authenticate user
        user = User.validate_auth_key(username=request.form.get("username"),
                                      api_key=request.form.get("api_key"))
        if user is None:
            return "API Auth Failed: Post"

        # decode the json payload
        data = json.loads(request.form.get("ebooks"))

    except KeyError:
        return "Bad Request"

    # stats log the upload
    Log.create(user.id, "CONNECT", request.form.get("total"),
               request.form.get("api_key"))

    # update the library
    ds = DataStore(user)
    new_ebook_count = ds.update_library(data)
    Log.create(user.id, "NEW", new_ebook_count, request.form.get("api_key"))

    # handle badge and reputation changes
    r = Reputation(user)
    r.new_ebooks(new_ebook_count)
    r.earn_badges()
    msgs = r.get_new_badges()

    # query books missing from S3 and supply back to the client
    rs = ds.find_missing_books()
    return json.dumps({'ebooks_to_upload': rs, 'messages': msgs})
Ejemplo n.º 3
0
def post():
    try:
        # authenticate user
        user = User.validate_auth_key(
            username=request.form.get("username"),
            api_key=request.form.get("api_key")
        )
        if user is None:
            return "API Auth Failed: Post"

        # decode the json payload
        data = json.loads(request.form.get("ebooks"))

    except KeyError:
        return "Bad Request"

    # stats log the upload
    Log.create(user.id, "CONNECT", request.form.get("total"), request.form.get("api_key"))

    # update the library
    ds = DataStore(user)
    new_ebook_count = ds.update_library(data)
    Log.create(user.id, "NEW", new_ebook_count, request.form.get("api_key"))

    # handle badge and reputation changes
    r = Reputation(user)
    r.new_ebooks(new_ebook_count)
    r.earn_badges()
    msgs = r.get_new_badges()

    # query books missing from S3 and supply back to the client
    rs = ds.find_missing_books()
    return json.dumps({
        'ebooks_to_upload': rs,
        'messages': msgs
    })