<commit_before>from flask.ext import restful
from . import db
from flask import abort, request

class DocumentResource(restful.Resource):

    def get(self):

        documents = [
            {
                'name': document['name'],
                'size': document['size'],
                'uploaded': document['uploaded'].strftime('%Y-%m-%d %H:%M:%S')
            } for document in db.get_all_documents()
        ]

        return {'documents': documents}

    def post(self):

        file = request.files['file']

        if not file:

            abort(400)

        filename = secure_filename(file.filename)

        if not os.path.exists('/tmp/uploaded/'):

            os.makedirs('/tmp/uploaded/')

        path = os.path.join('/tmp/uploaded/', filename)

        file.save(path)

        db.add_document(path)

        return ''<commit_msg>Updated the document resource for the new libredb<commit_after>from flask.ext import restful
from . import database
from flask import abort, request
from werkzeug import secure_filename
import os

class DocumentResource(restful.Resource):

    def get(self):

        documents = [
            {
                'id': document['id'],
                'name': document['name'],
                'size': document['size'],
                'path': document['path'],
                'uploaded': document['upload_time'].strftime('%Y-%m-%d %H:%M:%S')
            } for document in database.get_all_documents()
        ]

        return {'documents': documents}

    def post(self):

        file = request.files['file']

        if not file:

            abort(400)

        filename = secure_filename(file.filename)

        if not os.path.exists('/tmp/uploaded/'):

            os.makedirs('/tmp/uploaded/')

        path = os.path.join('/tmp/uploaded/', filename)

        file.save(path)

        database.add_document(path)

        documents = [
            {
                'id': document['id'],
                'name': document['name'],
                'size': document['size'],
                'path': document['path'],
                'uploaded': document['upload_time'].strftime('%Y-%m-%d %H:%M:%S')
            } for document in database.get_all_documents()
        ]

        return {'documents': documents}
{'fraction_non_alphanumeric': 0.13901147396293026, 'fraction_numerical': 0.00264783759929391, 'mean_word_length': 1.9026888604353394, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5490435', 'n_tokens_mistral': 661, 'n_tokens_neox': 604, 'n_words': 137}