Skip to content

Commit

Permalink
add ImageLayers.io service
Browse files Browse the repository at this point in the history
  • Loading branch information
andyshinn authored and Andy Shinn committed Nov 10, 2015
1 parent 6cf46ec commit 0c24199
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
43 changes: 43 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4286,6 +4286,49 @@ cache(function(data, match, sendBadge, request) {
});
}));

// ImageLayers.io integration.
camp.route(/^\/imagelayers\/(image\-size|layers)\/([^\/]+)\/([^\/]+)\/([^\/]*)\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
var type = match[1];
var user = match[2];
var repo = match[3];
var tag = match[4]
var format = match[5];
if (user === '_') {
user = 'library';
}
var path = user + '/' + repo;
var badgeData = getBadgeData(type, data);
var options = {
method: 'POST',
json: true,
body: {
"repos": [{"name": path, "tag": tag}]
},
uri: 'https://imagelayers.io:8888/registry/analyze'
};
request(options, function(err, res, buffer) {
if (err != null) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);
return;
}
try {
if (type == 'image-size') {
size = metric(buffer[0].repo.size) + "B";
badgeData.text[1] = size;
} else if (type == 'layers') {
badgeData.text[1] = buffer[0].repo.count;
}
badgeData.colorscheme = null;
badgeData.colorB = '#007ec6';
sendBadge(format, badgeData);
} catch(e) {
badgeData.text[1] = 'invalid';
sendBadge(format, badgeData);
}
});
}));

// Any badge.
camp.route(/^\/(:|badge\/)(([^-]|--)*?)-(([^-]|--)*)-(([^-]|--)+)\.(svg|png|gif|jpg)$/,
Expand Down
9 changes: 9 additions & 0 deletions try.html
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,15 @@ <h3 id="miscellaneous"> Miscellaneous </h3>
<td><img src='/docker/pulls/mashape/kong.svg' alt=''/></td>
<td><code>https://img.shields.io/docker/pulls/mashape/kong.svg</code></td>
</tr>
<tr><th data-keywords='imagelayers'> ImageLayers Size: </th>
<td><img src='/imagelayers/image-size/_/ubuntu/latest.svg' alt=''/></td>
<td><code>https://img.shields.io/imagelayers/image-size/_/ubuntu/latest.svg</code></td>
</tr>
</tr>
<tr><th data-keywords='imagelayers'> ImageLayers Layers: </th>
<td><img src='/imagelayers/layers/_/ubuntu/latest.svg' alt=''/></td>
<td><code>https://img.shields.io/imagelayers/layers/_/ubuntu/latest.svg</code></td>
</tr>
</tbody></table>

<h3 id="miscellaneous"> Longer Miscellaneous </h3>
Expand Down

0 comments on commit 0c24199

Please sign in to comment.