Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | 1x 1x 1x 1x 1x 11x 11x 1x 10x 10x 120x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 5x 5x 10x 5x 5x 5x 5x 4x 1x 1x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 5690x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 1x | /**
* Build a GDPR data export ZIP for a single user.
*
* Collects all personal data from Firestore, strips sensitive internal
* fields, and assembles a ZIP buffer using archiver.
*
* @param {string} uniqueId - The user's uniqueId
* @returns {Promise<{buffer: Buffer}>}
*/
const archiver = require('archiver');
const { db } = require('./firebase');
const { queryDocs } = require('./firestore-helpers');
const log = require('./log');
// Fields to strip from the profile (internal/sensitive)
const STRIP_FIELDS = [
'pinHash',
'pinSetAt',
'pinAttempts',
'pinLockedUntil',
'pinLockoutCount',
'firebaseUid',
'fcmTokens',
'dataExportR2Key',
'dataExportStatus',
'dataExportExpiresAt',
'lastDataExportRequestedAt',
'_testRun',
];
async function buildDataExport(uniqueId) {
// Read user doc
const userSnap = await db.doc(`users/${uniqueId}`).get();
if (!userSnap.exists) {
throw new Error('User not found');
}
const userData = { ...userSnap.data() };
// Strip sensitive fields
for (const field of STRIP_FIELDS) {
delete userData[field];
}
// Collect all data
const profile = { ...userData };
delete profile.followerIds;
delete profile.followingIds;
delete profile.blockedUserIds;
const settings = {
pmPrivacy: userData.pmPrivacy,
pmNotificationsEnabled: userData.pmNotificationsEnabled,
pmSoundEnabled: userData.pmSoundEnabled,
pmShowTimestamps: userData.pmShowTimestamps,
pmShowDateSeparators: userData.pmShowDateSeparators,
pmNotificationPreview: userData.pmNotificationPreview,
dndEnabled: userData.dndEnabled,
dndStartHour: userData.dndStartHour,
dndStartMinute: userData.dndStartMinute,
dndEndHour: userData.dndEndHour,
dndEndMinute: userData.dndEndMinute,
minGiftAnimationValue: userData.minGiftAnimationValue,
selfDestructAlertEnabled: userData.selfDestructAlertEnabled,
language: userData.language,
};
const followers = {
followerIds: userData.followerIds || [],
followingIds: userData.followingIds || [],
};
const blocked = { blockedUserIds: userData.blockedUserIds || [] };
const balance = {
shyCoins: userData.shyCoins || 0,
shyBeans: userData.shyBeans || 0,
luckScore: userData.luckScore || 0,
pityCounter: userData.pityCounter || 0,
};
// Subcollections
const backpack = await queryDocs(db.collection(`users/${uniqueId}/backpack`));
const giftWall = await queryDocs(db.collection(`users/${uniqueId}/giftWall`));
const transactions = await queryDocs(db.collection(`users/${uniqueId}/transactions`));
const warnings = await queryDocs(db.collection(`users/${uniqueId}/warnings`));
// Conversations (only user's own messages)
let conversations = [];
const userMessages = [];
try {
const convSnap = await db
.collection('conversations')
.where('participantIds', 'array-contains', Number.parseInt(uniqueId, 10))
.get();
const numericId = Number.parseInt(uniqueId, 10);
conversations = convSnap.docs.map((d) => {
const data = d.data();
return {
id: d.id,
type: data.type,
createdAt: data.createdAt,
updatedAt: data.updatedAt,
participantCount: data.participantIds ? data.participantIds.length : undefined,
userRole: data.roles ? data.roles[uniqueId] : undefined,
isUserOwner: data.ownerId === numericId,
};
});
// Collect user's own messages from each conversation (max 1000 total)
for (const conv of convSnap.docs) {
Iif (userMessages.length >= 1000) break;
try {
const remaining = 1000 - userMessages.length;
const msgSnap = await db
.collection(`conversations/${conv.id}/messages`)
.where('senderId', '==', uniqueId)
.orderBy('createdAt', 'desc')
.limit(remaining)
.get();
for (const m of msgSnap.docs) {
userMessages.push({ conversationId: conv.id, id: m.id, ...m.data() });
}
} catch (msgErr) {
log.error('data-export', 'Failed to query messages for conversation', {
uniqueId,
conversationId: conv.id,
error: msgErr.message,
});
}
}
} catch (err) {
log.error('data-export', 'Failed to query conversations', {
uniqueId,
error: err.message,
});
}
// Rooms owned by user
let roomsOwned = [];
try {
const roomSnap = await db.collection('rooms').where('ownerId', '==', uniqueId).get();
roomsOwned = roomSnap.docs.map((d) => ({ id: d.id, ...d.data() }));
} catch (err) {
log.error('data-export', 'Failed to query rooms', {
uniqueId,
error: err.message,
});
}
// Reports filed by user
let reportsFiled = [];
try {
const reportSnap = await db.collection('reports').where('reporterId', '==', uniqueId).get();
reportsFiled = reportSnap.docs.map((d) => ({ id: d.id, ...d.data() }));
} catch (err) {
log.error('data-export', 'Failed to query reports', {
uniqueId,
error: err.message,
});
}
// Appeals
let appeals = [];
try {
const appealSnap = await db
.collection('suspensionAppeals')
.where('userId', '==', uniqueId)
.get();
appeals = appealSnap.docs.map((d) => ({ id: d.id, ...d.data() }));
} catch (err) {
log.error('data-export', 'Failed to query appeals', {
uniqueId,
error: err.message,
});
}
// Identity
let identity = [];
try {
const idSnap = await db
.collection('identityMap')
.where('uniqueId', '==', Number.parseInt(uniqueId, 10))
.get();
identity = idSnap.docs.map((d) => ({ id: d.id, ...d.data() }));
} catch (err) {
log.error('data-export', 'Failed to query identity', {
uniqueId,
error: err.message,
});
}
// Device bindings
let deviceBindings = [];
try {
const bindSnap = await db
.collection('deviceBindings')
.where('uniqueId', '==', Number.parseInt(uniqueId, 10))
.get();
deviceBindings = bindSnap.docs.map((d) => ({ id: d.id, ...d.data() }));
} catch (err) {
log.error('data-export', 'Failed to query device bindings', {
uniqueId,
error: err.message,
});
}
// Build ZIP
const buffer = await new Promise((resolve, reject) => {
const chunks = [];
const archive = archiver('zip', { zlib: { level: 9 } });
archive.on('data', (chunk) => chunks.push(chunk));
archive.on('end', () => resolve(Buffer.concat(chunks)));
archive.on('error', reject);
const readme = [
'ShyTalk Data Export',
'===================',
'',
`User ID: ${uniqueId}`,
`Export date: ${new Date().toISOString()}`,
'',
'This ZIP contains all personal data associated with your ShyTalk account.',
'',
'Files:',
' profile.json — Your profile information',
' settings.json — Your privacy and notification settings',
' identity.json — Your linked sign-in providers',
' followers.json — Your followers and following lists',
' blocked.json — Your blocked users list',
' economy/ — Your coins, beans, transactions, and backpack',
' gifts/ — Your gift wall',
' conversations/ — Your conversation metadata and messages',
' rooms/ — Rooms you own',
' reports/ — Reports you filed and appeals',
' devices/ — Your device bindings',
' moderation/ — Your warning history',
].join('\n');
archive.append(readme, { name: 'README.txt' });
archive.append(JSON.stringify(profile, null, 2), { name: 'profile.json' });
archive.append(JSON.stringify(settings, null, 2), {
name: 'settings.json',
});
archive.append(JSON.stringify(identity, null, 2), {
name: 'identity.json',
});
archive.append(JSON.stringify(followers, null, 2), {
name: 'followers.json',
});
archive.append(JSON.stringify(blocked, null, 2), { name: 'blocked.json' });
archive.append(JSON.stringify(balance, null, 2), {
name: 'economy/balance.json',
});
archive.append(JSON.stringify(transactions.slice(0, 1000), null, 2), {
name: 'economy/transactions.json',
});
archive.append(JSON.stringify(backpack, null, 2), {
name: 'economy/backpack.json',
});
archive.append(JSON.stringify(giftWall, null, 2), {
name: 'gifts/gift-wall.json',
});
archive.append(JSON.stringify(conversations, null, 2), {
name: 'conversations/conversations.json',
});
archive.append(JSON.stringify(userMessages, null, 2), {
name: 'conversations/messages.json',
});
archive.append(JSON.stringify(roomsOwned, null, 2), {
name: 'rooms/rooms-owned.json',
});
archive.append(JSON.stringify(reportsFiled, null, 2), {
name: 'reports/reports-filed.json',
});
archive.append(JSON.stringify(appeals, null, 2), {
name: 'reports/appeals.json',
});
archive.append(JSON.stringify(deviceBindings, null, 2), {
name: 'devices/device-bindings.json',
});
archive.append(JSON.stringify(warnings, null, 2), {
name: 'moderation/warnings.json',
});
archive.finalize();
});
return { buffer };
}
module.exports = buildDataExport;
|