1.0.3 • Published 3 years ago

akamai-netstorageapi v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

akamai-netstorageapi-typescript

Akamai Netstorage Typescript (UNOFFICIAL)

This is a complete typescript rewirte of a official NodeJS package for Akamai Netstorage

Table of Contents

Installation

To install Netstorage API with npm global:

$ npm install --global netstorageapi

or as a development dependency for your project:

$ npm install --save netstorageapi

Example

const Netstorage = require('netstorageapi')

// Defaults: SSL: false
// By default no proxy is set
const config = {
  hostname: '*******.akamaihd.net',
  keyName: 'DDDDDDDDDDDDDDDDDDDDDDDDDDDD',
  key: 'xxxxxxxxxx',
  cpCode: '407617',
  ssl: false,
  // proxy: 'https://yourproxyurl.com:port' // Optional
}
// Don't expose KEY on your public repository.

const ns = new Netstorage(config)
const local_source = 'hello.txt'

// or `/${config.cpCode}/` will asume the destination filename is the same as the source
const netstorage_destination = `/${config.cpCode}/hello.txt`

ns.upload(local_source, netstorage_destination, (error, response, body) => {
  if (error) { // errors other than http response codes
    console.log(`Got error: ${error.message}`)
  }
  if (response.statusCode == 200) {
    console.log(body)
  }
});

// Async Way
let response: Promise<UploadResponse> = await ns.uploadAsync(local_source, netstorage_destination)

// { message: 'Request Processed.' }

Methods

delete

↑ back to method list

  • Syntax:
ns.delete(NETSTORAGE_PATH, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_PATHstringfull path for the file, not the directory

deleteAsync

↑ back to method list

  • Syntax:
ns.deleteAsync(NETSTORAGE_PATH)
  • Parameters:

    NameTypeDescription
    NETSTORAGE_PATHstringfull path for the file, not the directory
  • Response: Promise

dir

↑ back to method list

  • Syntax:
ns.dir(NETSTORAGE_PATH|OPTIONS, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_PATHstringfull path for the directory
    OPTIONSobjectJSON object containing options for the dir method
  • Valid Options:

  { path: '/your/path',
    actions: {
      max_entries: integer,
      start: '/start/path',
      end: '/end/path/',
      prefix: 'object-prefix',
      slash: 'both'
    }
  }

dirAsync

↑ back to method list

  • Syntax:
ns.dirAsync(NETSTORAGE_PATH|OPTIONS)
  • Parameters:

    NameTypeDescription
    NETSTORAGE_PATHstringfull path for the directory
    OPTIONSDirListOptsJSON object containing options for the dir method
  • Valid Options:

  { path: '/your/path',
    actions: {
      max_entries: integer,
      start: '/start/path',
      end: '/end/path/',
      prefix: 'object-prefix',
      slash: 'both'
    }
  }
  • Response: Promise

list

↑ back to method list

  • Syntax:
ns.list(NETSTORAGE_PATH|OPTIONS, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_PATHstringfull path to the file/directory
    OPTIONSobjectJSON object containing options for the list method
  • Valid Options:

  { path: '/your/path',
    actions: {
      max_entries: integer,
      end: '/end/path/'
    }
  }

listAsync

↑ back to method list

  • Syntax:
ns.listAsync(NETSTORAGE_PATH|OPTIONS)
  • Parameters:

    NameTypeDescription
    NETSTORAGE_PATHstringfull path to the file/directory
    OPTIONSDirListOptsJSON object containing options for the list method
  • Valid Options:

  { path: '/your/path',
    actions: {
      max_entries: integer,
      end: '/end/path/'
    }
  }
  • Response: Promise

download

↑ back to method list

  • Syntax:
ns.download(NETSTORAGE_SOURCE, LOCAL_DESTINATION, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_SOURCEstringPath to the file in NetStorage
    LOCAL_DESTINATIONstringLocation on the local host to write the downloaded file to (Optional value)

downloadAsync

↑ back to method list

  • Syntax:
ns.downloadAsync(NETSTORAGE_SOURCE, LOCAL_DESTINATION)
  • Parameters:

    NameTypeDescription
    NETSTORAGE_SOURCEstringPath to the file in NetStorage
    LOCAL_DESTINATIONstringLocation on the local host to write the downloaded file to (Optional value)
  • Response: Promise

downloadBuffer

↑ back to method list

  • Syntax:
ns.downloadBuffer(NETSTORAGE_SOURCE, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_SOURCEstringPath to the file in NetStorage

downloadBufferAsync

↑ back to method list

  • Syntax:
ns.downloadBufferAsync(NETSTORAGE_SOURCE)
  • Parameters:

    NameTypeDescription
    NETSTORAGE_SOURCEstringPath to the file in NetStorage
  • Response: Promise

du

↑ back to method list

  • Syntax:
ns.du(NETSTORAGE_PATH, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_PATHstringfull path to the file/directory

duAsync

↑ back to method list

  • Syntax:
ns.duAsync(NETSTORAGE_PATH)
  • Parameters:

    NameTypeDescription
    NETSTORAGE_PATHstringfull path to the file/directory
  • Response: Promise

mkdir

↑ back to method list

  • Syntax:
ns.mkdir(DIRECTORY_NAME, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    DIRECTORY_NAMEstringFull path to the directory you wish to create

mkdirAsync

↑ back to method list

  • Syntax:
ns.mkdirAsync(DIRECTORY_NAME)
  • Parameters:

    NameTypeDescription
    DIRECTORY_NAMEstringFull path to the directory you wish to create
  • Response: Promise

mtime

↑ back to method list

  • Syntax:
ns.mtime(NETSTORAGE_PATH, UNIX_TIME, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_PATHstringfull path to the file/directory
    UNIX_TIMEintegerUnix time to set the mtime of the file to. Note that millisecond accuracy is not supported

mtimeAsync

↑ back to method list

  • Syntax:
ns.mtimeAsync(NETSTORAGE_PATH, UNIX_TIME)
  • Parameters:

    NameTypeDescription
    NETSTORAGE_PATHstringfull path to the file/directory
    UNIX_TIMEintegerUnix time to set the mtime of the file to. Note that millisecond accuracy is not supported
  • Response: Promise

quickDelete

↑ back to method list

  • Syntax:
ns.quickDelete(NETSTORAGE_DIR, callback(err, response, body)) // needs to be enabled on the CP Code
  • Parameters:

    NameTypeDescription
    NETSTORAGE_DIRstringfull path to the directory you wish to delete

quickDeleteAsync

↑ back to method list

  • Syntax:
ns.quickDeleteAsync(NETSTORAGE_DIR) // needs to be enabled on the CP Code
  • Parameters:

    NameTypeDescription
    NETSTORAGE_DIRstringfull path to the directory you wish to delete
  • Response: Promise

rename

↑ back to method list

  • Syntax:
ns.rename(NETSTORAGE_TARGET, NETSTORAGE_DESTINATION, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_TARGETstringfull path to the original file/directory
    NETSTORAGE_DESTINATIONstringfull path to the renamed file/directory

renameAsync

↑ back to method list

  • Syntax:
ns.renameAsync(NETSTORAGE_TARGET, NETSTORAGE_DESTINATION)
  • Parameters:

    NameTypeDescription
    NETSTORAGE_TARGETstringfull path to the original file/directory
    NETSTORAGE_DESTINATIONstringfull path to the renamed file/directory
  • Response: Promise

rmdir

↑ back to method list

  • Syntax:
ns.rmdir(NETSTORAGE_DIR, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_DIRstringfull path to the empty object you wish to delete

rmdirAsync

↑ back to method list

  • Syntax:
ns.rmdirAsync(NETSTORAGE_DIR)
  • Parameters:

    NameTypeDescription
    NETSTORAGE_DIRstringfull path to the empty object you wish to delete
  • Response: Promise

stat

↑ back to method list

  • Syntax:
ns.stat(NETSTORAGE_PATH, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_PATHstringfull path to the file/directory you wish to stat

statAsync

↑ back to method list

  • Syntax:
ns.statAsync(NETSTORAGE_PATH)
  • Parameters:

    NameTypeDescription
    NETSTORAGE_PATHstringfull path to the file/directory you wish to stat
  • Response: Promise

symlink

↑ back to method list

  • Syntax:
ns.symlink(NETSTORAGE_SOURCE, NETSTORAGE_TARGET, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_SOURCEstringfull path to the original file
    NETSTORAGE_TARGETstringfull path of the new symlinked file to create

symlinkAsync

↑ back to method list

  • Syntax:
ns.symlinkAsync(NETSTORAGE_SOURCE, NETSTORAGE_TARGET)
  • Parameters:

    NameTypeDescription
    NETSTORAGE_SOURCEstringfull path to the original file
    NETSTORAGE_TARGETstringfull path of the new symlinked file to create
  • Response: Promise

upload

↑ back to method list

  • Syntax:
ns.upload(LOCAL_SOURCE, NETSTORAGE_DESTINATION, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    LOCAL_SOURCEstringPath to the local file you wish to upload
    NETSTORAGE_DESTINATIONstringPath to the location you wish to upload the file. Note that if you omit the actual filename, the source filename is used. You may only upload files using the API, not directories.

uploadAsync

↑ back to method list

  • Syntax:
ns.uploadAsync(LOCAL_SOURCE, NETSTORAGE_DESTINATION)
  • Parameters:

    NameTypeDescription
    LOCAL_SOURCEstringPath to the local file you wish to upload
    NETSTORAGE_DESTINATIONstringPath to the location you wish to upload the file. Note that if you omit the actual filename, the source filename is used. You may only upload files using the API, not directories.
  • Response: Promise

uploadBuffer

↑ back to method list

  • Syntax:
ns.uploadBuffer(LocalBuffer, Basename, NETSTORAGE_DESTINATION, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    LocalBufferBufferBuffer of the file you wish to upload
    BasenamestringFilename you wish to keep for the uploaded file along with the extension.
    NETSTORAGE_DESTINATIONstringPath to the location you wish to upload the file. You may only upload files using the API, not directories.

uploadBufferAsync

↑ back to method list

  • Syntax:
ns.uploadBufferAsync(LOCAL_SOURCE, NETSTORAGE_DESTINATION)
  • Parameters:

    NameTypeDescription
    LocalBufferBufferBuffer of the file you wish to upload
    BasenamestringFilename you wish to keep for the uploaded file along with the extension.
    NETSTORAGE_DESTINATIONstringPath to the location you wish to upload the file. You may only upload files using the API, not directories.
  • Response: Promise

Author

Boffin Coders (info@boffincoders.com)
Thanks to Astin Choi (achoi@akamai.com) as well for writing the origianl lib.