mirror of
https://github.com/aljazceru/ditto.git
synced 2026-02-06 22:14:20 +01:00
Load VAPID keys from configuration
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { generateVapidKeys } from '@negrel/webpush';
|
||||
import { encodeBase64 } from '@std/encoding/base64';
|
||||
import { exists } from '@std/fs/exists';
|
||||
import { generateSecretKey, nip19 } from 'nostr-tools';
|
||||
import question from 'question-deno';
|
||||
@@ -95,6 +97,15 @@ if (vars.DITTO_UPLOADER === 'local') {
|
||||
vars.MEDIA_DOMAIN = `https://${mediaDomain}`;
|
||||
}
|
||||
|
||||
const VAPID_PRIVATE_KEY = Deno.env.get('VAPID_PRIVATE_KEY');
|
||||
if (VAPID_PRIVATE_KEY) {
|
||||
vars.VAPID_PRIVATE_KEY = VAPID_PRIVATE_KEY;
|
||||
} else {
|
||||
const { privateKey } = await generateVapidKeys({ extractable: true });
|
||||
const bytes = await crypto.subtle.exportKey('pkcs8', privateKey);
|
||||
vars.VAPID_PRIVATE_KEY = encodeBase64(bytes);
|
||||
}
|
||||
|
||||
console.log('Writing to .env file...');
|
||||
|
||||
const result = Object.entries(vars).reduce((acc, [key, value]) => {
|
||||
|
||||
7
scripts/vapid.ts
Normal file
7
scripts/vapid.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { generateVapidKeys } from '@negrel/webpush';
|
||||
import { encodeBase64 } from '@std/encoding/base64';
|
||||
|
||||
const { privateKey } = await generateVapidKeys({ extractable: true });
|
||||
const bytes = await crypto.subtle.exportKey('pkcs8', privateKey);
|
||||
|
||||
console.log(encodeBase64(bytes));
|
||||
Reference in New Issue
Block a user