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

node-post-server

v0.1.4

Published

支持服务端部署

Downloads

13

Readme

Node-post-server

本模块需要配合 node-post 使用

npm i node-post-server --save

Exporess router

var path = require('path');
var express = require('express');
var router = express.Router();
var multipart = require('connect-multiparty');
var multipartMiddleware = multipart();
var Poster = require('node-post-server');
var poster = new Poster;

// 允许写入的路径
poster.config.merge({
    safePaths: [
        '/Users/gavinning/Desktop/test',
        '/Users/gavinning/Desktop/test1'
    ]
})

// Upload api
router.post('/upload', multipartMiddleware, (req, res) => {
    var user, source, target;

    user = auth(req);

    if(!checkuser(user)){
        return res.status(403).send('Permission denied')
    }

    // 上传文件的临时路径
    source = req.files[req.body.field].path;
    // 最终目标路径
    target = path.normalize(req.body.filepath);

    // 自动校检安全路径
    poster.dest(source, target, (err) => {
        err ?
            res.status(403).send(err.message):
            res.status(200).send(target)
    })
})

req.files

req.files = {
    files: {
        fieldName: 'files',
        originalFilename: '1.png',
        path: '/var/folders/wv/f11wc52113lfnqrnp0pEv8_m0000gn/T/lFs43x3i0saqM2FEriU5VS7v.png',
        headers: { 'content-disposition': 'form-data; name="files"; filename="1.png"',
        'content-type': 'image/png' },
        size: 67092,
        name: '1.png',
        type: 'image/png'
    }
}

API

post.safePath(src)
@des 判断目标是否为安全路径 @param type: String src 文件URL
@return type: Boolean 是否为安全路径

post.link(source, target, fn)
@des 建立硬链接,建立成功后根据post.config.get('deleteTmp')判断是否删除source
@param type: String source 源地址
@param type: String target 目标地址
@param type: Function fn 成功后回调,可选,有此参数为异步操作,无此参数为同步操作,推荐异步

post.copy 复制,其他同上

post.dest post输出文件的方法,默认为复制操作,其他同上

Options

配置项依赖 vpm-config 进行管理,点击了解api详情

post.config.init(options)

safePaths Array 配置安全路径
deleteTmp Boolean 是否删除临时文件,默认为 true