Git Product home page Git Product logo

blossom-server-sdk's Introduction

blossom-server-sdk

A collection of classes to for building blossom servers

Documentation

Metadata storage

all metadata storage classes implement the IBlobMetadataStore interface

interface IBlobMetadataStore {
  // blobs
  hasBlob(sha256: string): boolean | Promise<boolean>;
  getBlob(sha256: string): BlobMetadata | Promise<BlobMetadata>;
  addBlob(
    data: Omit<BlobMetadata, "url">,
  ): BlobMetadata | Promise<BlobMetadata>;
  removeBlob(sha256: string): boolean | Promise<boolean>;

  // blob owners
  hasOwner(sha256: string, pubkey: string): boolean | Promise<boolean>;
  addOwner(sha256: string, pubkey: string): boolean | Promise<boolean>;
  removeOwner(sha256: string, pubkey: string): boolean | Promise<boolean>;
  getOwnerBlobs(pubkey: string): BlobMetadata[] | Promise<BlobMetadata[]>;
}

SQLite Metadata store

The BlossomSQLite class can be used to store blob metadata in a sqlite database

import { BlossomSQLite } from "blossom-server-sdk/metadata/sqlite";

const metadataStore = new BlossomSQLite("./data/mysql.db");

await metadataStore.addBlob({
  sha256: "b1674191a88ec5cdd733e4240a81803105dc412d6c6708d53ab94fc248f4f553",
  size: 184929,
  type: "application/pdf",
  uploaded: Math.floor(Date.now() / 1000),
});

await metadataStore.addOwner(
  // blob hash
  "b1674191a88ec5cdd733e4240a81803105dc412d6c6708d53ab94fc248f4f553",
  // pubkey
  "266815e0c9210dfa324c6cba3573b14bee49da4209a9456f9484e5106cd408a5",
);

const blobs = await metadataStore.getOwnerBlobs(
  "266815e0c9210dfa324c6cba3573b14bee49da4209a9456f9484e5106cd408a5",
);

const orphaned = await metadataStore.getOrphanedBlobs();

for (let blob of orphaned) {
  await metadataStore.removeBlob(blob.sha256);
}

Blob Storage

all storage classes implement the IBlobStorage interface

interface IBlobStorage {
  setup(): Promise<void>;
  hasBlob(sha256: string): Promise<boolean>;
  writeBlob(sha256: string, stream: Readable, type?: string): Promise<void>;
  getBlobSize(sha256: string): number | Promise<number>;
  getBlobType(sha256: string): string | undefined | Promise<string | undefined>;
  readBlob(sha256: string): Promise<Readable>;
  removeBlob(sha256: string): Promise<void>;
}

Local Storage

A class that uses the built-in fs module in node to store blobs in the file system

import { LocalStorage } from "blossom-server-sdk/storage/local";
import https from "https";

const storage = new LocalStorage("./data");
await storage.setup();

const sha256 =
  "b1674191a88ec5cdd733e4240a81803105dc412d6c6708d53ab94fc248f4f553";

https.get(new URL(sha256, "https://cdn.satellite.earth"), async (res) => {
  const type = res.headers["content-type"];

  // write the blob to storage with the optional type
  await storage.writeBlob(sha256, res, type);
});

S3 Storage

A storage class that uses minio to store blobs in a s3 compatible API

import { S3Storage } from "blossom-server-sdk/storage/s3";
import https from "https";

const storage = new S3Storage("./data");
await storage.setup();

const sha256 =
  "b1674191a88ec5cdd733e4240a81803105dc412d6c6708d53ab94fc248f4f553";

https.get(new URL(sha256, "https://cdn.satellite.earth"), async (res) => {
  const type = res.headers["content-type"];

  // write the blob to s3 storage with the optional type
  await storage.writeBlob(sha256, res, type);
});

blossom-server-sdk's People

Contributors

hzrd149 avatar

Stargazers

 avatar Spencer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.