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

revolt-uploader

v1.1.5

Published

A utility script to allow easy uploads of files to revolt.

Downloads

21

Readme

Revolt Uploader

Revolt.js doesn't offer the ability to upload attachments, so here is a utility package to allow easy file uploads.

Installation

npm install revolt-uploader

It's as easy as that! :)

Usage

First, you have to import and initialize an uploader object.

// import the uploader library
const Uploader = require("revolt-uploader");

// you have to initialize a revolt.js client object as well.
// Then initialize the uploader and provide it with the client
const uploader = new Uploader(client);

Now you've got your uploader. All you have to do is to login your bot client using client.login("token")

After that, you can upload files to revolt's servers using the uploadFile method.

// you need to attach this to a message, meaning you need to have a message object
// you can get this by listening for the `message` event on the client object but this is up to you
client.on("message", (message) => {
  // the upload method will return an attachment id that you can add to the message
  Promise.allSettled([
    uploader.uploadFile("path/to/file", "file"),
    uploader.uploadFile("path/to/another/file", "another-file"),
  ]).then(attachments => { // we're using Promise.allSettled to asynchronously upload all of them
    attachments = attachments.map(attachment => attachment.value); // extracting the value from the promises
    // send the attachment to the channel
    message.channel.sendMessage({
        content: "Here is your file!",
        attachments: attachments // Note that attachments always has to be an array, even if you're only uploading one file
    });
    // All done!
  });

  // async/await approach:
  message.channel.sendMessage({
    content: "Here is your file!",
    attachments: [await uploader.uploadFile("/path/to/another/file", "file-name")]
  });
});

Uploading URLs

You can upload files from urls by using the uploadUrl method. It will stream the file from the url to autumn without saving the image on your machine. It works just like a normal file upload:

const id = await uploader.uploadUrl("url", "fileName");

Advanced usage

If you need to upload anything else than existing files, use the .upload(fileData, fileName) method. You can use any kind of data object for the fileData but have to specify the file name.

For example using a stream:

const https = require("https");

client.on("message", (message) => {
  https.get("<url>", (response) => {
    message.channel.sendMessage({
      content: "Downloaded file: ",
      attachments: [await uploader.upload(response, "file.filetype")]
    });
  });
});

Furthermore, it is possible to upload your content under different tags. The default tag is attachments. These tags are available:

  • attachments
  • avatars
  • backgrounds
  • icons
  • banners
  • emojis

All of these have different configurations and limits. See this file for the exact specifications.