Пример #1
0
from django.core.exceptions import ObjectDoesNotExist

import magic
import logging
import json
import hashlib
import datetime
import socket

log = logging.getLogger(__name__)
MEDIA_DIR = "/home/simon/Photon/"

mime_magic = magic.Magic(mime=True)
hasher = hashlib.sha1()
file_storage = FileSystemStorage(location=MEDIA_DIR)
file_storage.file_permission_mode=644

# Ping endpoint
# /photon/api/vX.X/info
def info(request):
    info = {}
    info['time'] = datetime.datetime.now().isoformat()
    info['version'] = "v1.0"
    info['host'] = socket.gethostname()
    return JsonResponse(info)

# Get metadata by hash
# /photon/api/vX.X/<hash>/meta
def get_metadata_by_hash(request, hash):
    try:
        image_entity = ImageEntity.objects.get(hash=hash)