51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
import os
|
|
import cherrypy
|
|
import logging
|
|
from datetime import datetime, timedelta
|
|
from photoapp.library import PhotoLibrary
|
|
from photoapp.types import Photo, PhotoSet, Tag, TagItem, PhotoStatus, User
|
|
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
|
from sqlalchemy import desc
|
|
from sqlalchemy import func, and_, or_
|
|
from photoapp.common import pwhash
|
|
import math
|
|
from urllib.parse import urlparse
|
|
from photoapp.utils import mime2ext, auth, require_auth, photo_auth_filter, slugify
|
|
from photoapp.dbutils import db
|
|
|
|
|
|
class PhotosApi(object):
|
|
def __init__(self):
|
|
self.v1 = PhotosApiV1()
|
|
|
|
|
|
class PhotosApiV1(object):
|
|
def __init__(self):
|
|
pass
|
|
|
|
@cherrypy.expose
|
|
def index(self):
|
|
yield f"<plaintext>hello, this is the api. my database is: {db()}\n"
|
|
|
|
@cherrypy.expose
|
|
def upload(self, files, meta):
|
|
pass
|
|
|
|
@cherrypy.expose
|
|
@cherrypy.tools.json_out()
|
|
def byhash(self, sha):
|
|
f = db().query(Photo).filter(Photo.hash == sha).first()
|
|
return f.to_json()
|
|
|
|
@cherrypy.expose
|
|
@cherrypy.tools.json_out()
|
|
def set(self, uuid):
|
|
s = db().query(PhotoSet).filter(PhotoSet.uuid == uuid).first()
|
|
return s.to_json()
|
|
|
|
@cherrypy.expose
|
|
def download(self, uuid):
|
|
f = db().query(Photo).filter(Photo.uuid == uuid).first()
|
|
return cherrypy.lib.static.serve_file(os.path.abspath(os.path.join("./library", f.path)),
|
|
f.format)#TODO no hardcode path
|