a cache for slack profile pictures and emojis

feat: add displayName to the user endpoint

Changed files
+22 -5
src
+12 -4
src/cache.ts
···
*/
interface User extends CacheItem {
type: "user";
+
displayName: string;
userId: string;
}
···
CREATE TABLE IF NOT EXISTS users (
id TEXT PRIMARY KEY,
userId TEXT UNIQUE,
+
displayName TEXT,
imageUrl TEXT,
expiration INTEGER
)
···
* @param expirationHours Optional custom expiration time in hours
* @returns boolean indicating success
*/
-
async insertUser(userId: string, imageUrl: string, expirationHours?: number) {
+
async insertUser(
+
userId: string,
+
displayName: string,
+
imageUrl: string,
+
expirationHours?: number,
+
) {
const id = crypto.randomUUID();
const expiration =
Date.now() + (expirationHours || this.defaultExpiration) * 3600000;
try {
this.db.run(
-
`INSERT INTO users (id, userId, imageUrl, expiration)
-
VALUES (?, ?, ?, ?)
+
`INSERT INTO users (id, userId, displayName, imageUrl, expiration)
+
VALUES (?, ?, ?, ?, ?)
ON CONFLICT(userId)
DO UPDATE SET imageUrl = ?, expiration = ?`,
-
[id, userId, imageUrl, expiration, imageUrl, expiration],
+
[id, userId, displayName, imageUrl, expiration, imageUrl, expiration],
);
return true;
} catch (error) {
···
type: "user",
id: result.id,
userId: result.userId,
+
displayName: result.displayName,
imageUrl: result.imageUrl,
expiration: new Date(result.expiration),
};
+10 -1
src/index.ts
···
});
}
-
await cache.insertUser(slackUser.id, slackUser.profile.image_512);
+
await cache.insertUser(
+
slackUser.id,
+
slackUser.profile.display_name_normalized,
+
slackUser.profile.image_512,
+
);
return {
id: slackUser.id,
expiration: new Date().toISOString(),
user: slackUser.id,
+
displayName: slackUser.profile.display_name_normalized,
image: slackUser.profile.image_512,
};
}
···
id: user.id,
expiration: user.expiration.toISOString(),
user: user.userId,
+
displayName: user.displayName,
image: user.imageUrl,
};
},
···
}),
user: t.String({
default: "U12345678",
+
}),
+
displayName: t.String({
+
default: "krn",
}),
image: t.String({
default: