{"id":17242773,"url":"https://github.com/imcuttle/express-restful-fileman","last_synced_at":"2025-04-14T03:25:37.559Z","repository":{"id":32511335,"uuid":"135807829","full_name":"imcuttle/express-restful-fileman","owner":"imcuttle","description":"A restful express router for manage(upload multi-files and remove files) file on web.","archived":false,"fork":false,"pushed_at":"2022-12-08T04:34:17.000Z","size":1219,"stargazers_count":2,"open_issues_count":22,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T23:07:38.825Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imcuttle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-02T10:17:10.000Z","updated_at":"2020-04-25T10:32:32.000Z","dependencies_parsed_at":"2023-01-14T21:27:14.644Z","dependency_job_id":null,"html_url":"https://github.com/imcuttle/express-restful-fileman","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Fexpress-restful-fileman","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Fexpress-restful-fileman/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Fexpress-restful-fileman/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Fexpress-restful-fileman/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imcuttle","download_url":"https://codeload.github.com/imcuttle/express-restful-fileman/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248814659,"owners_count":21165798,"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-10-15T06:14:02.043Z","updated_at":"2025-04-14T03:25:37.540Z","avatar_url":"https://github.com/imcuttle.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# express-restful-fileman\n\n[![build status](https://img.shields.io/travis/imcuttle/express-restful-fileman/master.svg?style=flat-square)](https://travis-ci.org/imcuttle/express-restful-fileman)\n[![Test coverage](https://img.shields.io/codecov/c/github/imcuttle/express-restful-fileman.svg?style=flat-square)](https://codecov.io/github/imcuttle/express-restful-fileman?branch=master)\n[![NPM version](https://img.shields.io/npm/v/express-restful-fileman.svg?style=flat-square)](https://www.npmjs.com/package/express-restful-fileman)\n[![NPM Downloads](https://img.shields.io/npm/dm/express-restful-fileman.svg?style=flat-square\u0026maxAge=43200)](https://www.npmjs.com/package/express-restful-fileman)\n\nA restful express router for manage(upload multi-files and remove files) file on web.\n\n## Usage\n\n    npm install express-restful-fileman --save\n\n```javascript\nconst fileman = require('express-restful-fileman')\nconst app = require('express')()\n\napp.use('/fileman', fileman(__dirname, { token: 'fake_token' }))\n```\n\n## Options\n\n### `fileman(dirpath: string, { token?: string, enableDelete?: boolean, browserViewRoute?: string, browserViewOptions?: object })`\n\n- `dirpath` (required): The file man's work directory.\n- `token` (optional): Check request's **authorization header** when token is be setting. (default: null)\n- `pass` (optional): The function for response success data. (default: `(res, data = 'ok') =\u003e {res.status(200).json({ code: 200, data })}`)\n- `fail` (optional): The function for response fail data. (default: `(res, error) =\u003e {...}`)\n- `generateFilename` (optional): The function for generating storing filename. (default: `({name, md5}) =\u003e name || md5`)\n- `enableDelete` (optional): Whether enable the delete's API. (default: false)\n- `browserViewRoute` (optional): The browserView route. (see [BrowserView Middleware](#browserview-middleware-v3))\n- `browserViewOptions` (optional): The browserView Middleware Options. (see [BrowserView Middleware](#browserview-middleware-v3))\n\n## Web API\n\n### Method: `POST`\n\nAdd the files which is belongs path using `multipart/form-data`.\n\n- Disable decompress (by default)  \n  The request path means path of directory, and each file's filename means relative path.\n\n  ```javascript\n  request\n    .post('/fileman/dir/path')\n    .attach('0', makeFixture('img.png'))\n    .attach('1', makeFixture('img.png'), { filepath: 'asasd/sds.png' })\n    .expect(200)\n    .end((err, res) =\u003e {\n      expect(res.body).toEqual({\n        code: 200,\n        data: ['/dir/path/img.png', '/dir/path/asasd/sds.png']\n      })\n\n      expect(isFile('dir/path/img.png')).toBeTruthy()\n      expect(isFile('dir/path/asasd/sds.png')).toBeTruthy()\n      done()\n    })\n  ```\n\n  Set path to be `dir/?force=true` to guarantee overwriting old file.\n\n* Enable decompress (by append querystring `?decompress=true`)  \n  The request path means path of directory too.\n\n  ```javascript\n  request\n    .post('/fileman/zip?decompress=true\u0026force=true')\n    .set('authorization', 'fake_token')\n    .attach('1', makeFixture('a.zip'))\n    .end((err, res) =\u003e {\n      expect(res.body).toEqual({\n        code: 200,\n        data: ['...paths']\n      })\n\n      expect(isFile('zip/你好.js')).toBeTruthy()\n      expect(isFile('zip/filemanRouter.js')).toBeTruthy()\n      expect(isFile('zip/FileMan.js')).toBeTruthy()\n      done()\n    })\n  ```\n\n### Method: `DELETE`\n\nRemove the files which is belongs path.\n\neg. `/dir/abc` can clear the `dirpath/dir/abc`.\n\n## BrowserView Middleware (\u003e=v3)\n\n**The Browser Upload UI.**\n\n![](https://i.loli.net/2018/08/25/5b80ea988f18e.png)\n\n### Usage\n\n#### Mix in `restful-fileman`\n\n```javascript\nconst fileman = require('express-restful-fileman')\nconst express = require('express')\nconst { join } = require('path')\n\nconst app = express()\napp.use(\n  '/fileman',\n  fileman(join(__dirname, 'www'), {\n    browserViewRoute: '', // `null` means disable ui feature.\n    browserViewOptions: {\n      /* options */\n    }\n  })\n)\n// GET: `/fileman` would servers browser UI.\n```\n\n#### Standalone\n\n```javascript\nconst browserView = require('express-restful-fileman/browser-view')\nconst express = require('express')\n\nconst app = express()\napp.use(\n  '/ui',\n  browserView({\n    // options\n  })\n)\n```\n\n### Options\n\n- `serverUrl`: The fileman's server url, eg. `http://example.com/fileman`. (default: `location.origin + location.pathname`)\n- `serverUrlVisible`: Whether the serverUrl input ui control is visible. (default: `false`)\n- `token`: Fileman server's token. (default: `null`)\n- `namespace`: The relative path you want to upload, eg. `root/abc`. (default: `''`)\n- `force`: see [Web API](#web-api) (default: `false`)\n- `decompress`: see [Web API](#web-api) (default: `false`)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimcuttle%2Fexpress-restful-fileman","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimcuttle%2Fexpress-restful-fileman","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimcuttle%2Fexpress-restful-fileman/lists"}