Пример #1
0
def tstodate(ts):
    try:
        date = datetime.fromtimestamp(ts)
    except TypeError:
        return ''
    else:
        return isoformat(date, timespec='seconds')
Пример #2
0
    async def makePinRequest(self,
                             op,
                             title,
                             descr,
                             objects,
                             priority=0,
                             tags=None):
        async with self.profile.dagUser as dag:
            # objects needs to be a list of IPFS objects paths

            if not isinstance(objects, list):
                return False

            username = self.profile.userInfo.iphandle
            uid = str(uuid.uuid4())
            now = datetime.now(timezone.utc)

            objsReq = []

            for obj in objects:
                path = IPFSPath(obj)
                if not path.valid:
                    continue

                try:
                    mType, stat = await self._rscAnalyzer(path)
                except:
                    continue

                statInfo = StatInfo(stat)
                if not statInfo.valid:
                    continue

                objsReq.append({
                    'path': path.objPath,
                    'totalsize': statInfo.totalSize,
                    'content_type': str(mType) if mType else None
                })

            pinRequest = {
                'pinrequest': {
                    'body': None,
                    'title': title,
                    'description': descr,
                    'objects': objsReq,
                    'uuid': uid,
                    'tags': tags if tags else [],
                    'author': username,
                    'priority': priority,
                    'date_published': isoformat(now),
                    'version': 1
                }
            }

            dag.dagRoot[PINREQS_NODEKEY].append(pinRequest)

        await self.update()
        return True
Пример #3
0
    async def post(self, op, message):
        profile = op.ctx.currentProfile
        username = profile.userInfo.username

        links = []
        words = message.split()
        for word in words:
            if cidValid(word):
                links.append(joinIpfs(word))

        await self.database.add(
            {
                'author': username,
                'post': message,
                'links': links,
                'date': isoformat(datetime.now(), timespec='seconds')
            })
        self.newMessages.emit(0)
Пример #4
0
    async def blogPost(self,
                       ipfsop,
                       title,
                       msg,
                       category=None,
                       tags=None,
                       author=None):
        async with self.edag:
            sHandle = self.profile.userInfo.spaceHandle

            username = sHandle.human
            uid = str(uuid.uuid4())
            postName = titleToPostName(title.strip().lower())

            exEntries = await self.blogEntries()
            if not postName or postName in exEntries:
                raise Exception('A blog post with this name already exists')

            now = datetime.now(timezone.utc)

            postObject = {
                'blogpost': {
                    'authordid': self.profile.userInfo.personDid,
                    'body': msg,
                    'title': title,
                    'uuid': uid,
                    'postname': postName,  # name of the post's DAG node
                    'tags': tags if tags else [],
                    'category': None,
                    'author': author if author else username,
                    'date_published': isoformat(now),
                    'date_modified': isoformat(now)
                }
            }

            # Create the DAG node for this post
            # Its view will be rendered later on

            self.dagBlog[postName] = {POST_NODEKEY: postObject}

        await ipfsop.sleep(2)
        await self.update()
        await ipfsop.sleep(1)

        result = await self.dagUser.resolve(
            posixIpfsPath.join(BLOG_NODEKEY, postName, 'view'))
        resolved = IPFSPath(result, autoCidConv=True)

        if isinstance(tags, list) and resolved.isIpfsRoot and resolved.valid:
            # Register the post by tag

            async with self.edag as dag:
                byTags = dag.root[BLOG_NODEKEY][TAGS_NODEKEY]

                for tag in tags:
                    if tag is None:
                        continue

                    planet, ptag = tag.split('#')
                    if not planet or not ptag:
                        continue

                    planet = planet.replace('@', '')

                    byTags.setdefault(planet, {})
                    byTags[planet].setdefault(ptag, {'_posts': []})

                    byTags[planet][ptag]['_posts'].append({
                        'name': postName,
                        'title': title,
                        'view': {
                            '/': stripIpfs(str(resolved))
                        }
                    })
                    byTags[planet][ptag]['index.html'] = await self.renderLink(
                        'usersite/bytag.html',
                        contained=True,
                        tag=tag,
                        tagposts=byTags[planet][ptag]['_posts'])

        logUser.info('Your blog post is online')
        return True
Пример #5
0
 def makeDatetime(self, date=None):
     datet = date if date else datetime.now()
     return isoformat(datet)