Add support for Blossom uploader

This commit is contained in:
Alex Gleason 2024-05-19 15:42:45 -05:00
parent 7c5b7c5d83
commit f0b247130f
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 13 additions and 0 deletions

View File

@ -140,6 +140,10 @@ class Conf {
static get nostrbuildEndpoint(): string { static get nostrbuildEndpoint(): string {
return Deno.env.get('NOSTRBUILD_ENDPOINT') || 'https://nostr.build/api/v2/upload/files'; return Deno.env.get('NOSTRBUILD_ENDPOINT') || 'https://nostr.build/api/v2/upload/files';
} }
/** Default Blossom servers to use when the `blossom` uploader is set. */
static get blossomServers(): string[] {
return Deno.env.get('BLOSSOM_SERVERS')?.split(',') || ['https://blossom.primal.net/'];
}
/** Module to upload files with. */ /** Module to upload files with. */
static get uploader() { static get uploader() {
return Deno.env.get('DITTO_UPLOADER'); return Deno.env.get('DITTO_UPLOADER');

View File

@ -1,3 +1,5 @@
import { BlossomUploader } from '@nostrify/nostrify/uploaders';
import { AppMiddleware } from '@/app.ts'; import { AppMiddleware } from '@/app.ts';
import { Conf } from '@/config.ts'; import { Conf } from '@/config.ts';
import { DenoUploader } from '@/uploaders/DenoUploader.ts'; import { DenoUploader } from '@/uploaders/DenoUploader.ts';
@ -8,6 +10,8 @@ import { fetchWorker } from '@/workers/fetch.ts';
/** Set an uploader for the user. */ /** Set an uploader for the user. */
export const uploaderMiddleware: AppMiddleware = async (c, next) => { export const uploaderMiddleware: AppMiddleware = async (c, next) => {
const signer = c.get('signer');
switch (Conf.uploader) { switch (Conf.uploader) {
case 's3': case 's3':
c.set('uploader', new S3Uploader(Conf.s3)); c.set('uploader', new S3Uploader(Conf.s3));
@ -21,6 +25,11 @@ export const uploaderMiddleware: AppMiddleware = async (c, next) => {
case 'nostrbuild': case 'nostrbuild':
c.set('uploader', new NostrBuildUploader({ endpoint: Conf.nostrbuildEndpoint, fetch: fetchWorker })); c.set('uploader', new NostrBuildUploader({ endpoint: Conf.nostrbuildEndpoint, fetch: fetchWorker }));
break; break;
case 'blossom':
if (signer) {
c.set('uploader', new BlossomUploader({ servers: Conf.blossomServers, signer, fetch: fetchWorker }));
}
break;
} }
await next(); await next();