Skip to content

Commit 83eef22

Browse files
committed
[[ ssb ]] using api from Perihelion
- new post works. - minimal debugging ui
1 parent 5a99e77 commit 83eef22

File tree

26 files changed

+1317
-14
lines changed

26 files changed

+1317
-14
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ Head over to the [Patchfox website](https://patchfox.org) for the documentation.
1717

1818
## Setup & Building
1919

20-
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:
20+
Patchfox requires [NodeJS](https://nodejs.org) for development. After you have NodeJS installed, you can install the dependencies with:
2121

2222
```
2323
$ npm install
2424
```
2525

26-
And run a development version of the app using:
26+
And run the backend use:
2727

2828
```
2929
$ npm run start
3030
```
3131

32-
To build use:
32+
To run the minimal UI use:
3333

3434
```
35-
$ npm run build
35+
$ npm run ui
3636
```
3737

3838

minimal-ui/index.html

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<html>
2+
<head>
3+
<title>Minimal Debugging UI</title>
4+
<link rel="stylesheet" href="https://the.missing.style/v1.0.6/missing.min.css">
5+
6+
<script src="https://unpkg.com/mithril/mithril.js"></script>
7+
</head>
8+
<body>
9+
<script>
10+
var root = document.body
11+
12+
const server = "http://localhost:3000/jsonrpc"
13+
const token = "85b2ae37-0be4-4faa-b1f0-d02189a31cfa"
14+
15+
async function callMethod(method, params) {
16+
const obj = {
17+
jsonrpc: "2.0",
18+
method: method,
19+
id: "1",
20+
params: [token, params],
21+
}
22+
23+
const response = await fetch(server, {
24+
method: "POST", // *GET, POST, PUT, DELETE, etc.
25+
mode: "cors", // no-cors, *cors, same-origin
26+
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
27+
credentials: "same-origin", // include, *same-origin, omit
28+
headers: {
29+
"Content-Type": "application/json",
30+
// 'Content-Type': 'application/x-www-form-urlencoded',
31+
},
32+
redirect: "follow", // manual, *follow, error
33+
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
34+
body: JSON.stringify(obj), // body data type must match "Content-Type" header
35+
})
36+
return response.json() // parses JSON response into native JavaScript objects
37+
}
38+
39+
callMethod("examples.getStateName", [12]).then(data => {
40+
console.log(data) // JSON data parsed by `data.json()` call
41+
})
42+
43+
callMethod("ssb.post", {
44+
identity: "@fu9wRz7+UwjDcvW6TZrvbNDT0cEPgWBh/ZZq5dKGEyY=.ed25519",
45+
content: {
46+
text: `Now it will work`,
47+
root: "%sUJg+n7aIiDXPWQPrEMi4Tg82KhyF4gpI0TaQt0Z8Vc=.sha256"
48+
}
49+
})
50+
.then(data => {
51+
console.log(data)
52+
})
53+
.catch(err => {
54+
console.log("error", err)
55+
})
56+
57+
// callMethod("ssb.timeline.public", {identity: "@fu9wRz7+UwjDcvW6TZrvbNDT0cEPgWBh/ZZq5dKGEyY=.ed25519"})
58+
// .then(data => {
59+
// console.log(data)
60+
// })
61+
// .catch(err => {
62+
// console.log("error", err)
63+
// })
64+
65+
66+
/* Live reload */
67+
document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] +
68+
':35729/livereload.js?snipver=1"></' + 'script>')
69+
</script>
70+
71+
</body>
72+
</html>

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"ssb-markdown": "^6.0.7",
8181
"ssb-master": "^1.0.3",
8282
"ssb-query": "^2.4.5",
83+
"ssb-ref": "^2.16.0",
8384
"ssb-replicate": "^1.3.3",
8485
"ssb-replication-scheduler": "^3.0.0",
8586
"ssb-room-client": "^2.0.2",

perihelion-files-prefix.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
3+
File adapted from Perihelion by Nicolas Santini.
4+
5+
Perihelion is an awesome SSB client, get its source from:
6+
7+
https://github.com/nsantini/perihelion
8+
9+
MIT License
10+
11+
Copyright (c) 2022 Nicolas Santini
12+
13+
Permission is hereby granted, free of charge, to any person obtaining a copy
14+
of this software and associated documentation files (the "Software"), to deal
15+
in the Software without restriction, including without limitation the rights
16+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17+
copies of the Software, and to permit persons to whom the Software is
18+
furnished to do so, subject to the following conditions:
19+
20+
The above copyright notice and this permission notice shall be included in all
21+
copies or substantial portions of the Software.
22+
23+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29+
SOFTWARE.
30+
31+
*/
32+
33+

src/api/ping.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const lori = require("lori")
2-
31
function ping(_useless, callback) {
42
callback(null, "pong")
53
}

src/api/ssb/post.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const ssbRef = require("ssb-ref")
2+
const serverForIdentity = require("../../sbot.js")
3+
const api = require("../../common/ssb/api.js")
4+
5+
async function post(params, callback) {
6+
console.log(params)
7+
const identity = params[0]?.identity
8+
const content = params[0]?.content
9+
let err = false
10+
let result = false
11+
12+
if (!identity) {
13+
err = "Invalid identity."
14+
}
15+
16+
if (!content || !content?.text) {
17+
err = "Invalid content."
18+
}
19+
20+
if (!ssbRef.isFeed(identity)) {
21+
err = `Identity: ${identity} is not a valid identity`
22+
}
23+
24+
if (!err) {
25+
try {
26+
result = await api.postMessage(identity, content)
27+
console.log(typeof result)
28+
console.log(JSON.stringify(result))
29+
console.log(result)
30+
} catch(n) {
31+
console.log(n)
32+
err = `Error: ${n}`
33+
}
34+
}
35+
36+
if (err) {
37+
callback(err, null)
38+
} else {
39+
callback(null, result)
40+
}
41+
}
42+
43+
module.exports = post

src/api/ssb/timeline/public.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const ssbRef = require("ssb-ref")
2+
const serverForIdentity = require("../../../sbot.js")
3+
const api = require("../../../common/ssb/api.js")
4+
5+
async function publicTimeline(params, callback) {
6+
console.log(params)
7+
const identity = params[0]?.identity
8+
let err = false
9+
let result = false
10+
11+
if (!identity) {
12+
err = "Invalid identity."
13+
}
14+
15+
if (!ssbRef.isFeed(identity)) {
16+
err = `Identity: ${identity} is not a valid identity`
17+
}
18+
19+
if (!err) {
20+
try {
21+
result = await api.getThreads(identity, 1, 1)
22+
} catch(n) {
23+
console.log(n)
24+
err = `Error: ${n}`
25+
}
26+
}
27+
28+
if (err) {
29+
callback(err, null)
30+
} else {
31+
callback(null, result)
32+
}
33+
}
34+
35+
module.exports = publicTimeline

src/commands/dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function setup(program) {
1313
.command("create-method <name>")
1414
.description("creates a new RPC method.")
1515
.action(methodName => {
16-
let methodPath = `./api/` + methodName.replace(".", "/") + ".js"
16+
let methodPath = `./src/api/` + methodName.replaceAll(".", "/") + ".js"
1717
if (fs.existsSync(methodPath)) {
1818
console.log("Sorry, method already exists.")
1919
return

src/commands/token.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function setup(program) {
1313
if (t.length == 0) {
1414
console.log("No tokens available")
1515
} else {
16-
console.log(`tokens: ${t}`)
16+
console.log(`tokens: \n${t.join(`\n`)}`)
1717
}
1818
})
1919

0 commit comments

Comments
 (0)