feat: migrate datafile (token => uploader unid)

pull/177/head
tycrek 2 years ago
parent 6cc0cb3ffa
commit 4c4009207f
No known key found for this signature in database
GPG Key ID: FF8A54DCE404885A

@ -66,6 +66,27 @@ const migrate = (authFileName = 'auth.json'): Promise<Users> => new Promise(asyn
// Save the new users object to auth.json // Save the new users object to auth.json
fs.writeJson(authPath, newUsers, { spaces: '\t' }) fs.writeJson(authPath, newUsers, { spaces: '\t' })
.catch(reject)
// Migrate the datafile (token => uploader)
.then(() => data().get())
.then((fileData: [string, FileData][]) =>
// Wait for all the deletions and puts to finish
Promise.all(fileData.map(async ([key, file]) => {
// We need to use `newUsers` because `users` hasn't been re-assigned yet
const user = newUsers.users.find((user) => user.token === file.token!)?.unid ?? ''; // ? This is probably fine
// Because of the stupid way I wrote papito, we need to DEL before we can PUT
await data().del(key);
// PUT the new data
return data().put(key, { ...file, uploader: user });
})))
// We did it hoofuckingray
.then(() => log.success('Migrated all auth & file data to new auth system'))
.then(() => resolve(newUsers)) .then(() => resolve(newUsers))
.catch(reject); .catch(reject);
}); });

Loading…
Cancel
Save