Пример #1
0
    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)
Пример #2
0
    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)