mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-24 05:05:20 -04:00
(feature)(profile) cards backup - base64
This commit is contained in:
parent
2ffa8f36e5
commit
534756668f
@ -910,15 +910,15 @@ router.get('/profile/export', handleErrorAsync(async (req, res) => {
|
||||
profiles,
|
||||
});
|
||||
|
||||
const payload = JSON.stringify({
|
||||
const payload = Buffer.from(JSON.stringify({
|
||||
version: 1,
|
||||
profiles,
|
||||
images,
|
||||
});
|
||||
})).toString('base64');
|
||||
|
||||
const signature = crypto.sign(payload);
|
||||
|
||||
res.setHeader('Content-disposition', `attachment; filename=pronounspage-${req.user.username}-${+new Date}.sjson.gz`);
|
||||
res.setHeader('Content-disposition', `attachment; filename=pronounspage-${req.user.username}-${+new Date}.card.gz`);
|
||||
res.setHeader('Content-type', 'application/gzip');
|
||||
res.end(
|
||||
zlib.gzipSync(
|
||||
@ -937,13 +937,18 @@ router.post('/profile/import', multer({limits: {fileSize: 10 * 1024 * 1024}}).an
|
||||
return res.status(401).json({error: 'One file expected'});
|
||||
}
|
||||
|
||||
const [payload, signature] = zlib.gunzipSync(req.files[0].buffer).toString('utf-8').split('\n');
|
||||
const contentParts = zlib.gunzipSync(req.files[0].buffer).toString('utf-8').split('\n');
|
||||
if (contentParts.length !== 2) {
|
||||
return res.status(401).json({error: 'profile.backup.error.signature'});
|
||||
}
|
||||
|
||||
const [payload, signature] = contentParts;
|
||||
|
||||
if (!crypto.validate(payload, signature)) {
|
||||
return res.status(400).json({error: 'profile.backup.error.signature'});
|
||||
}
|
||||
|
||||
const {version, profiles, images} = JSON.parse(payload);
|
||||
const {version, profiles, images} = JSON.parse(Buffer.from(payload, 'base64').toString('utf-8'));
|
||||
|
||||
const s3 = new S3(awsConfig);
|
||||
for (let [id, sizes] of Object.entries(images)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user