Skip to content

Commit e45603f

Browse files
authored
set things up
- need to actually encrypt + save - update saved note page to load
1 parent 3fec9ba commit e45603f

11 files changed

Lines changed: 122 additions & 6 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
node_modules
44
public/*
55
main
6-
assets
6+
assets/*
7+
!assets/manifest.json
78
database
89
mokintoken

assets/manifest.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "mokintoken",
3+
"icons": [],
4+
"start_url": "/",
5+
"display": "standalone",
6+
"theme_color": "#000000",
7+
"background_color": "#ffffff",
8+
"serviceworker": {
9+
"src": "/assets/service-worker.js"
10+
},
11+
"share_target": {
12+
"action": "/assets/share-target/",
13+
"method": "POST",
14+
"enctype": "multipart/form-data",
15+
"params": {
16+
"text": "text",
17+
"files": [
18+
{
19+
"name": "img",
20+
"accept": [
21+
"image/*"
22+
]
23+
}
24+
]
25+
}
26+
}
27+
}

mokintoken.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ func main() {
249249

250250
http.HandleFunc("/", userViews("home"))
251251
http.HandleFunc("/about", userViews("about"))
252+
http.HandleFunc("/noteSaved", userViews("noteSaved"))
252253
http.HandleFunc("/decrypt/", decryptHandler(db))
253254
http.HandleFunc("/api/save-note", saveNoteHandler(db))
254255
http.HandleFunc("/ping", ping(db))

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"scripts": {
1111
"test": "echo \"Error: no test specified\" && exit 1",
12-
"build": "rollup --config && cp node_modules/tachyons/css/tachyons.min.css assets",
12+
"build": "rollup --config && rollup --config rollup-serviceworker.config.js && cp node_modules/tachyons/css/tachyons.min.css assets",
1313
"dev": "rollup --config -w"
1414
},
1515
"author": "",

resources/js/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,32 @@ async function main() {
88
const { Decrypt } = await import('./decrypt')
99
new Decrypt()
1010
}
11+
12+
if (location.pathname.startsWith('/noteSaved')) {
13+
const { NoteSaved } = await import('./noteSaved')
14+
new NoteSaved()
15+
}
1116
}
1217
main()
18+
19+
const registerServiceWorker = async () => {
20+
if ("serviceWorker" in navigator) {
21+
try {
22+
const registration = await navigator.serviceWorker.register("/assets/service-worker.js", {
23+
scope: "/assets/",
24+
})
25+
if (registration.installing) {
26+
console.log("Service worker installing")
27+
} else if (registration.waiting) {
28+
console.log("Service worker installed")
29+
} else if (registration.active) {
30+
console.log("Service worker active")
31+
}
32+
} catch (error) {
33+
console.error(`Registration failed with ${error}`)
34+
}
35+
}
36+
}
37+
38+
registerServiceWorker();
39+

resources/js/noteSaved.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export class NoteSaved {
2+
3+
constructor() {
4+
console.log('note saved todo')
5+
}
6+
}

resources/js/service-worker.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import nacl from 'tweetnacl'
2+
import naclUutil from 'tweetnacl-util'
3+
import { Base64 } from 'js-base64'
4+
5+
console.log("ass" + nacl + naclUutil + Base64)
6+
7+
8+
self.addEventListener("fetch", (event) => {
9+
// Regular requests not related to Web Share Target.
10+
if (event.request.method !== "POST" || new URL(event.request.url).pathname != "/assets/share-target") {
11+
event.respondWith(fetch(event.request))
12+
return
13+
}
14+
15+
// Requests related to Web Share Target.
16+
event.respondWith(
17+
(async () => {
18+
const formData = await event.request.formData()
19+
// encrypt note or image
20+
// send to fetch api
21+
// respond with saved note page
22+
return Response.redirect('/noteSaved#todoshitinthehash', 303)
23+
})(),
24+
)
25+
})

resources/js/welcome.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function getImgBase64(ele) {
1717

1818
export class Welcome {
1919
loadNonceAndKey() {
20-
window.location.hash = '' // clear out old key
20+
//window.location.hash = '' // clear out old key
2121
// always generate new nonce
2222
const nonce = nacl.randomBytes(nacl.secretbox.nonceLength)
2323
const key = nacl.randomBytes(nacl.secretbox.keyLength)

rollup-serviceworker.config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import commonjs from '@rollup/plugin-commonjs'
2+
import resolve from '@rollup/plugin-node-resolve'
3+
import builtins from 'rollup-plugin-node-builtins'
4+
import globals from 'rollup-plugin-node-globals'
5+
module.exports = {
6+
input: 'resources/js/service-worker.js',
7+
output: {
8+
dir: 'assets'
9+
},
10+
plugins: [
11+
commonjs(),
12+
resolve({
13+
browser: true,
14+
preferBuiltins: false
15+
}),
16+
builtins(),
17+
globals()
18+
]
19+
}

views/noteSaved.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{{define "content"}}
2+
3+
<main>
4+
<h1 class="tc f1 pv6">NOTE SAVED TODO/h1>
5+
</main>
6+
{{end}}

0 commit comments

Comments
 (0)