diff --git a/src/config.ts b/src/config.ts index f3b472e..cc14998 100644 --- a/src/config.ts +++ b/src/config.ts @@ -140,6 +140,10 @@ class Conf { static get nostrbuildEndpoint(): string { 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. */ static get uploader() { return Deno.env.get('DITTO_UPLOADER'); diff --git a/src/middleware/uploaderMiddleware.ts b/src/middleware/uploaderMiddleware.ts index 8279a12..b0ee570 100644 --- a/src/middleware/uploaderMiddleware.ts +++ b/src/middleware/uploaderMiddleware.ts @@ -1,3 +1,5 @@ +import { BlossomUploader } from '@nostrify/nostrify/uploaders'; + import { AppMiddleware } from '@/app.ts'; import { Conf } from '@/config.ts'; import { DenoUploader } from '@/uploaders/DenoUploader.ts'; @@ -8,6 +10,8 @@ import { fetchWorker } from '@/workers/fetch.ts'; /** Set an uploader for the user. */ export const uploaderMiddleware: AppMiddleware = async (c, next) => { + const signer = c.get('signer'); + switch (Conf.uploader) { case 's3': c.set('uploader', new S3Uploader(Conf.s3)); @@ -21,6 +25,11 @@ export const uploaderMiddleware: AppMiddleware = async (c, next) => { case 'nostrbuild': c.set('uploader', new NostrBuildUploader({ endpoint: Conf.nostrbuildEndpoint, fetch: fetchWorker })); break; + case 'blossom': + if (signer) { + c.set('uploader', new BlossomUploader({ servers: Conf.blossomServers, signer, fetch: fetchWorker })); + } + break; } await next();