docs:更新文档

This commit is contained in:
张益铭
2021-03-01 15:06:11 +08:00
parent 1542135ab0
commit 9064b372e8
5835 changed files with 904126 additions and 161722 deletions

133
node_modules/koa-send/History.md generated vendored Normal file
View File

@@ -0,0 +1,133 @@
5.0.0 / 2018-06-19
==================
* bump deps
* fix bug that set Content-Type not working. (#105)
4.1.2 / 2017-12-14
==================
* Fix issue with dots in path when using extensions array (#92)
4.1.1 / 2017-09-25
==================
* Fix brotli support, closes #83
* Fix tests
4.1.0 / 2017-04-26
==================
* Add support for Cache-Control: immutable with a new "immutable" option
* Added serving of brotli versions of files
4.0.0 / 2017-04-09
==================
* throw error if file not exists, closes #43
* remove co, use async function
* bump deps
3.3.0 / 2017-01-10
==================
* add extensions option
* bump deps
3.2.0 / 2016-03-23
==================
* add setHeaders option
3.1.1 / 2016-03-04
==================
* bump deps
* simplify scripts
3.1.0 / 2015-10-24
==================
* return a promise instead of a generator
* fix: split path by path.sep instead of slash
* fix: strip root correctly on windows
* tests: resolve paths for windows
3.0.1 / 2015-10-23
==================
* fix stats info when path does not finish with slash and format is enabled, closes #34
3.0.0 / 2015-10-21
==================
* bump deps
* format option defaults to true
* fix: enable format only index exists
* simplify the declarations of `format`, `gzip`
2.0.1 / 2015-10-14
==================
* fix judgement of trailing slash
2.0.0 / 2015-10-14
==================
* serve directories without a trailing slash, closes #27
* when .hidden option is set, also check hidden directories, closes #17
* bump deps: mz@2, mocha@2, koa@1
* use resolve-path, closes #9
* gzip version of file should not be automatically sent
* fix test: gzip.json.gz is not valid json data
1.3.1 / 2014-09-08
==================
* add .maxAge alias
1.3.0 / 2014-09-07
==================
* add automatically check and serve `.gz` files
* remove `finished` dependency
* refactor with `mz`
1.2.3 / 2014-02-11
==================
* fix malicious path in windows
* update finished
* make assert message better
1.2.2 / 2014-01-07
==================
* fix: ignore directories instead of crashing koa
1.2.1 / 2014-01-02
==================
* add `content-length` header
1.2.0 / 2013-12-27
==================
* add `maxage` option
1.1.2 / 2013-12-22
==================
* replace deprecated ctx.error() with ctx.throw()
1.1.1 / 2013-12-20
==================
* use: on-socket-error
1.1.0 / 2013-12-19
==================
* add: `send` now returns the file path if sent
* add: destroy streams on socket errors to prevent fd leaks

22
node_modules/koa-send/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2020 Koa contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

109
node_modules/koa-send/README.md generated vendored Normal file
View File

@@ -0,0 +1,109 @@
# [**koa-send**](https://github.com/koajs/send)
> Static file serving middleware.
[![NPM version][npm-image]][npm-url]
[![Build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![Dependency Status][david-image]][david-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
## Installation
```js
$ npm install koa-send
```
## Options
- `maxage` Browser cache max-age in milliseconds. (defaults to `0`).
- `immutable` Tell the browser the resource is immutable and can be cached indefinitely. (defaults to `false`).
- `hidden` Allow transfer of hidden files. (defaults to `false`).
- [`root`](#root-path) Root directory to restrict file access.
- `index` Name of the index file to serve automatically when visiting the root location. (defaults to none).
- `gzip` Try to serve the gzipped version of a file automatically when `gzip` is supported by a client and if the requested file with `.gz` extension exists. (defaults to `true`).
- `brotli` Try to serve the brotli version of a file automatically when `brotli` is supported by a client and if the requested file with `.br` extension exists. (defaults to `true`).
- `format` If not `false` (defaults to `true`), format the path to serve static file servers and not require a trailing slash for directories, so that you can do both `/directory` and `/directory/`.
- [`setHeaders`](#setheaders) Function to set custom headers on response.
- `extensions` Try to match extensions from passed array to search for file when no extension is sufficed in URL. First found is served. (defaults to `false`)
### Root path
Note that `root` is required, defaults to `''` and will be resolved,
removing the leading `/` to make the path relative and this
path must not contain "..", protecting developers from
concatenating user input. If you plan on serving files based on
user input supply a `root` directory from which to serve from.
For example to serve files from `./public`:
```js
app.use(async (ctx) => {
await send(ctx, ctx.path, { root: __dirname + '/public' });
})
```
To serve developer specified files:
```js
app.use(async (ctx) => {
await send(ctx, 'path/to/my.js');
})
```
### setHeaders
The function is called as `fn(res, path, stats)`, where the arguments are:
* `res`: the response object.
* `path`: the resolved file path that is being sent.
* `stats`: the stats object of the file that is being sent.
You should only use the `setHeaders` option when you wish to edit the `Cache-Control` or `Last-Modified` headers, because doing it before is useless (it's overwritten by `send`), and doing it after is too late because the headers are already sent.
If you want to edit any other header, simply set them before calling `send`.
## Example
```js
const send = require('koa-send');
const Koa = require('koa');
const app = new Koa();
// $ GET /package.json
// $ GET /
app.use(async (ctx) => {
if ('/' == ctx.path) return ctx.body = 'Try GET /package.json';
await send(ctx, ctx.path);
})
app.listen(3000);
console.log('listening on port 3000');
```
## License
[MIT](/LICENSE)
[npm-image]: https://img.shields.io/npm/v/koa-send.svg?style=flat-square
[npm-url]: https://npmjs.org/package/koa-send
[github-tag]: http://img.shields.io/github/tag/koajs/send.svg?style=flat-square
[github-url]: https://github.com/koajs/send/tags
[travis-image]: https://img.shields.io/travis/koajs/send.svg?style=flat-square
[travis-url]: https://travis-ci.org/koajs/send
[coveralls-image]: https://img.shields.io/coveralls/koajs/send.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/koajs/send?branch=master
[david-image]: http://img.shields.io/david/koajs/send.svg?style=flat-square
[david-url]: https://david-dm.org/koajs/send
[license-image]: http://img.shields.io/npm/l/koa-send.svg?style=flat-square
[license-url]: LICENSE
[downloads-image]: http://img.shields.io/npm/dm/koa-send.svg?style=flat-square
[downloads-url]: https://npmjs.org/package/koa-send
[gittip-image]: https://img.shields.io/gittip/jonathanong.svg?style=flat-square
[gittip-url]: https://www.gittip.com/jonathanong/

188
node_modules/koa-send/index.js generated vendored Normal file
View File

@@ -0,0 +1,188 @@
/**
* Module dependencies.
*/
const fs = require('fs')
const util = require('util')
const debug = require('debug')('koa-send')
const resolvePath = require('resolve-path')
const createError = require('http-errors')
const assert = require('assert')
const stat = util.promisify(fs.stat)
const access = util.promisify(fs.access)
async function exists (path) {
try {
await access(path)
return true
} catch (e) {
return false
}
}
const {
normalize,
basename,
extname,
resolve,
parse,
sep
} = require('path')
/**
* Expose `send()`.
*/
module.exports = send
/**
* Send file at `path` with the
* given `options` to the koa `ctx`.
*
* @param {Context} ctx
* @param {String} path
* @param {Object} [opts]
* @return {Promise}
* @api public
*/
async function send (ctx, path, opts = {}) {
assert(ctx, 'koa context required')
assert(path, 'pathname required')
// options
debug('send "%s" %j', path, opts)
const root = opts.root ? normalize(resolve(opts.root)) : ''
const trailingSlash = path[path.length - 1] === '/'
path = path.substr(parse(path).root.length)
const index = opts.index
const maxage = opts.maxage || opts.maxAge || 0
const immutable = opts.immutable || false
const hidden = opts.hidden || false
const format = opts.format !== false
const extensions = Array.isArray(opts.extensions) ? opts.extensions : false
const brotli = opts.brotli !== false
const gzip = opts.gzip !== false
const setHeaders = opts.setHeaders
if (setHeaders && typeof setHeaders !== 'function') {
throw new TypeError('option setHeaders must be function')
}
// normalize path
path = decode(path)
if (path === -1) return ctx.throw(400, 'failed to decode')
// index file support
if (index && trailingSlash) path += index
path = resolvePath(root, path)
// hidden file support, ignore
if (!hidden && isHidden(root, path)) return
let encodingExt = ''
// serve brotli file when possible otherwise gzipped file when possible
if (ctx.acceptsEncodings('br', 'identity') === 'br' && brotli && (await exists(path + '.br'))) {
path = path + '.br'
ctx.set('Content-Encoding', 'br')
ctx.res.removeHeader('Content-Length')
encodingExt = '.br'
} else if (ctx.acceptsEncodings('gzip', 'identity') === 'gzip' && gzip && (await exists(path + '.gz'))) {
path = path + '.gz'
ctx.set('Content-Encoding', 'gzip')
ctx.res.removeHeader('Content-Length')
encodingExt = '.gz'
}
if (extensions && !/\./.exec(basename(path))) {
const list = [].concat(extensions)
for (let i = 0; i < list.length; i++) {
let ext = list[i]
if (typeof ext !== 'string') {
throw new TypeError('option extensions must be array of strings or false')
}
if (!/^\./.exec(ext)) ext = `.${ext}`
if (await exists(`${path}${ext}`)) {
path = `${path}${ext}`
break
}
}
}
// stat
let stats
try {
stats = await stat(path)
// Format the path to serve static file servers
// and not require a trailing slash for directories,
// so that you can do both `/directory` and `/directory/`
if (stats.isDirectory()) {
if (format && index) {
path += `/${index}`
stats = await stat(path)
} else {
return
}
}
} catch (err) {
const notfound = ['ENOENT', 'ENAMETOOLONG', 'ENOTDIR']
if (notfound.includes(err.code)) {
throw createError(404, err)
}
err.status = 500
throw err
}
if (setHeaders) setHeaders(ctx.res, path, stats)
// stream
ctx.set('Content-Length', stats.size)
if (!ctx.response.get('Last-Modified')) ctx.set('Last-Modified', stats.mtime.toUTCString())
if (!ctx.response.get('Cache-Control')) {
const directives = [`max-age=${(maxage / 1000 | 0)}`]
if (immutable) {
directives.push('immutable')
}
ctx.set('Cache-Control', directives.join(','))
}
if (!ctx.type) ctx.type = type(path, encodingExt)
ctx.body = fs.createReadStream(path)
return path
}
/**
* Check if it's hidden.
*/
function isHidden (root, path) {
path = path.substr(root.length).split(sep)
for (let i = 0; i < path.length; i++) {
if (path[i][0] === '.') return true
}
return false
}
/**
* File type.
*/
function type (file, ext) {
return ext !== '' ? extname(basename(file, ext)) : extname(file)
}
/**
* Decode `path`.
*/
function decode (path) {
try {
return decodeURIComponent(path)
} catch (err) {
return -1
}
}

88
node_modules/koa-send/package.json generated vendored Normal file
View File

@@ -0,0 +1,88 @@
{
"_args": [
[
"koa-send@5.0.1",
"J:\\Github\\CURD-TS"
]
],
"_development": true,
"_from": "koa-send@5.0.1",
"_id": "koa-send@5.0.1",
"_inBundle": false,
"_integrity": "sha1-Odzuv6+zldDWC+r/ujpwtPVD/nk=",
"_location": "/koa-send",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "koa-send@5.0.1",
"name": "koa-send",
"escapedName": "koa-send",
"rawSpec": "5.0.1",
"saveSpec": null,
"fetchSpec": "5.0.1"
},
"_requiredBy": [
"/koa-static",
"/vite"
],
"_resolved": "http://192.168.250.101:4873/koa-send/-/koa-send-5.0.1.tgz",
"_spec": "5.0.1",
"_where": "J:\\Github\\CURD-TS",
"bugs": {
"url": "https://github.com/koajs/send/issues"
},
"dependencies": {
"debug": "^4.1.1",
"http-errors": "^1.7.3",
"resolve-path": "^1.4.0"
},
"description": "Transfer static files",
"devDependencies": {
"eslint": "^4.19.1",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0",
"iltorb": "^2.3.2",
"koa": "^2.5.1",
"mocha": "^5.2.0",
"nyc": "^15.0.0",
"should": "^13.2.1",
"supertest": "^3.1.0"
},
"engines": {
"node": ">= 8"
},
"files": [
"index.js"
],
"homepage": "https://github.com/koajs/send",
"keywords": [
"koa",
"file",
"static",
"sendfile"
],
"license": "MIT",
"main": "index.js",
"name": "koa-send",
"nyc": {
"reporter": [
"lcov",
"text-summary"
],
"report-dir": "./coverage"
},
"repository": {
"type": "git",
"url": "git://github.com/koajs/send.git"
},
"scripts": {
"lint": "eslint --fix .",
"test": "npm run lint && mocha --require should --reporter spec --exit",
"test-cov": "nyc npm run test"
},
"version": "5.0.1"
}