Esempio n. 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)
Esempio n. 2
0
    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)
Esempio n. 3
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)