Skip to content

Commit e121f57

Browse files
author
Thomas Muldowney
committed
Make screenshots work
1 parent 854f4ca commit e121f57

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

Apps/dashboardv3/dashboard-client.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,36 @@ var submitPublish = function(req, res) {
271271
data.title = fields['old-name'];
272272
}
273273
request.post({uri: locker.lockerBase + '/registry/publish/' + fields.app, json: data}, function(err, resp, body) {
274-
res.send('<script type="text/javascript">parent.app = "viewAll"; parent.loadApp(); parent.window.location.reload();</script>');
274+
if (!err) {
275+
var reloadScript = '<script type="text/javascript">parent.app = "viewAll"; parent.loadApp(); parent.window.location.reload();</script>';
276+
// Send the screenshot
277+
var ssPut = request({method:"PUT", uri:locker.lockerBase + "/registry/screenshot/" + body.name,
278+
headers:{"Content-Type":"image/png"},
279+
body:fs.readFileSync(path.join(lconfig.lockerDir, githubapps[fields.app].srcdir, 'screenshot'))});
280+
// TODO: All of this below is more correct for piping a file to the PUT request but it does not work. Needs to be retested with node 0.6 and newer request.
281+
/*
282+
ssPut.on("data", function(body, result) {
283+
console.dir(ssPut);
284+
console.log("ssPut data body: " + body);
285+
});
286+
ssPut.on("error", function(error) {
287+
process.stderr.write("Error sending screenshot to registry " + error);
288+
});
289+
ssPut.on("end", function() {
290+
res.send(reloadScript);
291+
});
292+
var readStream = fs.createReadStream(path.join(lconfig.lockerDir, githubapps[fields.app].srcdir, 'screenshot'));
293+
readStream.on("pause", function() {
294+
console.log("RS Paused");
295+
});
296+
readStream.on("data", function() {
297+
console.log("Did stuff on the RS");
298+
});
299+
readStream.pipe(ssPut);
300+
*/
301+
} else {
302+
res.send(reloadScript);
303+
}
275304
});
276305
} else {
277306
res.send('<script type="text/javascript">parent.app = "viewAll"; parent.loadApp();</script>');

Apps/dashboardv3/views/iframe/exploreApps.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<div class="app-card" id="<%= i %>&breadcrumb=featured">
1616
<div class="left-side">
1717
<div class="description"><%= apps[i].repository.desc %></div>
18-
<div class="screenshot"><img src="img/batman.jpg"></div>
18+
<div class="screenshot"><img src="/registry/screenshot/<%= apps[i].repository.handle %>"></div>
1919
</div>
2020
<div class="app-info">
2121
<p class="title"><%= apps[i].repository.title %></p>

Ops/registry.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var regIndex = {};
2626
var syncInterval = 3600000;
2727
var syncTimer;
2828
var regBase = 'http://registry.singly.com';
29+
var burrowBase = "burrow.singly.com";
2930

3031
// make sure stuff is ready/setup locally, load registry, start sync check, etc
3132
exports.init = function(config, crypto, callback) {
@@ -92,6 +93,9 @@ exports.app = function(app)
9293

9394
app.post('/registry/publish/:id', express.bodyParser(), publishPackage);
9495

96+
app.put("/registry/screenshot/:id", publishScreenshot);
97+
app.get("/registry/screenshot/:id", getScreenshot);
98+
9599
app.get('/registry/myApps', exports.getMyApps);
96100
}
97101

@@ -117,6 +121,43 @@ function publishPackage(req, res) {
117121
});
118122
}
119123

124+
function publishScreenshot(req, res) {
125+
// first, required github
126+
req.pause();
127+
regUser(function(err, auth){
128+
if(err ||!auth || !auth._auth) {
129+
res.send(400, err);
130+
return;
131+
}
132+
logger.log("info", "Publising the screenshot for " + req.params.id);
133+
request.get({uri:"https://" + burrowBase + "/registry/" + req.params.id, json:true}, function(err, result, body) {
134+
if (err) {
135+
logger.log("error", "Tried to publish a screenshot to nonexistent package " + req.params.id);
136+
res.send(400, err);
137+
return;
138+
}
139+
140+
var putReq = request.put({uri:"https://" + burrowBase + "/registry/" + req.params.id + "/screenshot.png?rev=" + body._rev , headers:{"Content-Type":"image/png", Authorization:"Basic " + auth._auth}});
141+
putReq.on("error", function(err) {
142+
console.log("error", "Error uploading the screenshot: " + err);
143+
res.send(400, err);
144+
});
145+
putReq.on("end", function() {
146+
res.send(200);
147+
});
148+
req.resume();
149+
req.pipe(putReq);
150+
});
151+
})
152+
}
153+
154+
function getScreenshot(req, res) {
155+
if (!regIndex[req.params.id])
156+
res.redirect("/Me/dashboardv3/img/batman.jpg");
157+
else
158+
res.redirect("https://" + burrowBase + "/registry/" + req.params.id + "/screenshot.png");
159+
}
160+
120161
// verify the validity of a package
121162
function verify(pkg)
122163
{

0 commit comments

Comments
 (0)