<commit_before>import os
import datetime
from flask import abort, request, g
from werkzeug import secure_filename
from . import config, PhotoModel, AlbumModel, AuthenticatedResource
class PhotoInstance (AuthenticatedResource):

    def get (self, id):

        if PhotoModel.select().where(PhotoModel.id == id).count() != 1:

            abort(404)

        photo = PhotoModel.get(PhotoModel.id == id)

        return {'id': photo.id, 'name': photo.name, 'uploaded': photo.uploaded.strftime("%Y-%m-%d %H:%M:%S"), 'size': photo.size}

class PhotosResource (AuthenticatedResource):

    def post (self):

        album = request.form.get('album')
        file = request.files.get('file')

        if not album or not file:

            abort(400)

        if AlbumModel.select().where(AlbumModel.id == album).count() != 1:

            abort(404)

        album = AlbumModel.get(AlbumModel.id == album)

        filename = secure_filename(file.filename)

        photo = PhotoModel.create(
            name = filename,
            size = 0,
            album = album,
            user = g.user
        )

        path = os.path.join(config.get('Photos', 'ProcessingDirectory'), str(photo.id))
        file.save(path)

        photo.size = os.stat(path).st_size<commit_msg>Implemented DELETE on photo instances<commit_after>import os
import datetime
from flask import abort, request, g
from werkzeug import secure_filename
from . import config, PhotoModel, AlbumModel, AuthenticatedResource
class PhotoInstance (AuthenticatedResource):

    def get (self, id):

        if PhotoModel.select().where(PhotoModel.id == id).count() != 1:

            abort(404)

        photo = PhotoModel.get(PhotoModel.id == id)

        return {'id': photo.id, 'name': photo.name, 'uploaded': photo.uploaded.strftime("%Y-%m-%d %H:%M:%S"), 'size': photo.size}

    def delete (self, id):

        if not g.user.admin:

            abort(401)

        if PhotoModel.select().where(PhotoModel.id == id).count() != 1:

            abort(404)

        photo = PhotoModel.get(PhotoModel.id == id)

        photo.delete_instance()

        return '', 204

class PhotosResource (AuthenticatedResource):

    def post (self):

        album = request.form.get('album')
        file = request.files.get('file')

        if not album or not file:

            abort(400)

        if AlbumModel.select().where(AlbumModel.id == album).count() != 1:

            abort(404)

        album = AlbumModel.get(AlbumModel.id == album)

        filename = secure_filename(file.filename)

        photo = PhotoModel.create(
            name = filename,
            size = 0,
            album = album,
            user = g.user
        )

        path = os.path.join(config.get('Photos', 'ProcessingDirectory'), str(photo.id))
        file.save(path)

        photo.size = os.stat(path).st_size
{'fraction_non_alphanumeric': 0.12933753943217666, 'fraction_numerical': 0.011917280056081317, 'mean_word_length': 2.3895486935866983, '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': '4956443', 'n_tokens_mistral': 881, 'n_tokens_neox': 812, 'n_words': 200}