mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-25 11:27:31 -07:00
[backend] Generate VAPID keys during meta bootstrap
This commit is contained in:
parent
4006e74eca
commit
eadf9acdc3
1 changed files with 5 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
import { db } from "@/db/postgre.js";
|
import { db } from "@/db/postgre.js";
|
||||||
import { Meta } from "@/models/entities/meta.js";
|
import { Meta } from "@/models/entities/meta.js";
|
||||||
|
import push from 'web-push';
|
||||||
|
|
||||||
let cache: Meta;
|
let cache: Meta;
|
||||||
|
|
||||||
|
@ -46,12 +47,16 @@ export async function fetchMeta(noCache = false): Promise<Meta> {
|
||||||
cache = meta;
|
cache = meta;
|
||||||
return meta;
|
return meta;
|
||||||
} else {
|
} else {
|
||||||
|
const { publicKey, privateKey } = push.generateVAPIDKeys();
|
||||||
|
|
||||||
// If fetchMeta is called at the same time when meta is empty, this part may be called at the same time, so use fail-safe upsert.
|
// If fetchMeta is called at the same time when meta is empty, this part may be called at the same time, so use fail-safe upsert.
|
||||||
const saved = await transactionalEntityManager
|
const saved = await transactionalEntityManager
|
||||||
.upsert(
|
.upsert(
|
||||||
Meta,
|
Meta,
|
||||||
{
|
{
|
||||||
id: "x",
|
id: "x",
|
||||||
|
swPublicKey: publicKey,
|
||||||
|
swPrivateKey: privateKey,
|
||||||
},
|
},
|
||||||
["id"],
|
["id"],
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue