-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(WIP): use file storage blob storage instead of blob file man…
…ager
- Loading branch information
Showing
14 changed files
with
205 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,43 @@ | ||
import IORedis from "ioredis"; | ||
|
||
import { BlobStorage } from "@blobscan/db"; | ||
import { getBlobStorageManager } from "@blobscan/blob-storage-manager"; | ||
import type { BlobStorageManager } from "@blobscan/blob-storage-manager"; | ||
import { prisma } from "@blobscan/db"; | ||
import type { BlobscanPrismaClient } from "@blobscan/db"; | ||
|
||
import { BlobPropagator } from "./BlobPropagator"; | ||
import { env } from "./env"; | ||
|
||
function createBlobPropagator() { | ||
const availableStorages: BlobStorage[] = []; | ||
|
||
if (env.GOOGLE_STORAGE_ENABLED) { | ||
availableStorages.push(BlobStorage.GOOGLE); | ||
} | ||
|
||
if (env.POSTGRES_STORAGE_ENABLED) { | ||
availableStorages.push(BlobStorage.POSTGRES); | ||
} | ||
|
||
if (env.SWARM_STORAGE_ENABLED) { | ||
availableStorages.push(BlobStorage.SWARM); | ||
} | ||
|
||
async function createBlobPropagator( | ||
blobStorageManager: BlobStorageManager, | ||
prisma: BlobscanPrismaClient | ||
) { | ||
const connection = new IORedis(env.REDIS_URI, { maxRetriesPerRequest: null }); | ||
|
||
return new BlobPropagator(availableStorages, { | ||
return new BlobPropagator({ | ||
blobStorageManager, | ||
prisma, | ||
tmpBlobStorage: env.BLOB_PROPAGATOR_TMP_STORAGE, | ||
workerOptions: { | ||
connection, | ||
}, | ||
}); | ||
} | ||
const blobPropagator = | ||
env.BLOB_PROPAGATOR_ENABLED === true ? createBlobPropagator() : undefined; | ||
|
||
export { blobPropagator, createBlobPropagator }; | ||
let blobPropagator: BlobPropagator | undefined; | ||
|
||
async function getBlobPropagator() { | ||
if (!env.BLOB_PROPAGATOR_ENABLED) { | ||
return; | ||
} | ||
|
||
if (!blobPropagator) { | ||
const blobStorageManager = await getBlobStorageManager(); | ||
|
||
blobPropagator = await createBlobPropagator(blobStorageManager, prisma); | ||
} | ||
|
||
return blobPropagator; | ||
} | ||
|
||
export { getBlobPropagator, createBlobPropagator }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.