Skip to content

Commit ee65cf4

Browse files
committed
can't add not valid url
1 parent 7655552 commit ee65cf4

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

frontend/plugins/seeder.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const parse = require('parse-dat-url')
2+
13
module.exports = (state, emitter) => {
24
state.feeds = []
35
state.stats = {}
@@ -16,25 +18,30 @@ module.exports = (state, emitter) => {
1618
state.open = true
1719
emitter.emit('render')
1820
} else {
19-
url = url.trim()
20-
if (url == '') return
21+
try {
22+
url = parse(url)
2123

22-
if (state.feeds.indexOf(url) != -1) return
24+
if (url.protocol != 'dat:') return
2325

24-
window.fetch('/feeds', {
25-
body: JSON.stringify({url: url}),
26-
headers: {
27-
'content-type': 'application/json'
28-
},
29-
method: 'POST'
30-
})
31-
.then(res => res.json())
32-
.then((data) => {
33-
state.feeds.push(url)
34-
emitter.emit('render')
35-
stats(url)
36-
})
37-
state.open = false
26+
if (state.feeds.indexOf(url.href) != -1) return
27+
28+
window.fetch('/feeds', {
29+
body: JSON.stringify({url: url.href}),
30+
headers: {
31+
'content-type': 'application/json'
32+
},
33+
method: 'POST'
34+
})
35+
.then(res => res.json())
36+
.then((data) => {
37+
state.feeds.push(url.href)
38+
emitter.emit('render')
39+
stats(url.href)
40+
})
41+
state.open = false
42+
} catch (e) {
43+
console.error(e)
44+
}
3845
}
3946

4047
})

package-lock.json

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"start": "node server.js",
99
"watch": "watchify -t sheetify -o bundles/bundle.js frontend/index.js",
1010
"build": "browserify -t sheetify -o bundles/bundle.js frontend/index.js",
11-
"update": "git pull origin master && npm run build && systemctl restart dat"
11+
"update": "git pull origin master && npm run build && systemctl restart dat"
1212
},
1313
"repository": {
1414
"type": "git",
@@ -27,6 +27,7 @@
2727
"koa-bodyparser": "^4.2.0",
2828
"koa-router": "^7.4.0",
2929
"koa-static": "^4.0.2",
30+
"parse-dat-url": "^3.0.1",
3031
"sheetify": "^7.3.1"
3132
},
3233
"devDependencies": {

0 commit comments

Comments
 (0)