{"id":22433546,"url":"https://github.com/gavinning/node-post-server","last_synced_at":"2025-03-27T07:45:36.953Z","repository":{"id":57327738,"uuid":"63232724","full_name":"gavinning/node-post-server","owner":"gavinning","description":"支持node-post实现Server端接收接口","archived":false,"fork":false,"pushed_at":"2016-07-15T06:29:10.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-22T02:04:17.704Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gavinning.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-13T09:22:13.000Z","updated_at":"2016-07-13T09:22:55.000Z","dependencies_parsed_at":"2022-09-17T11:10:42.497Z","dependency_job_id":null,"html_url":"https://github.com/gavinning/node-post-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fnode-post-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fnode-post-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fnode-post-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fnode-post-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gavinning","download_url":"https://codeload.github.com/gavinning/node-post-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245806389,"owners_count":20675296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-05T22:15:16.717Z","updated_at":"2025-03-27T07:45:36.930Z","avatar_url":"https://github.com/gavinning.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node-post-server\n本模块需要配合 [node-post](https://www.npmjs.com/package/node-post) 使用  \n\n```sh\nnpm i node-post-server --save\n```\n\n### Exporess router\n```js\nvar path = require('path');\nvar express = require('express');\nvar router = express.Router();\nvar multipart = require('connect-multiparty');\nvar multipartMiddleware = multipart();\nvar Poster = require('node-post-server');\nvar poster = new Poster;\n\n// 允许写入的路径\nposter.config.merge({\n    safePaths: [\n        '/Users/gavinning/Desktop/test',\n        '/Users/gavinning/Desktop/test1'\n    ]\n})\n\n// Upload api\nrouter.post('/upload', multipartMiddleware, (req, res) =\u003e {\n    var user, source, target;\n\n    user = auth(req);\n\n    if(!checkuser(user)){\n        return res.status(403).send('Permission denied')\n    }\n\n    // 上传文件的临时路径\n    source = req.files[req.body.field].path;\n    // 最终目标路径\n    target = path.normalize(req.body.filepath);\n\n    // 自动校检安全路径\n    poster.dest(source, target, (err) =\u003e {\n        err ?\n            res.status(403).send(err.message):\n            res.status(200).send(target)\n    })\n})\n```\n\nreq.files\n```js\nreq.files = {\n    files: {\n        fieldName: 'files',\n        originalFilename: '1.png',\n        path: '/var/folders/wv/f11wc52113lfnqrnp0pEv8_m0000gn/T/lFs43x3i0saqM2FEriU5VS7v.png',\n        headers: { 'content-disposition': 'form-data; name=\"files\"; filename=\"1.png\"',\n        'content-type': 'image/png' },\n        size: 67092,\n        name: '1.png',\n        type: 'image/png'\n    }\n}\n```\n\n### API\n``post.safePath(src)``  \n``@des`` 判断目标是否为安全路径\n``@param`` ``type: String`` ``src`` 文件URL  \n``@return`` ``type: Boolean`` 是否为安全路径\n\n``post.link(source, target, fn)``  \n``@des`` 建立硬链接，建立成功后根据post.config.get('deleteTmp')判断是否删除source  \n``@param`` ``type: String`` ``source`` 源地址  \n``@param`` ``type: String`` ``target`` 目标地址  \n``@param`` ``type: Function`` ``fn`` 成功后回调，可选，有此参数为异步操作，无此参数为同步操作，推荐异步  \n\n``post.copy`` 复制，其他同上\n\n``post.dest`` post输出文件的方法，默认为复制操作，其他同上\n\n### Options\n配置项依赖 [vpm-config](https://www.npmjs.com/package/vpm-config) 进行管理，点击了解api详情\n```js\npost.config.init(options)\n```\n\n``safePaths`` ``Array`` 配置安全路径  \n``deleteTmp`` ``Boolean`` 是否删除临时文件，默认为 ``true``\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavinning%2Fnode-post-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgavinning%2Fnode-post-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavinning%2Fnode-post-server/lists"}