-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathproviders.js
More file actions
98 lines (98 loc) · 3.6 KB
/
Copy pathproviders.js
File metadata and controls
98 lines (98 loc) · 3.6 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
var allProviders = [
{id: 'btfs', disp: 'BTFS', dht: 1},
{id: 'ipfs', disp: 'IPFS', dht: 1},
{id: 'sia', disp: 'Skynet', dht: 1},
{id: 'youtube', disp: 'YouTube'},
{id: 'twitch', disp: 'Twitch'},
{id: 'dailymotion', disp: 'Dailymotion'},
{id: 'instagram', disp: 'Instagram'},
{id: 'liveleak', disp: 'LiveLeak'},
{id: 'vimeo', disp: 'Vimeo'},
{id: 'facebook', disp: 'Facebook'},
]
var failedProviders = []
provider = null
prov = {
idToDisp: function(id) {
for (let i = 0; i < allProviders.length; i++)
if (allProviders[i].id == id)
return allProviders[i].disp
return
},
dispToId: function(disp) {
for (let i = 0; i < allProviders.length; i++)
if (allProviders[i].disp == disp)
return allProviders[i].id
return
},
tryNext: function(video) {
failedProviders.push(provider)
var available = this.available(video)
var reallyAvailable = []
for (let i = 0; i < available.length; i++) {
if (failedProviders.indexOf(available[i]) == -1)
reallyAvailable.push(available[i])
}
if (reallyAvailable.length > 0) {
provider = reallyAvailable[0]
handleVideo(video)
}
},
getDefaultGateway: function(video) {
if (provider == 'IPFS' && video && video.files && video.files.ipfs && video.files.ipfs.gw)
return video.files.ipfs.gw + '/ipfs/'
if (provider == 'BTFS' && video && video.files && video.files.btfs && video.files.btfs.gw)
return video.files.btfs.gw + '/btfs/'
if (provider == 'IPFS') return portals.IPFS[0]
if (provider == 'BTFS') return portals.BTFS[0]
if (provider == 'Skynet') return portals.Skynet[0]
return
},
getFallbackGateway: function() {
if (provider == 'IPFS') return portals.IPFS[1]
if (provider == 'BTFS') return portals.BTFS[1]
if (provider == 'Skynet') return portals.Skynet[1]
},
available: function(video) {
var provs = []
if (video && video.files) {
for (let i = 0; i < allProviders.length; i++) {
if (allProviders[i].dht == 1) {
if (
video.files[allProviders[i].id] &&
video.files[allProviders[i].id].vid &&
Object.keys(video.files[allProviders[i].id].vid).length > 0
) {
provs.push(allProviders[i].disp)
}
} else {
if (video.files[allProviders[i].id])
provs.push(allProviders[i].disp)
}
}
}
if (video && video.providerName && provs.indexOf(video.providerName) == -1)
provs.push(video.providerName)
return provs
},
default: function(video) {
if (video && video.providerName) return video.providerName
if (video && video.files) {
for (let i = 0; i < allProviders.length; i++) {
if (allProviders[i].dht == 1) {
if (
video.files[allProviders[i].id] &&
video.files[allProviders[i].id].vid &&
Object.keys(video.files[allProviders[i].id].vid).length > 0
) {
return allProviders[i].disp
}
} else {
if (video.files[allProviders[i].id])
return allProviders[i].disp
}
}
}
return 'IPFS'
}
}