hash, set, and file retrival endpoints

This commit is contained in:
dave 2019-06-18 18:38:01 -07:00
parent 16271aa54a
commit 91b84710a4
2 changed files with 30 additions and 6 deletions

View File

@ -21,10 +21,6 @@ class PhotosApi(object):
class PhotosApiV1(object):
def __init__(self):
# self.tpl.filters.update(mime2ext=mime2ext,
# basename=os.path.basename,
# ceil=math.ceil,
# statusstr=lambda x: str(x).split(".")[-1])
pass
@cherrypy.expose
@ -37,5 +33,18 @@ class PhotosApiV1(object):
@cherrypy.expose
@cherrypy.tools.json_out()
def findbysha(self, sha):
pass
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

View File

@ -33,6 +33,15 @@ class PhotoSet(Base):
status = Column(Enum(PhotoStatus), default=PhotoStatus.private)
def to_json(self):
s = {attr: getattr(self, attr) for attr in {"uuid", "title", "description"}}
s["lat"] = str(self.lat)
s["lon"] = str(self.lon)
s["date"] = self.date.isoformat()
s["files"] = {i.uuid: i.to_json() for i in self.files}
s["tags"] = [t.name for t in self.tags]
return s
class Photo(Base):
__tablename__ = 'files'
@ -51,6 +60,12 @@ class Photo(Base):
path = Column(Unicode)
format = Column(String(length=64)) # TODO how long can a mime string be
def to_json(self):
j = {attr: getattr(self, attr) for attr in
{"uuid", "size", "width", "height", "orientation", "format"}}
j["set"] = self.set.uuid
return j
class Tag(Base):
__tablename__ = 'tags'