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

supabase-ged

v1.0.2

Published

A file management utility for Supabase Storage API, supporting user-specific directories and file operations.

Downloads

192

Readme

Supabase Storage Manager

A simple utility for managing user-specific files and directories using the Supabase Storage API. This module allows you to create, rename, delete, move directories and upload, list, and delete files for each user.

Installation

To install the package via npm:

npm install supabase-ged

Usage

Importing the Module

Import the necessary functions from the supabase-ged package.

import {
  initializeSupabase,
  createDirectory,
  uploadFile,
  listUserFiles,
  renameDirectory,
  deleteDirectory,
  deleteFile,
  moveFile,
} from "supabase-ged";

Initializing Supabase Client

Before using any of the functions, initialize the Supabase client with your project URL and API key.

const supabaseUrl = "https://your-project.supabase.co";
const supabaseKey = "your-supabase-key";
initializeSupabase(supabaseUrl, supabaseKey);

Functionality

createDirectory(userId, directory)

Creates a directory for a user. The directory is created with a dummy .keep file to ensure that it exists in Supabase Storage.

createDirectory("user-id-123", "documents")
  .then(() => console.log("Directory created"))
  .catch((error) => console.error("Error:", error));

uploadFile(userId, directory, file)

Uploads a file to a specific user's directory.

const file = document.getElementById("file-input").files[0];
uploadFile("user-id-123", "documents", file)
  .then((filePath) => console.log("File uploaded to:", filePath))
  .catch((error) => console.error("Error uploading file:", error));

listUserFiles(userId, directory)

Lists all the files in a specified user's directory.

listUserFiles("user-id-123", "documents")
  .then((files) => console.log("Files in directory:", files))
  .catch((error) => console.error("Error listing files:", error));

renameDirectory(userId, oldDirectory, newDirectory)

Renames a directory for a user.

renameDirectory("user-id-123", "old-directory", "new-directory")
  .then(() => console.log("Directory renamed"))
  .catch((error) => console.error("Error renaming directory:", error));

deleteDirectory(userId, directory)

Deletes a directory and all its contents for a user.

deleteDirectory("user-id-123", "documents")
  .then(() => console.log("Directory deleted"))
  .catch((error) => console.error("Error deleting directory:", error));

deleteFile(userId, directory, fileName)

Deletes a specific file within a user's directory.

deleteFile("user-id-123", "documents", "file.txt")
  .then(() => console.log("File deleted"))
  .catch((error) => console.error("Error deleting file:", error));

moveFile(userId, sourceDirectory, targetDirectory, fileName)

Moves a file from one directory to another within a user's storage.

moveFile("user-id-123", "old-directory", "new-directory", "file.txt")
  .then(() => console.log("File moved"))
  .catch((error) => console.error("Error moving file:", error));

Error Handling

All functions return promises. If any operation fails, they will throw an error with an appropriate message. You can catch these errors using .catch() or try-catch blocks when working with async functions.

Example:

try {
  await createDirectory("user-id-123", "documents");
} catch (error) {
  console.error("Error creating directory:", error);
}

Notes

  • This module relies on Supabase Storage, so you need a Supabase project with a storage bucket (e.g., user-files).
  • All directories and files are user-specific. Make sure to use a unique identifier (like user-id) to isolate users' files.
  • File paths and directory names are sanitized with the escapePath function to ensure they are compatible with Supabase.

License

MIT License. See LICENSE for more details.