def update(self, environ, params): try: req = Controller().getRequest() router = Controller().getRouter() b = BlobFactory.get(params['bid']) if not b: output.error('blob not found', 404) cT = req.headers['Content-Type'] or 'application/octet-stream' BlobFactory.update( params['bid'], b.type, 'draft', req.body, cT, activity=b.activity ) resultUrl = router.getRoute('graph.Blob.fetch', { 'version': params['version'], 'bid': params['bid'], 'release': 'draft' }) output.success({ 'url': resultUrl, 'blobId': params['bid'] }, 202) except Error: pass return Controller().getResponse(True)
def delete(self, environ, params): try: Controller().checkToken() if Controller().getApiType() != 1: output.error("Not your api business", 403) u = UserFactory.get(params["uid"]) if not u: output.error("user not found", 404) uid = params["uid"] blobId = BlobFactory.getBlobIds(user=params["uid"], release="published", type="avatar") if not len(blobId): output.error("avatar not found", 404) blobId = blobId.pop() BlobFactory.delete(blobId, "published") UserFactory.setAvatar(u.uid, False) output.success("avatar deleted", 200) except Error: pass return Controller().getResponse(True)
def set(self, environ, params): try: Controller().checkToken() req = Controller().getRequest() router = Controller().getRouter() u = UserFactory.get(params["uid"]) if not u: output.error("user not found", 404) cT = req.headers["Content-Type"] or "application/octet-stream" blobId = BlobFactory.getBlobIds(user=params["uid"], release="published", type="avatar") if not len(blobId): blobId = BlobFactory.insert("avatar", "published", req.body, cT, user=params["uid"]) else: blobId = blobId[0] BlobFactory.update(blobId, "avatar", "published", req.body, cT, user=params["uid"]) UserFactory.setAvatar(u.uid, True) resultUrl = router.getRoute( "graph.Blob.fetch", {"version": params["version"], "bid": str(blobId), "release": "published"} ) output.success({"url": resultUrl, "blobId": str(blobId)}, 201) except Error: pass return Controller().getResponse(True)
def delete(self, environ, params): try: b = BlobFactory.get(params['bid']) if not b: output.error('blob not found', 404) BlobFactory.delete(params['bid']) output.success('blob deleted', 202) except Error: pass return Controller().getResponse(True)
def save(self, environ, params): try: req = Controller().getRequest() router = Controller().getRouter() a = ActivityFactory.get(params['rid']) if not a: output.error('activity not found', 404) cT = req.headers['Content-Type'] or 'application/octet-stream' blobId = BlobFactory.insert( 'attachments', 'draft', req.body, cT, activity=params['rid'] ) resultUrl = router.getRoute('graph.Blob.fetch', { 'version': params['version'], 'bid': str(blobId), 'release': 'draft' }) output.success({ 'url': resultUrl, 'blobId': str(blobId) }, 201) except Error: pass return Controller().getResponse(True)
def publish(self, environ, params): try: req = Controller().getRequest() a = ActivityFactory.get(params['rid']) if not a: output.error('not found', 404) a.publish() for (blobType, values) in a.published['blobs'].items(): for blobId in values: BlobFactory.publish(blobId) ActivityFactory.update(a) output.success(a.toObject(), 200) except Error: pass return Controller().getResponse(True)
def get(self, environ, params): try: req = Controller().getRequest() blobId = BlobFactory.getBlobIds(user=params["uid"], release="published", type="avatar") if not len(blobId): output.error("avatar not found", 404) blobId = blobId.pop() b = BlobFactory.get(blobId, "published") resp = Controller().getResponse() resp.headers["Content-Type"] = b.content_type resp.body = b.read() except Error: pass return Controller().getResponse(True)
def fetch(self, environ, params): try: req = Controller().getRequest() b = BlobFactory.get(params['bid'], params['release']) if not b: output.error('blob not found', 404) resp = Controller().getResponse() resp.headers['Content-Type'] = b.content_type resp.body = b.read() except Error: pass return Controller().getResponse(True)