[taglist] display the image content digest per tag

Signed-off-by: Jakob Ackermann <das7pad@outlook.com>
This commit is contained in:
Jakob Ackermann 2019-09-02 18:16:07 +02:00
parent 41d71a1991
commit 04f4c204d8
No known key found for this signature in database
GPG key ID: 17FA08AA7E62A231
10 changed files with 173 additions and 12 deletions

View file

@ -22,6 +22,32 @@ function Http() {
this._headers = {};
}
Http.prototype.getContentDigest = function(cb) {
const headers = this.oReq.getAllResponseHeaders();
const start = headers.indexOf('etag: "sha256:');
if (start !== -1) {
// Same origin or advanced CORS headers set:
// 'Access-Control-Expose-Headers: ETag'
cb(headers.slice(start + 7, headers.indexOf('"', start + 7)))
} else if (window.crypto && window.TextEncoder) {
crypto.subtle.digest(
'SHA-256',
new TextEncoder().encode(this.oReq.responseText)
).then(function (buffer) {
cb(
'sha256:' + Array.from(
new Uint8Array(buffer)
).map(function(byte) {
return byte.toString(16).padStart(2, '0');
}).join('')
);
})
} else {
// IE and old Edge
// simply do not call the callback and skip the setup downstream
}
};
Http.prototype.addEventListener = function(e, f) {
this._events[e] = f;
const self = this;