kenote-store-helper
Upload Store's Helper.
Last updated 4 months ago by thondery .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install kenote-store-helper 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 1.1.2                                ...           latest (4 months ago)

8 Versions

  • 1.1.2                                ...           4 months ago
  • 1.1.1                                ...           4 months ago
  • 1.1.0                                ...           4 months ago
  • 1.0.4                                ...           7 months ago
  • 1.0.3                                ...           7 months ago
  • 1.0.2                                ...           10 months ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 5
Last Day 0
Last Week 4
Last Month 1
Dependencies (6)
Dev Dependencies (10)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |