A music player that connects to your cloud/distributed storage. diffuse.sh
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162import { createClient } from "~/components/input/s3/common.js";import { ostiary, rpc } from "~/common/worker.js";
import { OBJECT_PREFIX } from "./constants.js";
/** * @import {S3OutputWorkerActions} from "@specs/components/output/bytes/s3/types.d.ts" */
////////////////////////////////////////////// ACTIONS////////////////////////////////////////////
/** * @type {S3OutputWorkerActions["get"]} */export async function get({ bucket, name }) { try { const client = createClient(bucket); const path = bucket.path.replace(/(^\/+|\/+$)/g, ""); const key = path ? `${path}/${OBJECT_PREFIX}${name}` : `${OBJECT_PREFIX}${name}`;
const response = await client.getObject(key); const buffer = await response.arrayBuffer(); return new Uint8Array(buffer); } catch (_err) { // Object doesn't exist yet, or client creation failed — return undefined return undefined; }}
/** * @type {S3OutputWorkerActions["put"]} */export async function put({ bucket, data, name }) { try { const client = createClient(bucket); const path = bucket.path.replace(/(^\/+|\/+$)/g, ""); const key = path ? `${path}/${OBJECT_PREFIX}${name}` : `${OBJECT_PREFIX}${name}`;
await client.putObject(key, data); } catch (err) { console.error("Failed to put S3 object:", err); throw err; }}
////////////////////////////////////////////// ⚡️////////////////////////////////////////////
ostiary((context) => { rpc(context, { get, put, });});