Skip to content

Commit

Permalink
[[ ssb ]] using api from Perihelion
Browse files Browse the repository at this point in the history
- new post works.
- minimal debugging ui
  • Loading branch information
soapdog committed Jan 22, 2023
1 parent 5a99e77 commit 83eef22
Show file tree
Hide file tree
Showing 26 changed files with 1,317 additions and 14 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ Head over to the [Patchfox website](https://patchfox.org) for the documentation.

## Setup & Building

Patchfox uses [Mithril](https://mithril.js.org), [Electron](https://electronjs.org) and requires [NodeJS](https://nodejs.org) for development. After you have NodeJS installed, you can install the dependencies with:
Patchfox requires [NodeJS](https://nodejs.org) for development. After you have NodeJS installed, you can install the dependencies with:

```
$ npm install
```

And run a development version of the app using:
And run the backend use:

```
$ npm run start
```

To build use:
To run the minimal UI use:

```
$ npm run build
$ npm run ui
```


Expand Down
72 changes: 72 additions & 0 deletions minimal-ui/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<html>
<head>
<title>Minimal Debugging UI</title>
<link rel="stylesheet" href="https://the.missing.style/v1.0.6/missing.min.css">

<script src="https://unpkg.com/mithril/mithril.js"></script>
</head>
<body>
<script>
var root = document.body

const server = "http://localhost:3000/jsonrpc"
const token = "85b2ae37-0be4-4faa-b1f0-d02189a31cfa"

async function callMethod(method, params) {
const obj = {
jsonrpc: "2.0",
method: method,
id: "1",
params: [token, params],
}

const response = await fetch(server, {
method: "POST", // *GET, POST, PUT, DELETE, etc.
mode: "cors", // no-cors, *cors, same-origin
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
credentials: "same-origin", // include, *same-origin, omit
headers: {
"Content-Type": "application/json",
// 'Content-Type': 'application/x-www-form-urlencoded',
},
redirect: "follow", // manual, *follow, error
referrerPolicy: "no-referrer", // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
body: JSON.stringify(obj), // body data type must match "Content-Type" header
})
return response.json() // parses JSON response into native JavaScript objects
}

callMethod("examples.getStateName", [12]).then(data => {
console.log(data) // JSON data parsed by `data.json()` call
})

callMethod("ssb.post", {
identity: "@fu9wRz7+UwjDcvW6TZrvbNDT0cEPgWBh/ZZq5dKGEyY=.ed25519",
content: {
text: `Now it will work`,
root: "%sUJg+n7aIiDXPWQPrEMi4Tg82KhyF4gpI0TaQt0Z8Vc=.sha256"
}
})
.then(data => {
console.log(data)
})
.catch(err => {
console.log("error", err)
})

// callMethod("ssb.timeline.public", {identity: "@fu9wRz7+UwjDcvW6TZrvbNDT0cEPgWBh/ZZq5dKGEyY=.ed25519"})
// .then(data => {
// console.log(data)
// })
// .catch(err => {
// console.log("error", err)
// })


/* Live reload */
document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] +
':35729/livereload.js?snipver=1"></' + 'script>')
</script>

</body>
</html>
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"ssb-markdown": "^6.0.7",
"ssb-master": "^1.0.3",
"ssb-query": "^2.4.5",
"ssb-ref": "^2.16.0",
"ssb-replicate": "^1.3.3",
"ssb-replication-scheduler": "^3.0.0",
"ssb-room-client": "^2.0.2",
Expand Down
33 changes: 33 additions & 0 deletions perihelion-files-prefix.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*

File adapted from Perihelion by Nicolas Santini.

Perihelion is an awesome SSB client, get its source from:

https://github.com/nsantini/perihelion

MIT License

Copyright (c) 2022 Nicolas Santini

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*/


2 changes: 0 additions & 2 deletions src/api/ping.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const lori = require("lori")

function ping(_useless, callback) {
callback(null, "pong")
}
Expand Down
43 changes: 43 additions & 0 deletions src/api/ssb/post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const ssbRef = require("ssb-ref")
const serverForIdentity = require("../../sbot.js")
const api = require("../../common/ssb/api.js")

async function post(params, callback) {
console.log(params)
const identity = params[0]?.identity
const content = params[0]?.content
let err = false
let result = false

if (!identity) {
err = "Invalid identity."
}

if (!content || !content?.text) {
err = "Invalid content."
}

if (!ssbRef.isFeed(identity)) {
err = `Identity: ${identity} is not a valid identity`
}

if (!err) {
try {
result = await api.postMessage(identity, content)
console.log(typeof result)
console.log(JSON.stringify(result))
console.log(result)
} catch(n) {
console.log(n)
err = `Error: ${n}`
}
}

if (err) {
callback(err, null)
} else {
callback(null, result)
}
}

module.exports = post
35 changes: 35 additions & 0 deletions src/api/ssb/timeline/public.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const ssbRef = require("ssb-ref")
const serverForIdentity = require("../../../sbot.js")
const api = require("../../../common/ssb/api.js")

async function publicTimeline(params, callback) {
console.log(params)
const identity = params[0]?.identity
let err = false
let result = false

if (!identity) {
err = "Invalid identity."
}

if (!ssbRef.isFeed(identity)) {
err = `Identity: ${identity} is not a valid identity`
}

if (!err) {
try {
result = await api.getThreads(identity, 1, 1)
} catch(n) {
console.log(n)
err = `Error: ${n}`
}
}

if (err) {
callback(err, null)
} else {
callback(null, result)
}
}

module.exports = publicTimeline
2 changes: 1 addition & 1 deletion src/commands/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function setup(program) {
.command("create-method <name>")
.description("creates a new RPC method.")
.action(methodName => {
let methodPath = `./api/` + methodName.replace(".", "/") + ".js"
let methodPath = `./src/api/` + methodName.replaceAll(".", "/") + ".js"
if (fs.existsSync(methodPath)) {
console.log("Sorry, method already exists.")
return
Expand Down
2 changes: 1 addition & 1 deletion src/commands/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function setup(program) {
if (t.length == 0) {
console.log("No tokens available")
} else {
console.log(`tokens: ${t}`)
console.log(`tokens: \n${t.join(`\n`)}`)
}
})

Expand Down
Loading

0 comments on commit 83eef22

Please sign in to comment.