mirror of
https://github.com/obsidian-desci/Obsidian-Desci.git
synced 2026-07-22 08:50:32 +00:00
code cleanup
This commit is contained in:
parent
e1867e2ec9
commit
2b3df8035f
12 changed files with 17 additions and 87 deletions
52
main.tsx
52
main.tsx
|
|
@ -1,13 +1,13 @@
|
|||
import { Notice, Plugin, ItemView } from 'obsidian';
|
||||
import {
|
||||
type CanvasView,
|
||||
} from './utils/canvas-util'
|
||||
import { getDpid } from './desci-nodes/getDpid'
|
||||
import { runSdxl } from './lilypad/runSdxl'
|
||||
import { runCowsay } from 'lilypad/runCowsay';
|
||||
import {dagGet} from './ipfs/dagGet'
|
||||
import {cat} from './ipfs/cat'
|
||||
import {add} from './ipfs/add'
|
||||
} from './src/utils/canvas-util'
|
||||
import { getDpid } from './src/desci-nodes/getDpid'
|
||||
import { runSdxl } from './src/lilypad/runSdxl'
|
||||
import { runCowsay } from 'src/lilypad/runCowsay';
|
||||
import {dagGet} from './src/ipfs/dagGet'
|
||||
import {cat} from './src/ipfs/cat'
|
||||
import {add} from './src/ipfs/add'
|
||||
import { ethers, Signer, Provider, JsonRpcProvider, Wallet } from 'ethers';
|
||||
import ExampleClient from './artifacts/ExampleClient.json'
|
||||
|
||||
|
|
@ -15,8 +15,7 @@ import {
|
|||
ObsidianDesciSettings,
|
||||
ObsidianDesciSettingTab,
|
||||
DEFAULT_SETTINGS
|
||||
} from 'settings';
|
||||
// Remember to rename these classes and interfaces!
|
||||
} from './src/settings';
|
||||
|
||||
|
||||
export default class ObsidianDesci extends Plugin {
|
||||
|
|
@ -33,15 +32,8 @@ export default class ObsidianDesci extends Plugin {
|
|||
if (this.settings.privateKey) {
|
||||
this.wallet = new Wallet(this.settings.privateKey, this.provider)
|
||||
this.signer = this.wallet.connect(this.provider)
|
||||
console.log('clientadd', ExampleClient.address)
|
||||
this.exampleClient = new ethers.Contract(ExampleClient.address, ExampleClient.abi, this.signer)
|
||||
} else {
|
||||
console.log('no private key detected, web3 not enabled')
|
||||
}
|
||||
if (this.settings.useEngine) {
|
||||
|
||||
} else {
|
||||
console.log('Engine not enabled')
|
||||
}
|
||||
this.addCommand({
|
||||
id: 'runCowsay',
|
||||
|
|
@ -73,35 +65,7 @@ export default class ObsidianDesci extends Plugin {
|
|||
name: 'ipfsAdd - Add Json objects referenced by CID',
|
||||
callback: add.bind(this)
|
||||
});
|
||||
|
||||
// This creates an icon in the left ribbon.
|
||||
const ribbonIconEl = this.addRibbonIcon('dice', 'Obsidian Lilypad', (evt: MouseEvent) => {
|
||||
// Called when the user clicks the icon.
|
||||
new Notice('This is a notice!');
|
||||
});
|
||||
// Perform additional things with the ribbon
|
||||
ribbonIconEl.addClass('my-plugin-ribbon-class');
|
||||
|
||||
// This adds a status bar item to the bottom of the app. Does not work on mobile apps.
|
||||
const statusBarItemEl = this.addStatusBarItem();
|
||||
statusBarItemEl.setText('Status Bar Text');
|
||||
|
||||
// This adds a simple command that can be triggered anywhere
|
||||
|
||||
// This adds a complex command that can check whether the current state of the app allows execution of the command
|
||||
|
||||
// This adds a settings tab so the user can configure various aspects of the plugin
|
||||
this.addSettingTab(new ObsidianDesciSettingTab(this.app, this));
|
||||
|
||||
// If the plugin hooks up any global DOM events (on parts of the app that doesn't belong to this plugin)
|
||||
// Using this function will automatically remove the event listener when this plugin is disabled.
|
||||
this.registerDomEvent(document, 'click', (evt: MouseEvent) => {
|
||||
console.log('click', evt);
|
||||
});
|
||||
|
||||
// When registering intervals, this function will automatically clear the interval when the plugin is disabled.
|
||||
this.registerInterval(window.setInterval(() => console.log('setInterval'), 5 * 60 * 1000));
|
||||
console.log('end of onload')
|
||||
}
|
||||
|
||||
onunload() {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { requestUrl } from 'obsidian'
|
||||
import { type CanvasNode } from '../utils/canvas-internal'
|
||||
import type ObsidianDecsiPlugin from '../main'
|
||||
import type ObsidianDecsiPlugin from '../../main'
|
||||
import {
|
||||
createNode,
|
||||
placeholderNoteHeight,
|
||||
|
|
@ -56,7 +56,6 @@ const formatPerson = (dpid: string, node:any) => {
|
|||
}
|
||||
|
||||
export const getDpid = async function () {
|
||||
console.log('this', this)
|
||||
if (this.unloaded) return
|
||||
this.logDebug("fetching dpid json from desci nodes")
|
||||
const canvas = this.getActiveCanvas()
|
||||
|
|
@ -77,7 +76,6 @@ export const getDpid = async function () {
|
|||
//const nodeData = node.getData()
|
||||
let nodeText = await getNodeText(node) || ''
|
||||
if (nodeText.length == 0) {
|
||||
console.log('no node text')
|
||||
this.logDebug('no node Text found')
|
||||
return
|
||||
}
|
||||
|
|
@ -94,7 +92,6 @@ export const getDpid = async function () {
|
|||
)
|
||||
try {
|
||||
const res = await requestUrl(`http://beta.dpid.org/${nodeText}?jsonld`)
|
||||
console.log('res.json', res.json)
|
||||
const metadataNode = createNode(canvas, created,
|
||||
{
|
||||
text: `${JSON.stringify(
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { requestUrl } from 'obsidian'
|
||||
import { CanvasNode } from 'utils/canvas-internal'
|
||||
import { CanvasNode } from 'src/utils/canvas-internal'
|
||||
import {
|
||||
createNode,
|
||||
placeholderNoteHeight,
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
import { requestUrl, Vault } from 'obsidian'
|
||||
import { CanvasNode } from 'utils/canvas-internal'
|
||||
import { CanvasNode } from 'src/utils/canvas-internal'
|
||||
import * as fs from 'fs'
|
||||
console.log('fs', fs)
|
||||
import {
|
||||
createNode,
|
||||
placeholderNoteHeight,
|
||||
|
|
@ -57,7 +56,6 @@ export const cat = async function () {
|
|||
//"Content-Type": "text/plain",
|
||||
}
|
||||
})
|
||||
console.log('res', res)
|
||||
if (res.text.startsWith('<27>PNG')) {
|
||||
|
||||
const buffer = Buffer.from(res.arrayBuffer);
|
||||
|
|
@ -65,9 +63,7 @@ export const cat = async function () {
|
|||
if (error) {
|
||||
console.error('Error saving image:', error);
|
||||
} else {
|
||||
console.log(`Image file saved at ${nodeText}.png`);
|
||||
const file = this.app.vault.getAbstractFileByPath(`${nodeText}.png`)
|
||||
console.log('file', file)
|
||||
const cidNode = createNode(canvas, created,
|
||||
{
|
||||
file,
|
||||
|
|
@ -80,7 +76,6 @@ export const cat = async function () {
|
|||
)
|
||||
}
|
||||
});
|
||||
console.log('canvas', canvas)
|
||||
} else {
|
||||
const cidNode = createNode(canvas, created,
|
||||
{
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { requestUrl } from 'obsidian'
|
||||
import { CanvasNode } from 'utils/canvas-internal'
|
||||
import { CanvasNode } from 'src/utils/canvas-internal'
|
||||
import {
|
||||
createNode,
|
||||
placeholderNoteHeight,
|
||||
|
|
@ -42,7 +42,6 @@ export const dagGet = async function () {
|
|||
}
|
||||
)
|
||||
try {
|
||||
console.log('waiting for ipfs. . .')
|
||||
|
||||
const res = await requestUrl({
|
||||
url: `${this.settings.kuboRpc}/dag/get?arg=${nodeText}`,
|
||||
|
|
@ -51,7 +50,6 @@ export const dagGet = async function () {
|
|||
"Content-Type": "text/plain",
|
||||
}
|
||||
})
|
||||
console.log('res', res)
|
||||
res.json.Links.forEach((link: any) => {
|
||||
const name = createNode(canvas, created,
|
||||
{
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { requestUrl } from 'obsidian'
|
||||
import { CanvasNode } from 'utils/canvas-internal'
|
||||
import { CanvasNode } from 'src/utils/canvas-internal'
|
||||
import {
|
||||
createNode,
|
||||
placeholderNoteHeight,
|
||||
|
|
@ -9,7 +9,6 @@ import {
|
|||
|
||||
import {ethers} from 'ethers'
|
||||
export const runCowsay = async function () {
|
||||
console.log('unloaded status: ', this.unloaded)
|
||||
if (this.unloaded) return
|
||||
|
||||
this.logDebug("Running Cowsay")
|
||||
|
|
@ -32,7 +31,6 @@ export const runCowsay = async function () {
|
|||
const nodeData = node.getData()
|
||||
let nodeText = await getNodeText(node) || ''
|
||||
if (nodeText.length == 0) {
|
||||
console.log('no node text')
|
||||
this.logDebug('no node Text found')
|
||||
return
|
||||
}
|
||||
|
|
@ -48,21 +46,18 @@ export const runCowsay = async function () {
|
|||
}
|
||||
)
|
||||
try {
|
||||
console.log('waiting for cowsay run')
|
||||
const tx = await this.exampleClient.runCowsay(
|
||||
nodeText, {
|
||||
value: ethers.parseUnits('2', 'ether')
|
||||
}
|
||||
)
|
||||
|
||||
console.log('tx', tx)
|
||||
created.setText(`success! tx hash: ${tx.hash}, fetching ipfs.io cid`)
|
||||
|
||||
const res = await this.exampleClient.fetchAllResults()
|
||||
const ipfsio = res[res.length - 1][2]
|
||||
const cid = res[res.length - 1][1]
|
||||
created.setText(`job complete see on ${ipfsio}`)
|
||||
console.log('hmmmmmm')
|
||||
const ipfsFetchNode = createNode(canvas, created,
|
||||
{
|
||||
text: `${cid}`,
|
||||
|
|
@ -4,7 +4,7 @@ import {
|
|||
assistantColor,
|
||||
getNodeText
|
||||
} from '../utils/canvas-util'
|
||||
import { CanvasNode } from 'utils/canvas-internal'
|
||||
import { CanvasNode } from 'src/utils/canvas-internal'
|
||||
import { ethers } from 'ethers'
|
||||
export const runSdxl = async function () {
|
||||
if (this.unloaded) return
|
||||
|
|
@ -29,7 +29,6 @@ export const runSdxl = async function () {
|
|||
//const nodeData = node.getData()
|
||||
let nodeText = await getNodeText(node) || ''
|
||||
if (nodeText.length == 0) {
|
||||
console.log('no node text')
|
||||
this.logDebug('no node Text found')
|
||||
return
|
||||
}
|
||||
|
|
@ -45,22 +44,15 @@ export const runSdxl = async function () {
|
|||
}
|
||||
)
|
||||
try {
|
||||
console.log('waiting for sdxl run')
|
||||
console.log('signer', this.signer)
|
||||
const tx = await this.exampleClient.runSDXL(
|
||||
nodeText, {
|
||||
value: ethers.parseUnits('4', 'ether')
|
||||
}
|
||||
)
|
||||
const receipt = await tx.wait()
|
||||
console.log('receipt', receipt)
|
||||
|
||||
console.log('tx', tx)
|
||||
created.setText(`success! tx hash: ${tx.hash}, listening for job completion`)
|
||||
this.exampleClient.on("ReceivedJobResults", (jobId:string, cid:string) => {
|
||||
//const res = await this.exampleClient.fetchAllResults()
|
||||
//console.log('res', res)
|
||||
//const ipfsio = res[res.length -1][2]
|
||||
const ipfsFetchNode = createNode(canvas, created,
|
||||
{
|
||||
text: `${cid}`,
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import type ObsidianDesci from './main'
|
||||
import type ObsidianDesci from '../main'
|
||||
import { App, Plugin, PluginSettingTab, Setting } from 'obsidian';
|
||||
|
||||
interface ChainConfig {
|
||||
|
|
@ -10,7 +10,6 @@ interface ChainConfig {
|
|||
export interface ObsidianDesciSettings {
|
||||
privateKey: string;
|
||||
chain: ChainConfig;
|
||||
useEngine: boolean;
|
||||
kuboRpc: string;
|
||||
}
|
||||
|
||||
|
|
@ -21,7 +20,6 @@ export const DEFAULT_SETTINGS: ObsidianDesciSettings = {
|
|||
rpcUrl: 'http://testnet.lilypadnetwork.org:8545',
|
||||
chainId: 1337
|
||||
},
|
||||
useEngine: false,
|
||||
kuboRpc: 'http:/127.0.0.1:5001/api/v0'
|
||||
}
|
||||
|
||||
|
|
@ -39,7 +37,7 @@ export class ObsidianDesciSettingTab extends PluginSettingTab {
|
|||
containerEl.empty();
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Private Key')
|
||||
.setName('Private key')
|
||||
.setDesc('It\'s a secret')
|
||||
.addText(text => text
|
||||
.setPlaceholder('Enter your Ethereum Private Key')
|
||||
|
|
@ -49,7 +47,7 @@ export class ObsidianDesciSettingTab extends PluginSettingTab {
|
|||
await this.plugin.saveSettings();
|
||||
}));
|
||||
new Setting(containerEl)
|
||||
.setName('Kubo Rpc Url')
|
||||
.setName('Kubo rpc url')
|
||||
.setDesc('If you turn on a Kubo node we can use IPFS in obsidian')
|
||||
.addText(text => text
|
||||
.setPlaceholder('Enter your Kubo RPC endpoint')
|
||||
|
|
@ -58,14 +56,5 @@ export class ObsidianDesciSettingTab extends PluginSettingTab {
|
|||
this.plugin.settings.kuboRpc = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
new Setting(containerEl)
|
||||
.setName('Use Engine')
|
||||
.setDesc('If you have the Engine running on your computer you can gain enhanced functionality')
|
||||
.addToggle((toggle) => {
|
||||
toggle.setValue(this.plugin.settings.useEngine).onChange(async (value) => {
|
||||
this.plugin.settings.useEngine = value
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue