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

object-storage-ovh

v1.0.10

Published

Simple library to use OVH Public Cloud Object Storage.

Downloads

96

Readme

ObjectStorage OVH

Simple library to use OVH Public Cloud Object Storage. Create and manage containers (public, private or static), add and manage objects in OVH Public Cloud (OpenStack).

Based on developer.openstack.org official documentation.

Forkde from Dimer47 ObjectStorage OVh repository.

🎉 Features

  • Get account details and manage metas (create, update, has, get or delete),
  • Create, list, get details or delete containers,
  • Check if object exist in a container,
  • Define metas (create, update, has, get or delete) for container,
  • List files on a container,
  • Import object on container
  • Download or get content of object,
  • Delete all object in containers,
  • Program automatic delete of an object on datetime or after seconds,
  • Manage metas on objects (create, update, has, get or delete).

📍 Install via npm

npm install object-storage-ovh --save

🧮 Examples :

Authentification

Requesting a token to make operations on container.

var OVHStorage = require("object-storage-ovh");
var config = {
  username: "******",
  password: "******",
  authURL: "https://auth.cloud.ovh.net/v3/auth",
  tenantId: "******",
  region: "SBG",
};

(async () => {
  try {
    let storage = new OVHStorage(config);
    await storage.connection();
  } catch (e) {
    // throw e
  }
})();

Account

Available methods :

  • all() : Object of account details and list containers (Promise)
  • details() : Object (Promise)
  • containers() : Array of each container object (Promise)
  • metas()
    • create( container, key, value ) : Header response (Promise)
    • create_with_result( container, key, value ) : Boolean (Promise)
    • update( container, key, value ) : Header response (Promise)
    • update_with_result( container, key, value ) : Boolean (Promise)
    • delete( container, key ) : Header response (Promise)
    • delete_with_result( container, key ) : Boolean (Promise)
    • all( container ) : Object of metas (Promise)
    • has( container, key ) : Boolean (Promise)
    • get( container, key ) : String or null (Promise)

Create

var OVHStorage = require('object-storage-ovh');
var config = {
    ...
};

(async () => {
    try {
        let storage = new OVHStorage(config);
        await storage.connection();

        await storage.containers().create("private-files");
        await storage.containers().create("assets", "static", {
            index:'index.html',
            css: 'style.css',
            error: 'error.html',
        });
        // or with boolean result
        console.log(await storage.containers().create_with_result("images", "public"));
    } catch (e) {
        // throw e
    }
})();

Delete

var OVHStorage = require('object-storage-ovh');
var config = {
    ...
};

(async () => {
	try {
		let storage = new OVHStorage(config);
		await storage.connection();

        await storage.containers().delete("assets");
        // or with boolean result
        console.log(await storage.containers().delete_with_result("images"));

	} catch (e) {
        // throw e
	}
})();

Delete (container and all objects inside)

var OVHStorage = require('object-storage-ovh');
var config = {
    ...
};

(async () => {
	try {
		let storage = new OVHStorage(config);
		await storage.connection();

        await storage.containers().delete("assets", true);
        // or with boolean result
        console.log(await storage.containers().delete_with_result("images", true));

	} catch (e) {
        // throw e
	}
})();

Remove all object in container

var OVHStorage = require('object-storage-ovh');
var config = {
    ...
};

(async () => {
	try {
		let storage = new OVHStorage(config);
		await storage.connection();

        await storage.containers().delete_objects("assets");
        // or with boolean result
        console.log(await storage.containers().delete_objects_with_result("images"));

	} catch (e) {
        // throw e
	}
})();

List all object in container

var OVHStorage = require('object-storage-ovh');
var config = {
    ...
};

(async () => {
	try {
		let storage = new OVHStorage(config);
		await storage.connection();

        let objects = await storage.containers().list("assets");
        console.log(objects);
	} catch (e) {
        // throw e
	}
})();

Check if container exist

var OVHStorage = require('object-storage-ovh');
var config = {
    ...
};

(async () => {
	try {
		let storage = new OVHStorage(config);
		await storage.connection();

        if(await storage.containers().exist("assets"))
            console.log("Assets container exist !");
	} catch (e) {
        // throw e
	}
})();

Details about container

var OVHStorage = require('object-storage-ovh');
var config = {
    ...
};

(async () => {
	try {
		let storage = new OVHStorage(config);
		await storage.connection();

        let details  = await storage.containers().info("assets");
        console.log(details);
	} catch (e) {
        // throw e
	}
})();

Meta informations of container

var OVHStorage = require('object-storage-ovh');
var config = {
    ...
};

(async () => {
    try {
        let storage = new OVHStorage(config);
        await storage.connection();

        // list all metas of container
        await storage.containers().metas().all("assets");

        // create a new meta author
        await storage.containers().metas().create("assets", "author", "me");

        // retrieve value of author meta
        console.log(await storage.containers().metas().get("assets", "author"));

        // update value of author meta
        await storage.containers().metas().update("assets", "author", 'unknown');

        // if meta author exist on container name "assets", remove it
        if(await storage.containers().metas().has("assets", "author"))
            await storage.containers().metas().delete("assets", "author");
	} catch (e) {
        // throw e
	}
})();

Containers

Available methods :

  • create( container, types, web*content_pages ) *: Header response (Promise)_
  • create_with_result( container, types, web*content_pages ) *: Boolean_
  • list( container ) : Object (Promise)
  • exist( container ) : Boolean (Promise)
  • info( container ) : Header response (Promise)
  • delete_objects( container ) : Object (Promise)
  • delete_objects_with_result( container ) : Boolean (Promise)
  • delete( container, force=false ) : Header response (Promise)
  • delete_with_result( container, force=false ) : Boolean (Promise)
  • metas()
    • create( container, key, value ) : Header response (Promise)
    • create_with_result( container, key, value ) : Boolean (Promise)
    • update( container, key, value ) : Header response (Promise)
    • update_with_result( container, key, value ) : Boolean (Promise)
    • delete( container, key ) : Header response (Promise)
    • delete_with_result( container, key ) : Boolean (Promise)
    • all( container ) : Object of metas (Promise)
    • has( container, key ) : Boolean (Promise)
    • get( container, key ) : String or null (Promise)

Create

var OVHStorage = require('object-storage-ovh');
var config = {
    ...
};

(async () => {
    try {
        let storage = new OVHStorage(config);
        await storage.connection();

        await storage.containers().create("private-files");
        await storage.containers().create("assets", "static", {
            index:'index.html',
            css: 'style.css',
            error: 'error.html',
        });
        // or with boolean result
        console.log(await storage.containers().create_with_result("images", "public"));
    } catch (e) {
        // throw e
    }
})();

Delete

var OVHStorage = require('object-storage-ovh');
var config = {
    ...
};

(async () => {
	try {
		let storage = new OVHStorage(config);
		await storage.connection();

        await storage.containers().delete("assets");
        // or with boolean result
        console.log(await storage.containers().delete_with_result("images"));

	} catch (e) {
        // throw e
	}
})();

Delete (container and all objects inside)

var OVHStorage = require('object-storage-ovh');
var config = {
    ...
};

(async () => {
	try {
		let storage = new OVHStorage(config);
		await storage.connection();

        await storage.containers().delete("assets", true);
        // or with boolean result
        console.log(await storage.containers().delete_with_result("images", true));

	} catch (e) {
        // throw e
	}
})();

Remove all object in container

var OVHStorage = require('object-storage-ovh');
var config = {
    ...
};

(async () => {
	try {
		let storage = new OVHStorage(config);
		await storage.connection();

        await storage.containers().delete_objects("assets");
        // or with boolean result
        console.log(await storage.containers().delete_objects_with_result("images"));

	} catch (e) {
        // throw e
	}
})();

List all object in container

var OVHStorage = require('object-storage-ovh');
var config = {
    ...
};

(async () => {
	try {
		let storage = new OVHStorage(config);
		await storage.connection();

        let objects = await storage.containers().list("assets");
        console.log(objects);
	} catch (e) {
        // throw e
	}
})();

Check if container exist

var OVHStorage = require('object-storage-ovh');
var config = {
    ...
};

(async () => {
	try {
		let storage = new OVHStorage(config);
		await storage.connection();

        if(await storage.containers().exist("assets"))
            console.log("Assets container exist !");
	} catch (e) {
        // throw e
	}
})();

Details about container

var OVHStorage = require('object-storage-ovh');
var config = {
    ...
};

(async () => {
	try {
		let storage = new OVHStorage(config);
		await storage.connection();

        let details  = await storage.containers().info("assets");
        console.log(details);
	} catch (e) {
        // throw e
	}
})();

Meta informations of container

var OVHStorage = require('object-storage-ovh');
var config = {
    ...
};

(async () => {
    try {
        let storage = new OVHStorage(config);
        await storage.connection();

        // list all metas of container
        await storage.containers().metas().all("assets");

        // create a new meta author
        await storage.containers().metas().create("assets", "author", "me");

        // retrieve value of author meta
        console.log(await storage.containers().metas().get("assets", "author"));

        // update value of author meta
        await storage.containers().metas().update("assets", "author", 'unknown');

        // if meta author exist on container name "assets", remove it
        if(await storage.containers().metas().has("assets", "author"))
            await storage.containers().metas().delete("assets", "author");
	} catch (e) {
        // throw e
	}
})();

Objects

  • save( file, path ) : Header response (Promise)
  • save_with_result( file, path ) : Header response (Promise)
  • set( file, path ) : Header response (Promise)
  • set_with_result( file, path ) : Header response (Promise)
  • exist( path ) : Boolean (Promise)
  • info( path ) : Header response (Promise)
  • get( path ) : Object with content and header response (Promise)
  • download( path, pathLocal ) : Boolean (Promise)
  • copy( pathOrigin, pathToPaste ) : Header response (Promise)
  • copy_with_result( ) : Boolean (Promise)
  • delete( path, checkContainer = true ) : Header response (Promise)
  • delete_with_result( path, checkContainer = true ) : Boolean (Promise)
  • deletes( path, checkContainer = true ) : Header response of all deleted files (Promise)
  • deletes_with_result( path, checkContainer = true ) : Boolean (Promise)
  • expire_at( path, expire*date ) *: Header response (Promise)_
  • expire_at_with_result( path, expire*date ) *: Boolean (Promise)_
  • expire_after( path, delete*seconds ) *: Header response (Promise)_
  • expire_after_with_result( path, delete*seconds ) *: Boolean (Promise)_
  • metas()
    • create( path, key, value ) : Header response (Promise)
    • create_with_result( path, key, value ) : Boolean (Promise)
    • update( path, key, value ) : Header response (Promise)
    • update_with_result( path, key, value ) : Boolean (Promise)
    • delete( path, key ) : Header response (Promise)
    • delete_with_result( path, key ) : Boolean (Promise)
    • all( path ) : Object of metas (Promise)
    • has( path, key ) : Boolean (Promise)
    • get( path, key ) : String or null (Promise)

Download object

var OVHStorage = require('object-storage-ovh');
var config = {
    ...
};

(async () => {
    try {
        let storage = new OVHStorage(config);
        await storage.connection();

        await storage.objects().download("/assets/IMG_1145.jpg", "./IMG_1145.jpg")
    } catch (e) {
        // throw e
    }
})();

Get object content

(async () => {
  try {
    let storage = new OVHStorage(config);
    await storage.connection();

    let rqt = await storage.objects().get("/assets/IMG_1145.jpg");
    console.log(rqt.content);
  } catch (e) {
    // throw e
  }
})();

Add object

(async () => {
  try {
    let storage = new OVHStorage(config);
    await storage.connection();

    await storage.objects().save("./IMG_1145.jpg", "/assets/IMG_1145.jpg");
    // or with boolean result
    console.log(
      await storage
        .objects()
        .save_with_result("./IMG_1145.jpg", "/assets/IMG_1145.jpg")
    );
  } catch (e) {
    // throw e
  }
})();

Clone object

(async () => {
  try {
    let storage = new OVHStorage(config);
    await storage.connection();

    await storage
      .objects()
      .copy("/assets/IMG_1145.jpg", "/assets/IMG_1145_2.jpg");
    // or with boolean result
    console.log(
      await storage
        .objects()
        .copy_with_result("/assets/IMG_1145.jpg", "/assets/IMG_1145_2.jpg")
    );
  } catch (e) {
    // throw e
  }
})();

Delete object

(async () => {
  try {
    let storage = new OVHStorage(config);
    await storage.connection();

    await storage.objects().delete("/assets/IMG_1145_2.jpg");
    // or with boolean result
    console.log(
      await storage.objects().delete_with_result("/assets/IMG_1145_2.jpg")
    );
  } catch (e) {
    // throw e
  }
})();

Details about object

(async () => {
  try {
    let storage = new OVHStorage(config);
    await storage.connection();

    let details = await storage.objects().info("/assets/IMG_1145.jpg");
    console.log(details);
  } catch (e) {
    // throw e
  }
})();

Programming object expiration at datetime (need momentjs)

(async () => {
  try {
    let storage = new OVHStorage(config);
    await storage.connection();

    await storage
      .objects()
      .expire_at("/assets/IMG_1145.jpg", moment().add("7", "days"));
    // or with boolean result
    console.log(
      await storage
        .objects()
        .expire_at_with_result(
          "/assets/IMG_1145.jpg",
          moment().add("7", "days")
        )
    );
  } catch (e) {
    // throw e
  }
})();

Programming object expiration after seconds

(async () => {
  try {
    let storage = new OVHStorage(config);
    await storage.connection();

    await storage.objects().expire_after("/assets/IMG_1145.jpg", 180);
    // or with boolean result
    console.log(
      await storage
        .objects()
        .expire_after_with_result("/assets/IMG_1145.jpg", 180)
    );
  } catch (e) {
    // throw e
  }
})();

Meta informations of container

var OVHStorage = require('object-storage-ovh');
var config = {
    ...
};

(async () => {
    try {
        let storage = new OVHStorage(config);
        await storage.connection();

        // list all metas of object
        await storage.objects().metas().all("/assets/IMG_1145.jpg");

        // create a new meta author
        await storage.objects().metas().create("/assets/IMG_1145.jpg", "author", "me");

        // retrieve value of author meta
        console.log(await storage.objects().metas().get("/assets/IMG_1145.jpg", "author"));

        // update value of author meta
        await storage.objects().metas().update("/assets/IMG_1145.jpg", "author", 'unknown');

        // if meta author exist on object, remove it
        if(await storage.objects().metas().has("/assets/IMG_1145.jpg", "author"))
            await storage.objects().metas().delete("/assets/IMG_1145.jpg", "author");
	} catch (e) {
        // throw e
	}
})();

🧾 License

Creative Commons Attribution Share Alike 4.0 International