-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck.js
42 lines (34 loc) · 1.05 KB
/
check.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const parse = require('parse-dat-url')
module.exports = async function check(source) {
var upstream, archive
const fork_url = parse(window.location.href)
if (fork_url.protocol == 'dat:' || fork_url.protocol == 'workspace:') {
archive = new DatArchive(fork_url.origin + '/')
return await try_check()
}
async function try_check() {
var info = await archive.getInfo()
if (info.isOwner) {
const fork_json = await get_package_json(archive)
if (fork_json.update) source = fork_json.update.url || source
upstream = new DatArchive(source)
const upstream_json = await get_package_json(upstream)
if (fork_json && upstream_json) {
if (fork_json.version < upstream_json.version) {
return [archive, upstream, fork_json, upstream_json]
}
}
}
return false
}
async function get_package_json(archive) {
try {
var json = await archive.readFile('/package.json')
json = JSON.parse(json)
return json
} catch (e) {
console.error("There's no valid package.json in the root directory of " + archive.url)
return null
}
}
}