npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

revay-storage

v1.0.16

Published

revay-storage acts as a simple and efficient storage bridge that allows developers to use files for easy storage in a database. This package simplifies the file storage process by abstracting the complexities of file handling and preparing it for databas

Downloads

28

Readme

How revay-storage Works

revay-storage acts as a simple and efficient storage bridge that allows developers to use files for easy storage in a database. This package simplifies the file storage process by abstracting the complexities of file handling and preparing it for database storage. Key Features:

Database-Ready Format: It removes the need to store files in external storage services, allowing for a more lightweight and integrated approach.

Why Use revay-storage?

Simplified File Handling: Revay-storage enables developers to easily store and retrieve files directly from a database without additional storage layers like AWS S3 or other external file storage services.

Enhanced Security and Portability: Since the files are stored directly in the database , they benefit from database-level security. This can reduce dependencies on third-party storage providers while keeping data in a centralized place.

Quick Integration: revay-storage can be integrated into any system with minimal setup, making it ideal for applications where ease of storage is a priority, such as user profile pictures, document uploads, and other multimedia content.

Installation | JS

To get started with revay-storage, download the SDK as a zip file or use npm to install and include it in your project.

```javascript
npm i revay-storage;
```

Example

"use client";

import { useState } from 'react';
import { RevayStorage } from 'revay-storage';

const VideoUpload = () => {
    const [title, setTitle] = useState('');
    const [file, setFile] = useState<File | null>(null);
    const [preview, setPreview] = useState<string | null>(null);

    const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
        e.preventDefault();

        if (file) {
            await handleFile(file);
        }
    };

    async function handleFile(file: File) {
        try {
            const myfile = await RevayStorage(file);
            setPreview(myfile);
        } catch (error) {
            console.error("Error:", error);
        }
    }

    return (
        <form onSubmit={handleSubmit}>
            <input
                type="text"
                placeholder="Video Title"
                value={title}
                onChange={(e) => setTitle(e.target.value)}
                required
            />
            <input
                type="file"
                accept="video/*"
                onChange={(e: React.ChangeEvent<HTMLInputElement>) => setFile(e.target.files?.[0] || null)}
                required
            />
            <button type="submit">Upload Video</button>
            {preview && (
                <video controls width="300">
                    <source src={preview} type="video/mp4" />
                    Your browser does not support the video tag.
                </video>
            )}
        </form>
    );
};

export default VideoUpload;

Example 2: Use Cloudinary Preset as Unsigned and Cloud Name

"use client";

import { useState } from "react";
import { RevayuploadFile } from "revay-storage";

const name = "";
const preset = "";
const VideoUpload = () => {
  const [title, setTitle] = useState("");
  const [file, setFile] = useState<File | null>(null);
  const [preview, setPreview] = useState<string | null>(null);

  const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
    e.preventDefault();

    if (file) {
      await handleFile(file);
    }
  };

  async function handleFile(file: File) {
    try {
      const myfile = await RevayuploadFile(file, name, preset);

      console.log(myfile);
      setPreview(myfile as string);
    } catch (error) {
      console.error("Error:", error);
    }
  }

  return (
    <form onSubmit={handleSubmit}>
      <input
        type="text"
        placeholder="Video Title"
        value={title}
        onChange={(e) => setTitle(e.target.value)}
        required
      />
      <input
        type="file"
        accept="video/*"
        onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
          setFile(e.target.files?.[0] || null)
        }
        required
      />
      <button type="submit">Upload Video</button>
      {preview && (
        <video controls width="300">
          <source src={preview} type="video/mp4" />
          Your browser does not support the video tag.
        </video>
      )}
    </form>
  );
};

export default VideoUpload;

Example 3: Uploading File to DropBox

But the Url cannot be viewed in html tags because of CORS isue, but can be viewed in it's own page via it's own Url

Visit this link on how to generate accessKey:'https://dropbox.tech/developers/generate-an-access-token-for-your-own-account'

and Enable Scopped App Settings for files.write,files.permanent_delete and others

"use client";

import { useState } from "react";
import { deleteFileFromDropbox, uploadFileToDropbox } from "revay-storage";

const path = "/public";
const accessKey = "";
const VideoUpload = () => {
  const [title, setTitle] = useState("");
  const [file, setFile] = useState<File | null>(null);
  const [preview, setPreview] = useState<string | null>(null);
  const [id, setId] = useState<string | null>(null);

  const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
    e.preventDefault();

    if (file) {
      await handleFile(file);
    }
  };

  async function handleFile(file: File) {
    try {
      const myfile = await uploadFileToDropbox(accessKey, file, path);

      console.log(myfile);
      setPreview(myfile.url as string);
      setId(myfile.path);
    } catch (error) {
      console.error("Error:", error);
    }
  }

  async function handleDelete() {
    try {
      const deleted = await deleteFileFromDropbox(accessKey, id as string);
    } catch (error) {
      console.error("Error", error);
    }
  }
  return (
    <form onSubmit={handleSubmit}>
      <input
        type="text"
        placeholder="Video Title"
        value={title}
        onChange={(e) => setTitle(e.target.value)}
        required
      />
      <input
        type="file"
        accept="video/*"
        onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
          setFile(e.target.files?.[0] || null)
        }
        required
      />
      <div className="flex flex-row gap-2">
        <button type="submit">Upload Video</button>
        {id && (
          <button type="button" onClick={handleDelete}>
            Delete
          </button>
        )}
      </div>
      {preview && (
        <video controls width="300">
          <source src={preview} type="video/mp4" />
          Your browser does not support the video tag.
        </video>
      )}
    </form>
  );
};

export default VideoUpload;

Example:4 Using Supabase Storage

"use client";

import { useState, useEffect } from "react";
import {
  initializeSupabase,
  deleteFileFromSupabase,
  UploadFileToSupabase,
} from "revay-storage";

const storage = "files"; // Specify the Supabase storage bucket

const VideoUpload = () => {
  const [title, setTitle] = useState("");
  const [file, setFile] = useState<File | null>(null);
  const [preview, setPreview] = useState<string | null>(null);
  const [fileName, setFileName] = useState<string | null>(null);
  const [supabaseClient, setSupabaseClient] = useState<any>(null);

  useEffect(() => {
    const initialize = async () => {
      //Initialize SupabaseClient
      const supabase = initializeSupabase(
        process.env.NEXT_PUBLIC_URL as string,
        process.env.NEXT_PUBLIC_ANON_KEY as string,
      );
      setSupabaseClient(supabase);
    };
    initialize();
  }, []);

  const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
    e.preventDefault();

    if (file && supabaseClient) {
      await handleFile(file);
    }
  };

  async function handleFile(file: File) {
    try {
      // Pass supabaseClient to the UploadImage function
      const { publicUrl, fileName: uploadedFileName } =
        await UploadFileToSupabase(supabaseClient, file, storage);

      console.log("Uploaded File:", publicUrl);
      setPreview(publicUrl); // Set video preview URL
      setFileName(uploadedFileName); // Save the file name for deletion
    } catch (error) {
      console.error("Error uploading file:", error);
    }
  }

  async function handleDelete() {
    try {
      if (fileName && supabaseClient) {
        // Pass supabaseClient to the deleteImage function
        await deleteFileFromSupabase(supabaseClient, fileName, storage);
        console.log(`Deleted file: ${fileName}`);

        // Clear the state after deletion
        setPreview(null);
        setFileName(null);
      }
    } catch (error) {
      console.error("Error deleting file:", error);
    }
  }

  return (
    <form onSubmit={handleSubmit}>
      <input
        type="text"
        placeholder="Video Title"
        value={title}
        onChange={(e) => setTitle(e.target.value)}
        required
      />
      <input
        type="file"
        accept="video/*"
        onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
          setFile(e.target.files?.[0] || null)
        }
        required
      />
      <div className="flex flex-row gap-2">
        <button type="submit">Upload Video</button>
        {fileName && (
          <button type="button" onClick={handleDelete}>
            Delete
          </button>
        )}
      </div>
      {preview && (
        <video controls width="300">
          <source src={preview} type="video/mp4" />
          Your browser does not support the video tag.
        </video>
      )}
    </form>
  );
};

export default VideoUpload;