Skip to content

Commit 313b891

Browse files
authored
Merge pull request #7 from HughIsaacs2/experimental
Experimental
2 parents 6708395 + 4d05055 commit 313b891

4 files changed

Lines changed: 46 additions & 16 deletions

File tree

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Basically all this does is use the Chrome Extension WebRequest API and Proxy API
2626
* Firefox support (this is trouble as [the Firefox WebExtension Proxy API](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/proxy) is different).
2727
* Firefox for Android support.
2828
* Opera support.
29+
* Mac OS support.
30+
* Linux support.
2931
* Chrome OS support.
3032
* dat:// link support.
3133
* This'll require coming up with a way to simply parse Dat URLs in a regular web browser, as [parse-dat-url](https://github.com/pfrazee/parse-dat-url "parse-dat-url") doesn't work very well on the web (there's likely a fix that can be done with regular expressions but I suck at them so... yeah).
@@ -44,3 +46,14 @@ Basically all this does is use the Chrome Extension WebRequest API and Proxy API
4446
* Edge support? (Not possible yet, needs the Proxy API, if it ever gets it)
4547
* Safari support? (I'm unsure if this is possible)
4648
* Internet Explorer support? (I'm being ridiculous here, but again unsure if this is possible)
49+
50+
## To-Do [Short term + more specific list]
51+
* Dat URL for current tab in the extension pop up.
52+
* Support for 404 pages by reading “fallback_page” in dat.json.
53+
* An button in the extension pop up to tell the app to download the entire Dat.
54+
* A button in the extension pop up to tell the app to delete the entire Dat.
55+
* A landing page for introducing users to the extension/app.
56+
* A page for deleting torrents/dats and other information.
57+
* The ability to submit dat links or hashes as searches in the extension (needs Dat parse for web).
58+
* Grey out extension icon when not on a Dat site.
59+

electron app/resources/datpart/launch.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ var appName = app.getName();
1515
var appIcon = __dirname+'/logo_128.png';
1616
var appPath = app.getAppPath();
1717

18-
if (!fs.existsSync(__dirname + '/../../dats/')) {
19-
fs.mkdirSync(__dirname + '/../../dats/');
20-
}
18+
if (fs.existsSync(__dirname + '/../../dev.hta')) {
19+
dev = true;
20+
}
21+
22+
if (!fs.existsSync(__dirname + '/../../dats/')) {
23+
fs.mkdirSync(__dirname + '/../../dats/');
24+
}
2125

2226
function createWindow () {
2327
// Create the browser window.

electron app/resources/datpart/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
}
2828
],
2929
"icon": "favicon.ico"
30+
},
31+
"mac": {
32+
"target": "dmg"
33+
},
34+
"linux": {
35+
"target": "AppImage",
36+
"category": "Network"
3037
}
3138
},
3239
"devDependencies": {

electron app/resources/datpart/server_script.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ const requestHandler = (request, response) => {
9898
var currentTLD = currentURLRequest.hostname.split(".").pop();
9999
var currentURLhostNoTLD = currentURLRequest.hostname.split(".")[0];
100100

101-
var fileSearch = currentURLRequest.pathname;
101+
var datPath = currentURLRequest.pathname;
102102

103-
console.log(fileSearch);
103+
console.log(datPath);
104104

105105
console.log("TLD: " + currentTLD + " Hash: " + currentURLhostNoTLD);
106106
/*
107107
if(currentTLD == 'dat_site') {
108-
fileSearch = "/dats/" + currentURLhostNoTLD + currentURLRequest.pathname;
109-
console.log(fileSearch);
108+
datPath = "/dats/" + currentURLhostNoTLD + currentURLRequest.pathname;
109+
console.log(datPath);
110110
}
111111
*/
112112
var uri = url.parse(request.url).pathname,
@@ -122,24 +122,28 @@ if(currentTLD == 'dat_site' && fs.existsSync(__dirname + "/../../dats/")) {
122122

123123
dat( __dirname + '/../../dats/'+currentURLhostNoTLD, {
124124
// 2. Tell Dat what link I want
125-
key: currentURLhostNoTLD, temp: false, sparse: true // (a 64 character hash from above)
125+
key: currentURLhostNoTLD, temp: true, sparse: true // (a 64 character hash from above)
126126
}, function (err, dat) {
127127
if (err) {throw err;console.log(err)}
128128

129129
var stats = dat.trackStats()
130130

131131
// 3. Join the network & download (files are automatically downloaded)
132132
dat.joinNetwork();
133-
/*
134-
dat.archive.readFile(fileSearch+'/dat.json', function (err, content) {
133+
134+
var datJSON;
135+
136+
dat.archive.readFile(datPath+'/dat.json', function (err, content) {
135137
console.log(JSON.parse(content));
138+
datJSON = JSON.parse(content);
139+
console.log(datJSON["fallback_page"]);
136140
if (err) {throw err;console.log(err)}
137141
});
138-
*/
142+
139143
var lastChar = request.url.substr(-1); // Selects the last character
140144
if (lastChar == '/') { // If the last character is not a slash
141145

142-
dat.archive.readFile(fileSearch+'/index.html', function (err, content) {
146+
dat.archive.readFile(datPath+'/index.html', function (err, content) {
143147
console.log(content);
144148
response.writeHead(200, { "Content-Type": "text/html" });
145149
response.end(content);
@@ -148,11 +152,13 @@ if (lastChar == '/') { // If the last character is not a slash
148152

149153
} else {
150154

151-
dat.archive.readFile(fileSearch, function (err, content) {
155+
dat.archive.readFile(datPath, function (err, content) {
152156
console.log(content);
153157
response.writeHead(200, { "Content-Type": mimeType });
154158
response.end(content);
155-
if (err) {throw err;console.log(err)}
159+
if (err) {
160+
throw err;console.log(err)
161+
}
156162
});
157163

158164
}
@@ -169,9 +175,9 @@ console.log(request.url);
169175
var currentTLD = currentURLRequest.hostname.split(".").pop();
170176
var currentURLhostNoTLD = currentURLRequest.hostname.split(".")[0];
171177

172-
var fileSearch = currentURLRequest.pathname;
178+
var datPath = currentURLRequest.pathname;
173179

174-
console.log(fileSearch);
180+
console.log(datPath);
175181

176182
console.log("TLD: " + currentTLD + " Hash: " + currentURLhostNoTLD);
177183

0 commit comments

Comments
 (0)