feat: #12695 Topic Synchronization via resolvable context

- Generation of a context collection digest via object ids
- Sending of said digest in ETag header
- Parsing of digests via If-None-Match header
- Update note assertion logic to handle 304 response
This commit is contained in:
Julian Lam
2024-07-16 11:37:38 -04:00
parent da25fd21ea
commit ff0c289e1d
4 changed files with 73 additions and 9 deletions

View File

@@ -4,6 +4,7 @@ const { generateKeyPairSync } = require('crypto');
const nconf = require('nconf');
const validator = require('validator');
const cheerio = require('cheerio');
const crypto = require('crypto');
const meta = require('../meta');
const posts = require('../posts');
@@ -19,6 +20,7 @@ const webfingerCache = ttl({
max: 5000,
ttl: 1000 * 60 * 60 * 24, // 24 hours
});
const sha256 = payload => crypto.createHash('sha256').update(payload).digest('hex');
const Helpers = module.exports;
@@ -403,3 +405,20 @@ Helpers.generateCollection = async ({ set, method, page, perPage, url }) => {
return object;
};
Helpers.generateDigest = (set) => {
if (!(set instanceof Set)) {
throw new Error('[[error:invalid-data]]');
}
return Array
.from(set)
.map(item => sha256(item))
.reduce((memo, cur) => {
const a = Buffer.from(memo, 'hex');
const b = Buffer.from(cur, 'hex');
// eslint-disable-next-line no-bitwise
const result = a.map((x, i) => x ^ b[i]);
return result.toString('hex');
});
};