1.1.5 • Published 4 years ago

kenote-store-helper v1.1.5

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

store-helper

Upload Store's Helper.

NPM Version NPM Downloads Build Status Gratipay

Installation

$ npm install kenote-store-helper
# Or
$ yarn add kenote-store-helper

Usages

app.ts

import * as http from 'http'
import * as express from 'express'
import * as bodyParser from 'body-parser'
import { StroeOptions } from 'kenote-store-helper'

const store: StroeOptions = {
  type: 'local',
  max_size: '2MB',
  root_dir: 'uploadfiles',
  root_url: 'http://localhost',
  mime_type: ['image/png', 'image/jpeg']
}

const app: express.Application = express()
app.use(bodyParser.json({ limit: '1mb' }))
app.use(bodyParser.urlencoded({ extended: true, limit: '1mb' }))

app.post('/upload', async (req, res, next) => {
  try {
    let result: ProxyResult = await new IStore({ request: req, options: store }).asyncSave(ErrorInfo)
    return res.json(result)
  } catch (error) {
    return res.json(error)
  }
})

http.createServer(app).listen(3000)

function ErrorInfo (code: number, opts?: any) {
  return {
    code,
    message: opts && opts.join(',')
  }
}

store

import { Store, Connect, localProxy } from 'kenote-store-helper'

@Connect({
  proxys: {
    local: new localProxy()
  },
  errors: {
    mimetype: 1001,
    limit: 1002
  }
})
export default class IStore extends Store {}

Custom Proxy

store_proxys/qn.ts

import { IProxy, ProxyOptions, ProxyResult } from 'kenote-store-helper'

export default class Proxy implements IProxy {

  public upload (file: NodeJS.ReadableStream, options: ProxyOptions, done: (err: any, doc: ProxyResult) => void): void {
    // ---
    
  }
}

License

this repo is released under the MIT License.

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago