コード例 #1
0
ファイル: iprofile.py プロジェクト: atavacron/galacteek
    async def setIcon(self, op, fp):
        entry = await op.addPath(fp, recursive=False)
        if not entry:
            return

        async with self.profile.userInfo as dag:
            dag.curIdentity['avatar'] = dag.mkLink(entry['Hash'])

        await op.sleep(2)
        await self.loadIcon()

        # Update the avatar DID service
        ipid = await self.profile.userInfo.ipIdentifier()
        avatarServiceId = ipid.didUrl(path='/avatar')

        if not await ipid.searchServiceById(avatarServiceId):
            await ipid.addServiceRaw(
                {
                    'id': avatarServiceId,
                    'type': IPService.SRV_TYPE_AVATAR,
                    'serviceEndpoint': joinIpfs(entry['Hash']),
                    'description': 'User Avatar'
                },
                publish=True)
        else:
            async with ipid.editService(avatarServiceId) as editor:
                editor.service['serviceEndpoint'] = joinIpfs(entry['Hash'])
コード例 #2
0
ファイル: mfs.py プロジェクト: atavacron/galacteek
    def fullPath(self):
        parentHash = self.parentHash
        if parentHash:
            fp = joinIpfs(os.path.join(parentHash, self.entry['Name']))
        else:
            fp = joinIpfs(self.entry['Hash'])

        return fp + '/' if self.isDir() else fp
コード例 #3
0
ファイル: ipfsview.py プロジェクト: atavacron/galacteek
 def getFullPath(self):
     """
     Returns the full IPFS path of the entry associated with this item
     (preserving file names) if we have the parent's hash, or the IPFS path
     with the entry's hash otherwise
     """
     parentHash = self.getParentHash()
     name = self.entry['Name']
     if parentHash:
         return joinIpfs(os.path.join(parentHash, name))
     else:
         return joinIpfs(cidConvertBase32(self.entry['Hash']))
コード例 #4
0
    def getFullPath(self):
        """
        Returns the full IPFS path of the entry associated with this item
        (preserving file names) if we have the parent's hash, or the IPFS path
        with the entry's hash otherwise
        """

        if self._parentCid:
            return joinIpfs(
                posixIpfsPath.join(cidConvertBase32(self._parentCid),
                                   self.filename))
        else:
            return joinIpfs(cidConvertBase32(self.entry['Hash']))
コード例 #5
0
ファイル: dag.py プロジェクト: pinnaculum/galacteek
    def onFollowDAGLink(self, cidString):
        if not cidString:
            return messageBox(iInvalidCID())

        view = DAGViewer(cidhelpers.joinIpfs(cidString), self.app.mainWindow)
        self.app.mainWindow.registerTab(view,
                                        iDagViewer(),
                                        current=True,
                                        icon=getIcon('ipld.png'),
                                        tooltip=cidString)
コード例 #6
0
ファイル: ipfssearch.py プロジェクト: atavacron/galacteek
    async def fetchObjectStat(self, ipfsop, cid):
        path = joinIpfs(cid)

        try:
            mType, stat = await self.app.rscAnalyzer(path,
                                                     fetchExtraMetadata=True)
            if stat:
                self.objectStatAvailable.emit(cid, stat)
        except Exception:
            pass
コード例 #7
0
ファイル: iprofile.py プロジェクト: pinnaculum/galacteek
    async def setIcon(self, op, fp):
        entry = await op.addPath(fp, recursive=False)
        if not entry:
            return

        async with self.profile.userInfo as dag:
            dag.curIdentity['avatar'] = dag.mkLink(entry['Hash'])

        # Update the avatar DID service
        ipid = await self.profile.userInfo.ipIdentifier()

        await ipid.avatarSet(joinIpfs(entry['Hash']))
        await op.sleep(1)
        await self.loadIcon()
コード例 #8
0
ファイル: mediaplayer.py プロジェクト: atavacron/galacteek
    async def savePlaylist(self, ipfsop, obj, name):
        objPath = os.path.join(self.profile.pathPlaylists, name)
        exists = await ipfsop.filesStat(objPath)

        if exists:
            await ipfsop.filesRm(objPath)

        ent = await ipfsop.client.core.add_json(obj.root)

        if ent:
            await ipfsop.filesLinkFp(ent, objPath)
            self.playlistIpfsPath = joinIpfs(ent['Hash'])
            self.copyPathAction.setEnabled(True)

        self.update()
コード例 #9
0
ファイル: application.py プロジェクト: atavacron/galacteek
    async def setupRepository(self, op):
        pubsubEnabled = True  # mandatory now ..
        hExchEnabled = self.settingsMgr.isTrue(CFG_SECTION_IPFS,
                                               CFG_KEY_HASHMARKSEXCH)

        self.ipfsCtx.resources['ipfs-logo-ice'] = await self.importQtResource(
            '/share/icons/ipfs-logo-128-ice.png')
        self.ipfsCtx.resources['ipfs-cube-64'] = await self.importQtResource(
            '/share/icons/ipfs-cube-64.png')
        self.ipfsCtx.resources['atom-feed'] = await self.importQtResource(
            '/share/icons/atom-feed.png')
        self.ipfsCtx.resources['markdown-reference'] = \
            await self.importQtResource(
                '/share/static/docs/markdown-reference.html')

        await self.ipfsCtx.setup(pubsubEnable=pubsubEnabled,
                                 pubsubHashmarksExch=hExchEnabled,
                                 offline=self.offline)
        await self.ipfsCtx.profilesInit()
        await self.qSchemeHandler.start()
        await self.importLdContexts()

        self.feedFollower = FeedFollower(self)
        self.feedFollowerTask = await self.scheduler.spawn(
            self.feedFollower.process())

        await self.ipfsCtx.ipfsRepositoryReady.emit()
        self.ipfsCtx._ipfsRepositoryReady.emit()

        #
        # If the application's binary name is a valid CID, pin it!
        # This happens when running the AppImage and ensures
        # self-seeding of the image!
        #

        if isinstance(self.progName, str):
            progNameClean = re.sub(r'[\.\/]*', '', self.progName)
            if cidhelpers.cidValid(progNameClean):
                self._progCid = progNameClean
                log.debug("Auto pinning program's CID: {0}".format(
                    self.progCid))
                await self.ipfsCtx.pin(joinIpfs(self.progCid),
                                       False,
                                       self.onAppReplication,
                                       qname='self-seeding')

        if self.cmdArgs.seed and self.cmdArgs.appimage:
            await self.seedAppImage()
コード例 #10
0
    async def handleRequest(self, ipfsop, request, uid):
        if self.proxied is None:
            self.proxied = await self.getDag()

        if not self.proxied:
            return request.fail(QWebEngineUrlRequestJob.UrlInvalid)

        rUrl = request.requestUrl()
        path = rUrl.path()
        ipfsPathS = joinIpfs(self.proxied.dagCid) + path

        ipfsPath = IPFSPath(ipfsPathS)
        if not ipfsPath.valid:
            return self.urlInvalid(request)

        return await self.fetchFromPath(ipfsop, request, ipfsPath, uid)
コード例 #11
0
ファイル: __init__.py プロジェクト: pinnaculum/galacteek
    async def handleRequest(self, ipfsop, request, uid):
        rUrl = request.requestUrl()
        scheme = rUrl.scheme()
        host = rUrl.host()

        if not host:
            return self.urlInvalid(request)

        if scheme == SCHEME_IPFS:
            # hostname = base32-encoded CID or FQDN
            #
            # We keep a list (deque) of CIDs that have been validated.
            # If you hit a page which references a lot of other resources
            # for instance, this should be faster than regexp

            if domainValid(host):
                ipfsPathS = joinIpns(host) + rUrl.path()
            else:
                if host not in self.validCids:
                    if not ipfsRegSearchCid32(host):
                        return self.urlInvalid(request)

                    self.validCids.append(host)

                ipfsPathS = joinIpfs(host) + rUrl.path()
        elif scheme == SCHEME_IPNS:
            ipfsPathS = joinIpns(host) + rUrl.path()
        else:
            return self.urlInvalid(request)

        ipfsPath = IPFSPath(ipfsPathS)
        if not ipfsPath.valid:
            return self.urlInvalid(request)

        try:
            with async_timeout.timeout(self.requestTimeout):
                return await self.fetchFromPath(ipfsop, request, ipfsPath, uid)
        except asyncio.TimeoutError:
            return self.reqFailed(request)
        except Exception as err:
            # Any other error

            traceback.print_exc()
            self.debug(f'Unknown error while serving request: {err}')

            return self.reqFailed(request)
コード例 #12
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)
コード例 #13
0
    async def handleRequest(self, ipfsop, request, uid):
        if len(self.proxied) == 0:
            return self.urlInvalid(request)

        rUrl = request.requestUrl()
        path = rUrl.path()

        for dag in self.proxied:
            if not dag.dagCid:
                continue

            ipfsPathS = joinIpfs(dag.dagCid) + path
            ipfsPath = IPFSPath(ipfsPathS)

            if not ipfsPath.valid:
                return request.fail(QWebEngineUrlRequestJob.UrlInvalid)

            return await self.fetchFromPath(ipfsop,
                                            request,
                                            ipfsPath,
                                            uid,
                                            dag=dag)
コード例 #14
0
    async def encodeIpHandleQr(self, ipfsop,
                               iphandle,
                               did,
                               format='png',
                               filename=None):
        encoder = IPFSQrEncoder()

        try:
            entry = await ipfsop.addString(iphandle, pin=True, only_hash=True)
            if not entry:
                return

            await ipfsop.sleep()

            encoder.add(joinIpfs(entry['Hash']))
            encoder.add(joinIpns(ipfsop.ctx.node.id))

            if didIdentRe.match(did):
                encoder.add(did)

            return await encoder.encodeAndStore(format=format)
        except Exception:
            pass
コード例 #15
0
 def onPlaylistsMenu(self, action):
     entry = action.data()
     if entry:
         ensure(self.loadPlaylistFromPath(joinIpfs(entry['Hash'])))
コード例 #16
0
ファイル: render.py プロジェクト: atavacron/galacteek
def ipfspathnorm(input):
    if isinstance(input, str):
        if cidValid(input):
            return joinIpfs(input)
        elif isIpfsPath(input) or isIpnsPath(input):
            return input
コード例 #17
0
ファイル: dag.py プロジェクト: pinnaculum/galacteek
 def path(self, subpath):
     return posixIpfsPath.join(joinIpfs(self.dagCid), subpath)
コード例 #18
0
ファイル: mediaplayer.py プロジェクト: atavacron/galacteek
 def onPlaylistsMenu(self, action):
     entry = action.data()
     self.app.task(self.loadPlaylistFromPath, joinIpfs(entry['Hash']))
コード例 #19
0
ファイル: dag.py プロジェクト: atavacron/galacteek
 def path(self, subpath):
     return os.path.join(joinIpfs(self.dagCid), subpath)