0.1.7 • Published 11 months ago

@ssc-hermes/public-blobs v0.1.7

Weekly downloads
-
License
AGPL-3.0-or-later
Repository
github
Last release
11 months ago

public blobs tests

Write content addressed blobs to cloudinary, using a blake3 hash algorithm.

example

write a file

Write a base64 encoded blob to cloudinary, get a hash in response.

import dotenv from 'dotenv'
import { test } from 'tapzero'
import { Blobs } from '@ssc-hermes/public-blobs'
import { v2 } from 'cloudinary'
dotenv.config()
const cloudinary = v2

const config = {
    cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
    api_key: process.env.CLOUDINARY_API_KEY,
    api_secret: process.env.CLOUDINARY_API_SECRET
}

const base64file = 'data:image/png;base64,...'
cloudinary.config(config)

let blobs
test('create a cloudinary', async t => {
    blobs = Blobs(cloudinary)
    t.ok(blobs, 'blobs exists')
})

test('blobs.write', async t => {
    // `hash` is a url-safe string
    const { hash } = await blobs.write(base64file)

    t.ok(hash, 'hash exists')
    t.equal(hash, 'QyATP2PuM7EajnUt0IQlc5eRNsjQePxl9E_5YLpNGR0',
        'should return the expected hash')
})

get a file

Then use @cloudinary/url-gen to get the file by hash:

import { scale } from "@cloudinary/url-gen/actions/resize"
import { Cloudinary } from '@cloudinary/url-gen'

const cld = new Cloudinary({
    cloud: { cloudName: 'test' },
    url: {
        secure: true // force https, set to false to force http
    }
})

const url = cld
    .image(hash)
    .resize( scale().width(100) )
    .toURL()
0.1.7

11 months ago

0.1.5

11 months ago

0.1.0

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago