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

waifuvault-node-api

v1.7.1

Published

Official Node API for waifuvault.moe

Downloads

15

Readme

waifuvault-node-api

tests

This contains the official API bindings for uploading, deleting and obtaining files with waifuvault.moe. Contains a full up to date API for interacting with the service

Installation

npm install waifuvault-node-api

Usage

This API contains 4 interactions:

  1. Upload File
  2. Get File Info
  3. Delete File
  4. Get File
  5. Modify Entry
  6. Create Bucket
  7. Get Bucket
  8. Delete Bucket

The package is namespaced to Waifuvault, so to import it, simply:

import Waifuvault from "waifuvault-node-api";

Each function takes a optional signal from an abort controller as the last argument, you may use this to abort the requests

Upload File

To Upload a file, use the uploadFile function. This function takes the following options as an object:

| Option | Type | Description | Required | Extra info | |-------------------|----------------------|-----------------------------------------------------------------------------------|-------------------------------------|-----------------------------------------------| | file | string or Buffer | The file to upload. can be a string to the file on disk or a Buffer | true only if url is not supplied | If url is supplied, this prop can't be set | | url | string | The URL to a file that exists on the internet | true only if file is not supplied | If file is supplied, this prop can't be set | | expires | string | A string containing a number and a unit (1d = 1day) | false | Valid units are m, h and d | | hideFilename | boolean | If true, then the uploaded filename won't appear in the URL | false | Defaults to false | | password | string | If set, then the uploaded file will be encrypted | false | | | filename | string | Only used if file is set and is a Buffer, will set the filename of the buffer | false | | | oneTimeDownload | boolean | if supplied, the file will be deleted as soon as it is accessed | false | | | bucketToken | string | if supplied, the file will be associated with the bucket | false | |

Using a URL:

import Waifuvault from "waifuvault-node-api";

const resp = await Waifuvault.uploadFile({
    url: "https://waifuvault.moe/assets/custom/images/08.png"
});
console.log(resp.url); // the file download URL

Using a Buffer:

import Waifuvault from "waifuvault-node-api";

const resp = await Waifuvault.uploadFile({
    file: Buffer.from("someData"),
    filename: "aCoolFile.jpg"
});
console.log(resp.url); // the file download URL

Using a a file path:

import Waifuvault from "waifuvault-node-api";

const resp = await Waifuvault.uploadFile({
    file: "./files/aCoolFile.jpg"
});
console.log(resp.url); // the file download URL

Get File Info

If you have a token from your upload. Then you can get file info. This results in the following info:

  • token
  • url
  • protected
  • retentionPeriod

Use the fileInfo function. This function takes the following options as parameters:

| Option | Type | Description | Required | Extra info | |-------------|-----------|--------------------------------------------------------------------|----------|-------------------| | token | string | The token of the upload | true | | | formatted | boolean | If you want the retentionPeriod to be human-readable or an epoch | false | defaults to false |

import Waifuvault from "waifuvault-node-api";

const info = await Waifuvault.fileInfo("someToken");
console.log(a.retentionPeriod); // 28407118974
console.log(a.url); // the file download URL

Human-readable timestamp:

import Waifuvault from "waifuvault-node-api";

const info = await Waifuvault.fileInfo("someToken", true);
console.log(a.retentionPeriod); // 328 days 18 hours 51 minutes 31 seconds

Delete File

To delete a file, you must supply your token to the deleteFile function.

This function takes the following options as parameters:

| Option | Type | Description | Required | Extra info | |---------|----------|------------------------------------------|----------|------------| | token | string | The token of the file you wish to delete | true | |

NOTE: deleteFile will only ever either return true or throw an exception if the token is invalid

import Waifuvault from "waifuvault-node-api";

const succsess = await Waifuvault.deleteFile("someToken");
console.log(succsess);

Get File

This lib also supports obtaining a file from the API as a Buffer by supplying either the token or the unique identifier of the file (epoch/filename).

Use the getFile function. This function takes the following options an object:

| Option | Type | Description | Required | Extra info | |------------|----------|--------------------------------------------------------------------------------------------------|------------------------------------|----------------------------------------------------------| | token | string | The token of the file you want to download | true only if filename is not set | if filename is set, then this can not be used | | filename | string | The Unique identifier of the file, this is the epoch time stamp it was uploaded and the filename | true only if token is not set | if token is set, then this can not be used | | password | string | The password for the file if it is protected | false | Must be supplied if the file is uploaded with password |

Important! The Unique identifier filename is the epoch/filename only if the file uploaded did not have a hidden filename, if it did, then it's just the epoch. For example: 1710111505084/08.png is the Unique identifier for a standard upload of a file called 08.png, if this was uploaded with hidden filename, then it would be 1710111505084.png

Obtain an encrypted file

import Waifuvault from "waifuvault-node-api";

// upload the file
const resp = await Waifuvault.uploadFile({
    url: "https://waifuvault.moe/assets/custom/images/08.png",
    password: "epic"
});

// download the file
const file = await Waifuvault.getFile({
    password: "epic",
    token: resp.token
});

console.log(file); // a Buffer

Obtain a file from Unique identifier

import Waifuvault from "waifuvault-node-api";

// download the file
const file = await Waifuvault.getFile({
    filename: "/1710111505084/08.png"
});

console.log(file); // a Buffer

Modify Entry

If you want to modify aspects of your entry such as password, removing password, decrypting the file, encrypting the file, changing the expiry, etc. you can use modifyEntry function

Use the modifyEntry function. This function takes the following options an object and one as a parameter:

| parameter | Type | Description | Required | |-----------|----------|------------------------------------------|----------| | token | string | The token of the file you want to modify | true |

Options:

| Option | Type | Description | Required | Extra info | |--------------------|-----------|----------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------|----------------------------------------------------------------------------------------| | password | string | The new password or the password you want to use to encrypt the file | false | | | previousPassword | string | If the file is currently protected or encrpyted and you want to change it, use this for the old password | true only if password is set and the file is currently protected | if the file is protected already and you want to change the password, this MUST be set | | customExpiry | string | a new custom expiry, see expires in uploadFile | false | | | hideFilename | boolean | make the filename hidden | false | for the new URL, check the response URL prop |

Set a password on a non-encrypted file:

import Waifuvault from "waifuvault-node-api";

const foo = await Waifuvault.modifyEntry("token", {
    password: "apple",
});
foo.protected; // true

Change a password:

import Waifuvault from "waifuvault-node-api";

const foo = await Waifuvault.modifyEntry("token", {
    password: "newPass",
    previousPassword: "apple",
});

foo.protected; // true

change expire:

import Waifuvault from "waifuvault-node-api";

await Waifuvault.modifyEntry("token", {
    customExpiry: "1d"
});

decrypt a file and remove the password:

import Waifuvault from "waifuvault-node-api";

const foo = await Waifuvault.modifyEntry("token", {
    password: "",
    previousPassword: "apple",
});

foo.protected; // false

Create bucket

Buckets are virtual collections that are linked to your IP and a token. When you create a bucket, you will receive a bucket token that you can use in Get Bucket to get all the files in that bucket

To create a bucket, use the createBucket function. This function does not take any arguments.

import Waifuvault from "waifuvault-node-api";

const resp = await Waifuvault.createBucket();
console.log(resp.token); // the token to the new bucket

Get Bucket

To get a bucket, you must use the getBucket function and supply the token. This function takes the following options as parameters:

| Option | Type | Description | Required | Extra info | |-------------|-----------|-------------------------|----------|-------------------| | token | string | The token of the bucket | true | |

This will respond with the bucket and all the files the bucket contains.

import Waifuvault from "waifuvault-node-api";

const bucket = await Waifuvault.getBucket("someToken");
console.log(bucket.token); //the token to the new bucket
console.log(bucket.files); // an array of files in this bucket

Delete Bucket

Deleting a bucket will delete the bucket and all the files it contains.

To delete a bucket, you must call the deleteBucket function with the following options as parameters:

| Option | Type | Description | Required | Extra info | |-------------|-----------|-----------------------------------|----------|-------------------| | token | string | The token of the bucket to delete | true | |

NOTE: deleteBucket will only ever either return true or throw an exception if the token is invalid

import Waifuvault from "waifuvault-node-api";

const respo = await Waifuvault.deleteBucket("someToken");
console.log(respo); // true