♻️ cli: better information about file history and key (#525)

This commit is contained in:
Eric Doughty-Papassideris
2024-09-17 17:03:36 +02:00
parent 2eb6f73312
commit c9db0bf3d7
@@ -20,11 +20,11 @@ async function makeUserCache(platform: TdrivePlatform) {
.getProvider<DatabaseServiceAPI>("database")
.getRepository<User>(User_TYPE, User);
const cache: { [id: string]: User } = {};
return async id => {
if (id in cache) return cache[id];
return async (id): Promise<[boolean, User]> => {
if (id in cache) return [true, cache[id]];
const user = await usersRepo.findOne({ id });
if (user) cache[id] = user;
return user;
return [false, user];
};
}
@@ -36,8 +36,10 @@ interface ListArguments {
async function report(platform: TdrivePlatform, args: ListArguments) {
const users = await makeUserCache(platform);
async function formatUser(id) {
const user = await users(id);
return user?.email_canonical || id;
const [wasKnown, user] = await users(id);
return user?.email_canonical
? user.email_canonical + (wasKnown ? "" : ` (${id})`)
: `${JSON.stringify(id)} (user id not found)`;
}
const drivesRepo = await platform
.getProvider<DatabaseServiceAPI>("database")
@@ -60,7 +62,7 @@ async function report(platform: TdrivePlatform, args: ListArguments) {
console.error(` - URL encoded: ${encodeURIComponent(dfile.editing_session_key)}`);
console.error(` - applicationId: ${parsed.applicationId}`);
console.error(` - companyId: ${parsed.companyId}`);
console.error(` - instanceId: ${parsed.instanceId}`);
console.error(` - instanceId: ${JSON.stringify(parsed.instanceId)}`);
console.error(
` - userId: ${await formatUser(parsed.userId)} (${
parsed.userId === dfile.creator ? "same as creator ID" : "not the creator"