Example #1
0
    def uris(self):
        if self.remote:
            return URIs(id=self.ap_id)

        return URIs(
            id=uri("user", {"username": self.username}),
            following=uri("following", {"username": self.username}),
            followers=uri("followers", {"username": self.username}),
            outbox=uri("outbox", {"username": self.username}),
            inbox=uri("inbox", {"username": self.username}),
            atom=uri("atom", {"username": self.username}),
            avatar=self.avatar,
            featured=uri("featured", {"username": self.username}),
        )
Example #2
0
    def uris(self):
        if self.is_remote:
            return URIs(id=self.ap_id,
                        inbox=f'{self.ap_id}/inbox',
                        outbox=f'{self.ap_id}/inbox',
                        following=f'{self.ap_id}/following',
                        followers=f'{self.ap_id}/followers')

        return URIs(id=uri("user", {"username": self.username}),
                    following=uri("following", {"username": self.username}),
                    followers=uri("followers", {"username": self.username}),
                    outbox=uri("outbox", {"username": self.username}),
                    inbox=uri("inbox", {"username": self.username}),
                    atom=uri("atom", {"id": self.id}),
                    featured=uri("featured", {"username": self.username}),
                    avatar=uri('profile_image', {"name": self.avatar_file}))
Example #3
0
 def uris(self):
     if self.remote:
         ap_id = self.ap_id
     else:
         ap_id = uri("activity", {
             "username": self.person.username,
             "id": self.id
         })
     return URIs(id=ap_id)
Example #4
0
 def uris(self):
     return URIs(media=uri("media", {
         "id": self.media_name,
         "extension": self.extension
     }),
                 preview=uri("preview", {
                     "id": self.media_name,
                     "extension": self.extension
                 }))
Example #5
0
 def uris(self):
     from models.media import Media
     if self.remote:
         ap_id = self.ap_id
     else:
         ap_id = uri("status", {"username":self.user.username, "id":self.id})
     return URIs(id=ap_id,
                 media=[uri.uris.media for uri in self.media_object],
                 preview=[uri.uris.preview for uri in self.media_object]
                 )
Example #6
0
    async def post(self):

        user = self.current_user
        if not 'file' in self.request.files.keys():
            
            self.write({"Error": "File not provided"})
            self.set_status(422)
            return
            
        image = self.request.files['file'][0]

        # Search for a valid id 
        valid = False
        ident = ""
        while not valid:

            try:
                ident = str(uuid.uuid4())
                media = await self.application.objects.get(Media, media_name = ident)
            except Media.DoesNotExist:
                valid = True # If we are here that means that the object exits


        manager = MediaManager(self.request.files['file'][0]['body'])

        valid = manager.is_valid()

        if valid:
            description = self.get_argument('description', '')
            focus = (0,0)
            if self.get_argument('focus', False):
                args = self.get_argument('focus').replace(" ", "").split(',')
                if len(args) == 2:
                    focus = args[:2]

            extension = manager.get_media_type()
            
            urls = URIs(
                media=uri("media", {"id":ident, "extension": extension}),
                preview=uri("preview", {"id":ident, "extension": extension})
            )
            m = {
                "description": description,
                "id": ident, 
                "type": "unknown",
                "url": urls.media,
                "preview_url": urls.preview,
                "meta": None
            }   
            store_media(manager, ident, description, focus)

            self.write(json.dumps(m, default=str))
            self.set_status(200)
        else:
            raise CustomError(reason="Error storing files", status_code=400)
Example #7
0
 def uris(self):
     if self.remote:
         ap_id = self.ap_id
     else:
         ap_id = uri("status", {
             "username": self.user.username,
             "id": self.id
         })
     return URIs(id=ap_id,
                 media=uri("media", {"id": self.media_name}),
                 preview=uri("preview", {"id": self.media_name}))
Example #8
0
 def uris(self):
     return URIs(media=uri("media", {"id": self.media_name}),
                 preview=uri("preview", {"id": self.media_name}))