mirror of
https://github.com/spacebarchat/server.git
synced 2026-10-22 19:43:16 +00:00
Merge branch 'spacebarchat:master' into removeStupidPolies
This commit is contained in:
10 files changed
+310
-47
No files matched your search
@@ -44,6 +44,12 @@ export const MemberPrivateProjection: (keyof Member)[] = [
|
||||
"roles",
|
||||
"settings",
|
||||
"user",
|
||||
"avatar",
|
||||
"banner",
|
||||
"bio",
|
||||
"theme_colors",
|
||||
"pronouns",
|
||||
"communication_disabled_until",
|
||||
];
|
||||
|
||||
@Entity({
|
||||
|
||||
+25
-1
@@ -147,8 +147,31 @@ export async function generateToken(id: string) {
|
||||
});
|
||||
}
|
||||
|
||||
let lastFsCheck: number;
|
||||
let cachedKeypair: {
|
||||
privateKey: crypto.KeyObject;
|
||||
publicKey: crypto.KeyObject;
|
||||
fingerprint: string;
|
||||
}
|
||||
|
||||
// Get ECDSA keypair from file or generate it
|
||||
export async function loadOrGenerateKeypair() {
|
||||
if (cachedKeypair) {
|
||||
// check for file deletion every minute
|
||||
if (Date.now() - lastFsCheck > 60000) {
|
||||
if (!existsSync("jwt.key") || !existsSync("jwt.key.pub")) {
|
||||
console.log("[JWT] Keypair files disappeared... Saving them again.");
|
||||
await Promise.all([
|
||||
fs.writeFile("jwt.key", cachedKeypair.privateKey.export({ format: "pem", type: "sec1" })),
|
||||
fs.writeFile("jwt.key.pub", cachedKeypair.publicKey.export({ format: "pem", type: "spki" })),
|
||||
]);
|
||||
}
|
||||
lastFsCheck = Date.now();
|
||||
}
|
||||
|
||||
return cachedKeypair;
|
||||
}
|
||||
|
||||
let privateKey: crypto.KeyObject;
|
||||
let publicKey: crypto.KeyObject;
|
||||
|
||||
@@ -185,5 +208,6 @@ export async function loadOrGenerateKeypair() {
|
||||
.update(publicKey.export({ format: "pem", type: "spki" }))
|
||||
.digest("hex");
|
||||
|
||||
return { privateKey, publicKey, fingerprint };
|
||||
lastFsCheck = Date.now();
|
||||
return cachedKeypair = { privateKey, publicKey, fingerprint };
|
||||
}
|
||||
Reference in new issue
Block a user