Add new ipfs options to cli frontend

Add async ipfs for discord
pull/23/head
Guillermo Rodriguez 2023-09-28 21:31:26 -03:00
parent fe4574c5dc
commit 504d6cd730
No known key found for this signature in database
GPG Key ID: EC3AB66D5D83B392
6 changed files with 31 additions and 19 deletions

View File

@ -21,6 +21,7 @@ key = 5Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
node_url = https://testnet.skygpu.net node_url = https://testnet.skygpu.net
hyperion_url = https://testnet.skygpu.net hyperion_url = https://testnet.skygpu.net
ipfs_gateway_url = /ip4/169.197.140.154/tcp/4001/p2p/12D3KooWKWogLFNEcNNMKnzU7Snrnuj84RZdMBg3sLiQSQc51oEv ipfs_gateway_url = /ip4/169.197.140.154/tcp/4001/p2p/12D3KooWKWogLFNEcNNMKnzU7Snrnuj84RZdMBg3sLiQSQc51oEv
ipfs_url = http://127.0.0.1:5001
token = XXXXXXXXXX:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx token = XXXXXXXXXX:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
@ -32,5 +33,6 @@ key = 5Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
node_url = https://testnet.skygpu.net node_url = https://testnet.skygpu.net
hyperion_url = https://testnet.skygpu.net hyperion_url = https://testnet.skygpu.net
ipfs_gateway_url = /ip4/169.197.140.154/tcp/4001/p2p/12D3KooWKWogLFNEcNNMKnzU7Snrnuj84RZdMBg3sLiQSQc51oEv ipfs_gateway_url = /ip4/169.197.140.154/tcp/4001/p2p/12D3KooWKWogLFNEcNNMKnzU7Snrnuj84RZdMBg3sLiQSQc51oEv
ipfs_url = http://127.0.0.1:5001
token = XXXXXXXXXX:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx token = XXXXXXXXXX:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

View File

@ -388,7 +388,9 @@ def dgpu(
@click.option( @click.option(
'--node-url', '-n', default=f'https://testnet.{DEFAULT_DOMAIN}') '--node-url', '-n', default=f'https://testnet.{DEFAULT_DOMAIN}')
@click.option( @click.option(
'--ipfs-gateway-url', '-i', default=DEFAULT_IPFS_REMOTE) '--ipfs-url', '-i', default=DEFAULT_IPFS_LOCAL)
@click.option(
'--ipfs-gateway-url', '-I', default=None)
@click.option( @click.option(
'--db-host', '-h', default='localhost:5432') '--db-host', '-h', default='localhost:5432')
@click.option( @click.option(
@ -401,6 +403,7 @@ def telegram(
permission: str, permission: str,
key: str | None, key: str | None,
hyperion_url: str, hyperion_url: str,
ipfs_url: str,
ipfs_gateway_url: str, ipfs_gateway_url: str,
node_url: str, node_url: str,
db_host: str, db_host: str,
@ -414,7 +417,7 @@ def telegram(
key, account, permission = load_account_info( key, account, permission = load_account_info(
'telegram', key, account, permission) 'telegram', key, account, permission)
node_url, _, ipfs_gateway_url, _ = load_endpoint_info( node_url, _, ipfs_gateway_url, ipfs_url = load_endpoint_info(
'telegram', node_url=node_url, ipfs_gateway_url=ipfs_gateway_url) 'telegram', node_url=node_url, ipfs_gateway_url=ipfs_gateway_url)
async def _async_main(): async def _async_main():
@ -425,6 +428,7 @@ def telegram(
node_url, node_url,
hyperion_url, hyperion_url,
db_host, db_user, db_pass, db_host, db_user, db_pass,
ipfs_url,
remote_ipfs_node=ipfs_gateway_url, remote_ipfs_node=ipfs_gateway_url,
key=key key=key
) )
@ -449,7 +453,9 @@ def telegram(
@click.option( @click.option(
'--node-url', '-n', default=f'https://testnet.{DEFAULT_DOMAIN}') '--node-url', '-n', default=f'https://testnet.{DEFAULT_DOMAIN}')
@click.option( @click.option(
'--ipfs-gateway-url', '-i', default=DEFAULT_IPFS_REMOTE) '--ipfs-url', '-i', default=DEFAULT_IPFS_LOCAL)
@click.option(
'--ipfs-gateway-url', '-I', default=DEFAULT_IPFS_REMOTE)
@click.option( @click.option(
'--db-host', '-h', default='localhost:5432') '--db-host', '-h', default='localhost:5432')
@click.option( @click.option(
@ -462,6 +468,7 @@ def discord(
permission: str, permission: str,
key: str | None, key: str | None,
hyperion_url: str, hyperion_url: str,
ipfs_url: str,
ipfs_gateway_url: str, ipfs_gateway_url: str,
node_url: str, node_url: str,
db_host: str, db_host: str,
@ -475,8 +482,8 @@ def discord(
key, account, permission = load_account_info( key, account, permission = load_account_info(
'discord', key, account, permission) 'discord', key, account, permission)
node_url, _, ipfs_gateway_url, _ = load_endpoint_info( node_url, _, ipfs_gateway_url, ipfs_url = load_endpoint_info(
'telegram', node_url=node_url, ipfs_gateway_url=ipfs_gateway_url) 'discord', node_url=node_url, ipfs_gateway_url=ipfs_gateway_url)
async def _async_main(): async def _async_main():
frontend = SkynetDiscordFrontend( frontend = SkynetDiscordFrontend(
@ -486,6 +493,7 @@ def discord(
node_url, node_url,
hyperion_url, hyperion_url,
db_host, db_user, db_pass, db_host, db_user, db_pass,
ipfs_url,
remote_ipfs_node=ipfs_gateway_url, remote_ipfs_node=ipfs_gateway_url,
key=key key=key
) )

View File

@ -185,6 +185,7 @@ CONFIG_ATTRS = [
DEFAULT_DOMAIN = 'skygpu.net' DEFAULT_DOMAIN = 'skygpu.net'
DEFAULT_IPFS_REMOTE = '/ip4/169.197.140.154/tcp/4001/p2p/12D3KooWKWogLFNEcNNMKnzU7Snrnuj84RZdMBg3sLiQSQc51oEv' DEFAULT_IPFS_REMOTE = '/ip4/169.197.140.154/tcp/4001/p2p/12D3KooWKWogLFNEcNNMKnzU7Snrnuj84RZdMBg3sLiQSQc51oEv'
DEFAULT_IPFS_LOCAL = 'http://127.0.0.1:5001'
TG_MAX_WIDTH = 1280 TG_MAX_WIDTH = 1280
TG_MAX_HEIGHT = 1280 TG_MAX_HEIGHT = 1280

View File

@ -19,9 +19,8 @@ from leap.hyperion import HyperionAPI
import discord import discord
import io import io
from skynet.db import open_new_database, open_database_connection from skynet.db import open_database_connection
from skynet.ipfs import get_ipfs_file from skynet.ipfs import get_ipfs_file, AsyncIPFSHTTP
from skynet.ipfs.docker import open_ipfs_node
from skynet.constants import * from skynet.constants import *
from . import * from . import *
@ -44,6 +43,7 @@ class SkynetDiscordFrontend:
db_host: str, db_host: str,
db_user: str, db_user: str,
db_pass: str, db_pass: str,
ipfs_url: str,
remote_ipfs_node: str, remote_ipfs_node: str,
key: str key: str
): ):
@ -55,23 +55,21 @@ class SkynetDiscordFrontend:
self.db_host = db_host self.db_host = db_host
self.db_user = db_user self.db_user = db_user
self.db_pass = db_pass self.db_pass = db_pass
self.ipfs_url = ipfs_url
self.remote_ipfs_node = remote_ipfs_node self.remote_ipfs_node = remote_ipfs_node
self.key = key self.key = key
self.bot = DiscordBot(self) self.bot = DiscordBot(self)
self.cleos = CLEOS(None, None, url=node_url, remote=node_url) self.cleos = CLEOS(None, None, url=node_url, remote=node_url)
self.hyperion = HyperionAPI(hyperion_url) self.hyperion = HyperionAPI(hyperion_url)
self.ipfs_node = AsyncIPFSHTTP(ipfs_node)
self._exit_stack = ExitStack() self._exit_stack = ExitStack()
self._async_exit_stack = AsyncExitStack() self._async_exit_stack = AsyncExitStack()
async def start(self): async def start(self):
self.ipfs_node = self._exit_stack.enter_context( if self.remote_ipfs_node:
open_ipfs_node()) await self.ipfs_node.connect(self.remote_ipfs_node)
self.ipfs_node.connect(self.remote_ipfs_node)
logging.info(
f'connected to remote ipfs node: {self.remote_ipfs_node}')
self.db_call = await self._async_exit_stack.enter_async_context( self.db_call = await self._async_exit_stack.enter_async_context(
open_database_connection( open_database_connection(

View File

@ -217,10 +217,12 @@ def create_handler_context(frontend: 'SkynetDiscordFrontend'):
image.thumbnail((512, 512)) image.thumbnail((512, 512))
logging.warning(f'resized it to {image.size}') logging.warning(f'resized it to {image.size}')
image.save(f'ipfs-docker-staging/image.png', format='PNG') image_loc = 'ipfs-staging/image.png'
image.save(image_loc, format='PNG')
ipfs_hash = ipfs_node.add('image.png') ipfs_info = await ipfs_node.add(image_loc)
ipfs_node.pin(ipfs_hash) ipfs_hash = ipfs_info['Hash']
await ipfs_node.pin(ipfs_hash)
logging.info(f'published input image {ipfs_hash} on ipfs') logging.info(f'published input image {ipfs_hash} on ipfs')

View File

@ -217,9 +217,10 @@ def create_handler_context(frontend: 'SkynetTelegramFrontend'):
image.thumbnail((512, 512)) image.thumbnail((512, 512))
logging.warning(f'resized it to {image.size}') logging.warning(f'resized it to {image.size}')
image.save(f'ipfs-docker-staging/image.png', format='PNG') image_loc = 'ipfs-staging/image.png'
image.save(image_loc, format='PNG')
ipfs_info = await ipfs_node.add('image.png') ipfs_info = await ipfs_node.add(image_loc)
ipfs_hash = ipfs_info['Hash'] ipfs_hash = ipfs_info['Hash']
await ipfs_node.pin(ipfs_hash) await ipfs_node.pin(ipfs_hash)