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

mtr-storage

v1.2.2

Published

Library ini menggunakan package [**multer v1.4.1**](https://www.npmjs.com/package/multer "multer") dan [**request-promise v4.2.2**](https://www.npmjs.com/package/request-promise) ### Installation ```bash npm i git+ssh://[email protected]/mtr-p

Downloads

6

Readme

Storage Library

Dependency

Library ini menggunakan package multer v1.4.1 dan request-promise v4.2.2

Installation

npm i git+ssh://[email protected]/mtr-platform/libs/storage#v1.2.2

Penggunaan

Simpan konfigurasi service API pada file .env.
Nama service yang menggunakan disimpan dalam SVC_NAME
dan Datastore Service API dalam SVC_DATASTORE.

SVC_NAME=svc_name
SVC_DATASTORE=http://datastore.meteor.test:80

Untuk router middleware

const { multipartMiddleware } = require('mtr-storage');

router.post('/propic', multipartMiddleware([{ name: 'propic', maxCount: 1 }]), (req, res) => {
  console.log(req.files.propic[0]);
  /* or use this if your node support es6 */
  const [file] = req.files.propic;
  console.log(file);
});

Implementasi dengan Validation Formatter Library

const { checkBody } = require('mtr-validator');

checkBody(req, {
  propic: {
    notEmpty: true,
    isMimeType: ['image/jpeg', 'image/png'],
    isMaxFile: 2000000,
  },
});

Upload file ke DataStore

uploadUpdate(file: [required File], fileName: [required String], pathName: [required String], uploadWithNewName: [default:false Bool], bucketName: [optional String])
  • upload function ke datastore Minio
  • jika fileName tidak kosong dan uploadWithNewName true, maka akan upload file dengan nama baru dan melakukan delete pada file sebelumnya
  • jika fileName tidak kosong dan uploadWithNewName false, maka akan upload file dengan meng-replace file sebelumnya
try {
  const filename = await uploadUpdate(file, fileName, pathName, uploadWithNewName, bucketName)
    .catch(() => {
      throw new Error('Failed update profile picture');
    });

  console.log(filename);
} catch (error) {
  console.log(error);
}
uploadCreate(file: [required File], fileName: [required String], pathName: [required String], bucketName: [optional String])
  • upload function ke datastore Minio
  • jika fileName tidak kosong maka akan upload file baru dengan tambahan suffix jumlah duplikat di filename, ex: yourfilename_2.jpg
try {
  const filename = await uploadCreate(file, fileName, pathName, bucketName)
    .catch(() => {
      throw new Error('Failed update profile picture');
    });

  console.log(filename);
} catch (error) {
  console.log(error);
}
uploadOSS(file: [required File], fileName: [required String], pathName: [required String], bucketName: [optional String], replace: [optional Boolean], uploadWithNewName: [optional Boolean])
  • upload function ke datastore OSS Alicloud
  • jika fileName tidak kosong maka akan upload file baru dengan tambahan suffix jumlah duplikat di filename, ex: yourfilename_2.jpg
  • jika replace bernilai true, maka fitur upload akan menghapus file pada OSS dengan nilai fileName yg sama, default bernilai false. fitur replace hanya akan berjalan apabila argumen uploadWithNewName bernilai True.
try {
  const filename = await uploadOSS(file, fileName, pathName, bucketName)
    .catch(() => {
      throw new Error('Failed update profile picture');
    });

  console.log(filename);
} catch (error) {
  console.log(error);
}

API

checkMiddleware(fields)

Untuk meng-handle multipart form dan memasukkan file dari request ke dalam req.files.
Selain itu, API ini juga menambahkan object metadata ke dalam req.body untuk pemggunaan pada lib validation.

Param | Jenis | Keterangan --- | --- | --- fields | Array | Array yang berisi daftar file.

upload(upload(file: FileUpload[, fileName?: string][, replace?: boolean]))

Upload Buffer ke Datastore server.

Param | Jenis | Keterangan --- | --- | --- file | Object | Object files dari multipartMiddleware. fileName | string | Nama file yang akan digunakan dalam storage.   |   | Jika kosong maka akan dibuatkan secara otomatis. Misal: '/assets/face.png' pathName | string | Path yang akan digunakan untuk menyimpan file replace | boolean | Jika true, maka akan menimpa file yang sudah ada

delete file DataStore

deleteFile(fileName: [required String], pathName: [required String], bucketName: [optional String])
try {
  const filename = await deleteFile(fileName, bucketName)
    .catch(() => {
      throw new Error('Failed update profile picture');
    });

  console.log(filename);
} catch (error) {
  console.log(error);
}