@yvhitxcel/opencode-remote 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/README.md +82 -0
  2. package/bin/opencode-remote.js +70 -0
  3. package/bin/opencode-weixin.js +10 -0
  4. package/dist/AGENTS.md +20 -0
  5. package/dist/MEMORY.md +21 -0
  6. package/dist/bot-runner.js +180 -0
  7. package/dist/cli.js +256 -0
  8. package/dist/core/approval.js +95 -0
  9. package/dist/core/auth.js +119 -0
  10. package/dist/core/config.js +61 -0
  11. package/dist/core/notifications.js +134 -0
  12. package/dist/core/qiniu.js +267 -0
  13. package/dist/core/registry.js +86 -0
  14. package/dist/core/router.js +344 -0
  15. package/dist/core/session.js +403 -0
  16. package/dist/core/setup.js +418 -0
  17. package/dist/core/types.js +16 -0
  18. package/dist/feishu/adapter.js +72 -0
  19. package/dist/feishu/bot.js +168 -0
  20. package/dist/feishu/commands.js +601 -0
  21. package/dist/feishu/handler.js +380 -0
  22. package/dist/index.js +60 -0
  23. package/dist/opencode/client.js +823 -0
  24. package/dist/package-lock.json +762 -0
  25. package/dist/patch_spawn.js +28 -0
  26. package/dist/plugins/agents/acp/acp-adapter.js +42 -0
  27. package/dist/plugins/agents/claude-code/index.js +69 -0
  28. package/dist/plugins/agents/codex/index.js +44 -0
  29. package/dist/plugins/agents/copilot/index.js +44 -0
  30. package/dist/plugins/agents/opencode/index.js +66 -0
  31. package/dist/telegram/bot.js +288 -0
  32. package/dist/utils/message-split.js +38 -0
  33. package/dist/web/code-viewer.js +266 -0
  34. package/dist/weixin/adapter.js +135 -0
  35. package/dist/weixin/api.js +179 -0
  36. package/dist/weixin/bot.js +183 -0
  37. package/dist/weixin/commands.js +758 -0
  38. package/dist/weixin/handler.js +577 -0
  39. package/dist/weixin/node_modules/encodeurl/LICENSE +22 -0
  40. package/dist/weixin/node_modules/encodeurl/README.md +109 -0
  41. package/dist/weixin/node_modules/encodeurl/index.js +60 -0
  42. package/dist/weixin/node_modules/encodeurl/package.json +40 -0
  43. package/dist/weixin/node_modules/qiniu/.claude/settings.local.json +7 -0
  44. package/dist/weixin/node_modules/qiniu/.github/workflows/ci-test.yml +36 -0
  45. package/dist/weixin/node_modules/qiniu/.github/workflows/npm-publish.yml +20 -0
  46. package/dist/weixin/node_modules/qiniu/.github/workflows/version-check.yml +19 -0
  47. package/dist/weixin/node_modules/qiniu/.idea/MarsCodeWorkspaceAppSettings.xml +7 -0
  48. package/dist/weixin/node_modules/qiniu/.idea/codeStyles/Project.xml +44 -0
  49. package/dist/weixin/node_modules/qiniu/.idea/codeStyles/codeStyleConfig.xml +5 -0
  50. package/dist/weixin/node_modules/qiniu/.idea/git_toolbox_blame.xml +6 -0
  51. package/dist/weixin/node_modules/qiniu/.idea/inspectionProfiles/Project_Default.xml +6 -0
  52. package/dist/weixin/node_modules/qiniu/.idea/jsLibraryMappings.xml +6 -0
  53. package/dist/weixin/node_modules/qiniu/.idea/modules.xml +8 -0
  54. package/dist/weixin/node_modules/qiniu/.idea/nodejs-sdk.iml +12 -0
  55. package/dist/weixin/node_modules/qiniu/.idea/vcs.xml +6 -0
  56. package/dist/weixin/node_modules/qiniu/CHANGELOG.md +292 -0
  57. package/dist/weixin/node_modules/qiniu/README.md +56 -0
  58. package/dist/weixin/node_modules/qiniu/StorageResponseInterface.d.ts +239 -0
  59. package/dist/weixin/node_modules/qiniu/codecov.yml +28 -0
  60. package/dist/weixin/node_modules/qiniu/index.d.ts +1995 -0
  61. package/dist/weixin/node_modules/qiniu/index.js +32 -0
  62. package/dist/weixin/node_modules/qiniu/node_modules/encodeurl/HISTORY.md +14 -0
  63. package/dist/weixin/node_modules/qiniu/node_modules/encodeurl/LICENSE +22 -0
  64. package/dist/weixin/node_modules/qiniu/node_modules/encodeurl/README.md +128 -0
  65. package/dist/weixin/node_modules/qiniu/node_modules/encodeurl/index.js +60 -0
  66. package/dist/weixin/node_modules/qiniu/node_modules/encodeurl/package.json +40 -0
  67. package/dist/weixin/node_modules/qiniu/package.json +80 -0
  68. package/dist/weixin/node_modules/qiniu/qiniu/auth/digest.js +13 -0
  69. package/dist/weixin/node_modules/qiniu/qiniu/cdn.js +149 -0
  70. package/dist/weixin/node_modules/qiniu/qiniu/conf.js +254 -0
  71. package/dist/weixin/node_modules/qiniu/qiniu/fop.js +112 -0
  72. package/dist/weixin/node_modules/qiniu/qiniu/httpc/client.js +253 -0
  73. package/dist/weixin/node_modules/qiniu/qiniu/httpc/endpoint.js +66 -0
  74. package/dist/weixin/node_modules/qiniu/qiniu/httpc/endpointsProvider.js +27 -0
  75. package/dist/weixin/node_modules/qiniu/qiniu/httpc/endpointsRetryPolicy.js +76 -0
  76. package/dist/weixin/node_modules/qiniu/qiniu/httpc/middleware/base.js +31 -0
  77. package/dist/weixin/node_modules/qiniu/qiniu/httpc/middleware/index.js +9 -0
  78. package/dist/weixin/node_modules/qiniu/qiniu/httpc/middleware/qiniuAuth.js +53 -0
  79. package/dist/weixin/node_modules/qiniu/qiniu/httpc/middleware/retryDomains.js +101 -0
  80. package/dist/weixin/node_modules/qiniu/qiniu/httpc/middleware/ua.js +36 -0
  81. package/dist/weixin/node_modules/qiniu/qiniu/httpc/region.js +349 -0
  82. package/dist/weixin/node_modules/qiniu/qiniu/httpc/regionsProvider.js +788 -0
  83. package/dist/weixin/node_modules/qiniu/qiniu/httpc/regionsRetryPolicy.js +242 -0
  84. package/dist/weixin/node_modules/qiniu/qiniu/httpc/responseWrapper.js +40 -0
  85. package/dist/weixin/node_modules/qiniu/qiniu/retry/index.js +4 -0
  86. package/dist/weixin/node_modules/qiniu/qiniu/retry/retrier.js +99 -0
  87. package/dist/weixin/node_modules/qiniu/qiniu/retry/retryPolicy.js +55 -0
  88. package/dist/weixin/node_modules/qiniu/qiniu/rpc.js +237 -0
  89. package/dist/weixin/node_modules/qiniu/qiniu/rtc/app.js +123 -0
  90. package/dist/weixin/node_modules/qiniu/qiniu/rtc/credentials.js +57 -0
  91. package/dist/weixin/node_modules/qiniu/qiniu/rtc/room.js +118 -0
  92. package/dist/weixin/node_modules/qiniu/qiniu/rtc/util.js +16 -0
  93. package/dist/weixin/node_modules/qiniu/qiniu/sms/message.js +58 -0
  94. package/dist/weixin/node_modules/qiniu/qiniu/storage/form.js +442 -0
  95. package/dist/weixin/node_modules/qiniu/qiniu/storage/internal.js +214 -0
  96. package/dist/weixin/node_modules/qiniu/qiniu/storage/resume.js +1272 -0
  97. package/dist/weixin/node_modules/qiniu/qiniu/storage/rs.js +1764 -0
  98. package/dist/weixin/node_modules/qiniu/qiniu/util.js +382 -0
  99. package/dist/weixin/node_modules/qiniu/qiniu/zone.js +230 -0
  100. package/dist/weixin/node_modules/qiniu/tsconfig.json +112 -0
  101. package/dist/weixin/types.js +25 -0
  102. package/package.json +56 -0
@@ -0,0 +1,32 @@
1
+ module.exports = {
2
+ auth: {
3
+ digest: require('./qiniu/auth/digest.js')
4
+ },
5
+ cdn: require('./qiniu/cdn.js'),
6
+ form_up: require('./qiniu/storage/form.js'),
7
+ resume_up: require('./qiniu/storage/resume.js'),
8
+ rs: require('./qiniu/storage/rs.js'),
9
+ fop: require('./qiniu/fop.js'),
10
+ conf: require('./qiniu/conf.js'),
11
+ httpc: {
12
+ middleware: require('./qiniu/httpc/middleware'),
13
+ HttpClient: require('./qiniu/httpc/client').HttpClient,
14
+ ResponseWrapper: require('./qiniu/httpc/responseWrapper').ResponseWrapper,
15
+ Endpoint: require('./qiniu/httpc/endpoint').Endpoint,
16
+ StaticEndpointsProvider: require('./qiniu/httpc/endpointsProvider').StaticEndpointsProvider,
17
+ SERVICE_NAME: require('./qiniu/httpc/region').SERVICE_NAME,
18
+ Region: require('./qiniu/httpc/region').Region,
19
+ StaticRegionsProvider: require('./qiniu/httpc/regionsProvider').StaticRegionsProvider,
20
+ CachedRegionsProvider: require('./qiniu/httpc/regionsProvider').CachedRegionsProvider,
21
+ QueryRegionsProvider: require('./qiniu/httpc/regionsProvider').QueryRegionsProvider
22
+ },
23
+ rpc: require('./qiniu/rpc.js'),
24
+ util: require('./qiniu/util.js'),
25
+ zone: require('./qiniu/zone.js'),
26
+ app: require('./qiniu/rtc/app.js'),
27
+ room: require('./qiniu/rtc/room.js'),
28
+ Credentials: require('./qiniu/rtc/credentials.js'),
29
+ sms: {
30
+ message: require('./qiniu/sms/message.js')
31
+ }
32
+ };
@@ -0,0 +1,14 @@
1
+ 1.0.2 / 2018-01-21
2
+ ==================
3
+
4
+ * Fix encoding `%` as last character
5
+
6
+ 1.0.1 / 2016-06-09
7
+ ==================
8
+
9
+ * Fix encoding unpaired surrogates at start/end of string
10
+
11
+ 1.0.0 / 2016-06-08
12
+ ==================
13
+
14
+ * Initial release
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2016 Douglas Christopher Wilson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,128 @@
1
+ # encodeurl
2
+
3
+ [![NPM Version][npm-image]][npm-url]
4
+ [![NPM Downloads][downloads-image]][downloads-url]
5
+ [![Node.js Version][node-version-image]][node-version-url]
6
+ [![Build Status][travis-image]][travis-url]
7
+ [![Test Coverage][coveralls-image]][coveralls-url]
8
+
9
+ Encode a URL to a percent-encoded form, excluding already-encoded sequences
10
+
11
+ ## Installation
12
+
13
+ This is a [Node.js](https://nodejs.org/en/) module available through the
14
+ [npm registry](https://www.npmjs.com/). Installation is done using the
15
+ [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
16
+
17
+ ```sh
18
+ $ npm install encodeurl
19
+ ```
20
+
21
+ ## API
22
+
23
+ ```js
24
+ var encodeUrl = require('encodeurl')
25
+ ```
26
+
27
+ ### encodeUrl(url)
28
+
29
+ Encode a URL to a percent-encoded form, excluding already-encoded sequences.
30
+
31
+ This function will take an already-encoded URL and encode all the non-URL
32
+ code points (as UTF-8 byte sequences). This function will not encode the
33
+ "%" character unless it is not part of a valid sequence (`%20` will be
34
+ left as-is, but `%foo` will be encoded as `%25foo`).
35
+
36
+ This encode is meant to be "safe" and does not throw errors. It will try as
37
+ hard as it can to properly encode the given URL, including replacing any raw,
38
+ unpaired surrogate pairs with the Unicode replacement character prior to
39
+ encoding.
40
+
41
+ This function is _similar_ to the intrinsic function `encodeURI`, except it
42
+ will not encode the `%` character if that is part of a valid sequence, will
43
+ not encode `[` and `]` (for IPv6 hostnames) and will replace raw, unpaired
44
+ surrogate pairs with the Unicode replacement character (instead of throwing).
45
+
46
+ ## Examples
47
+
48
+ ### Encode a URL containing user-controled data
49
+
50
+ ```js
51
+ var encodeUrl = require('encodeurl')
52
+ var escapeHtml = require('escape-html')
53
+
54
+ http.createServer(function onRequest (req, res) {
55
+ // get encoded form of inbound url
56
+ var url = encodeUrl(req.url)
57
+
58
+ // create html message
59
+ var body = '<p>Location ' + escapeHtml(url) + ' not found</p>'
60
+
61
+ // send a 404
62
+ res.statusCode = 404
63
+ res.setHeader('Content-Type', 'text/html; charset=UTF-8')
64
+ res.setHeader('Content-Length', String(Buffer.byteLength(body, 'utf-8')))
65
+ res.end(body, 'utf-8')
66
+ })
67
+ ```
68
+
69
+ ### Encode a URL for use in a header field
70
+
71
+ ```js
72
+ var encodeUrl = require('encodeurl')
73
+ var escapeHtml = require('escape-html')
74
+ var url = require('url')
75
+
76
+ http.createServer(function onRequest (req, res) {
77
+ // parse inbound url
78
+ var href = url.parse(req)
79
+
80
+ // set new host for redirect
81
+ href.host = 'localhost'
82
+ href.protocol = 'https:'
83
+ href.slashes = true
84
+
85
+ // create location header
86
+ var location = encodeUrl(url.format(href))
87
+
88
+ // create html message
89
+ var body = '<p>Redirecting to new site: ' + escapeHtml(location) + '</p>'
90
+
91
+ // send a 301
92
+ res.statusCode = 301
93
+ res.setHeader('Content-Type', 'text/html; charset=UTF-8')
94
+ res.setHeader('Content-Length', String(Buffer.byteLength(body, 'utf-8')))
95
+ res.setHeader('Location', location)
96
+ res.end(body, 'utf-8')
97
+ })
98
+ ```
99
+
100
+ ## Testing
101
+
102
+ ```sh
103
+ $ npm test
104
+ $ npm run lint
105
+ ```
106
+
107
+ ## References
108
+
109
+ - [RFC 3986: Uniform Resource Identifier (URI): Generic Syntax][rfc-3986]
110
+ - [WHATWG URL Living Standard][whatwg-url]
111
+
112
+ [rfc-3986]: https://tools.ietf.org/html/rfc3986
113
+ [whatwg-url]: https://url.spec.whatwg.org/
114
+
115
+ ## License
116
+
117
+ [MIT](LICENSE)
118
+
119
+ [npm-image]: https://img.shields.io/npm/v/encodeurl.svg
120
+ [npm-url]: https://npmjs.org/package/encodeurl
121
+ [node-version-image]: https://img.shields.io/node/v/encodeurl.svg
122
+ [node-version-url]: https://nodejs.org/en/download
123
+ [travis-image]: https://img.shields.io/travis/pillarjs/encodeurl.svg
124
+ [travis-url]: https://travis-ci.org/pillarjs/encodeurl
125
+ [coveralls-image]: https://img.shields.io/coveralls/pillarjs/encodeurl.svg
126
+ [coveralls-url]: https://coveralls.io/r/pillarjs/encodeurl?branch=master
127
+ [downloads-image]: https://img.shields.io/npm/dm/encodeurl.svg
128
+ [downloads-url]: https://npmjs.org/package/encodeurl
@@ -0,0 +1,60 @@
1
+ /*!
2
+ * encodeurl
3
+ * Copyright(c) 2016 Douglas Christopher Wilson
4
+ * MIT Licensed
5
+ */
6
+
7
+ 'use strict'
8
+
9
+ /**
10
+ * Module exports.
11
+ * @public
12
+ */
13
+
14
+ module.exports = encodeUrl
15
+
16
+ /**
17
+ * RegExp to match non-URL code points, *after* encoding (i.e. not including "%")
18
+ * and including invalid escape sequences.
19
+ * @private
20
+ */
21
+
22
+ var ENCODE_CHARS_REGEXP = /(?:[^\x21\x25\x26-\x3B\x3D\x3F-\x5B\x5D\x5F\x61-\x7A\x7E]|%(?:[^0-9A-Fa-f]|[0-9A-Fa-f][^0-9A-Fa-f]|$))+/g
23
+
24
+ /**
25
+ * RegExp to match unmatched surrogate pair.
26
+ * @private
27
+ */
28
+
29
+ var UNMATCHED_SURROGATE_PAIR_REGEXP = /(^|[^\uD800-\uDBFF])[\uDC00-\uDFFF]|[\uD800-\uDBFF]([^\uDC00-\uDFFF]|$)/g
30
+
31
+ /**
32
+ * String to replace unmatched surrogate pair with.
33
+ * @private
34
+ */
35
+
36
+ var UNMATCHED_SURROGATE_PAIR_REPLACE = '$1\uFFFD$2'
37
+
38
+ /**
39
+ * Encode a URL to a percent-encoded form, excluding already-encoded sequences.
40
+ *
41
+ * This function will take an already-encoded URL and encode all the non-URL
42
+ * code points. This function will not encode the "%" character unless it is
43
+ * not part of a valid sequence (`%20` will be left as-is, but `%foo` will
44
+ * be encoded as `%25foo`).
45
+ *
46
+ * This encode is meant to be "safe" and does not throw errors. It will try as
47
+ * hard as it can to properly encode the given URL, including replacing any raw,
48
+ * unpaired surrogate pairs with the Unicode replacement character prior to
49
+ * encoding.
50
+ *
51
+ * @param {string} url
52
+ * @return {string}
53
+ * @public
54
+ */
55
+
56
+ function encodeUrl (url) {
57
+ return String(url)
58
+ .replace(UNMATCHED_SURROGATE_PAIR_REGEXP, UNMATCHED_SURROGATE_PAIR_REPLACE)
59
+ .replace(ENCODE_CHARS_REGEXP, encodeURI)
60
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "encodeurl",
3
+ "description": "Encode a URL to a percent-encoded form, excluding already-encoded sequences",
4
+ "version": "1.0.2",
5
+ "contributors": [
6
+ "Douglas Christopher Wilson <doug@somethingdoug.com>"
7
+ ],
8
+ "license": "MIT",
9
+ "keywords": [
10
+ "encode",
11
+ "encodeurl",
12
+ "url"
13
+ ],
14
+ "repository": "pillarjs/encodeurl",
15
+ "devDependencies": {
16
+ "eslint": "3.19.0",
17
+ "eslint-config-standard": "10.2.1",
18
+ "eslint-plugin-import": "2.8.0",
19
+ "eslint-plugin-node": "5.2.1",
20
+ "eslint-plugin-promise": "3.6.0",
21
+ "eslint-plugin-standard": "3.0.1",
22
+ "istanbul": "0.4.5",
23
+ "mocha": "2.5.3"
24
+ },
25
+ "files": [
26
+ "LICENSE",
27
+ "HISTORY.md",
28
+ "README.md",
29
+ "index.js"
30
+ ],
31
+ "engines": {
32
+ "node": ">= 0.8"
33
+ },
34
+ "scripts": {
35
+ "lint": "eslint .",
36
+ "test": "mocha --reporter spec --bail --check-leaks test/",
37
+ "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
38
+ "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
39
+ }
40
+ }
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "qiniu",
3
+ "version": "7.15.2",
4
+ "description": "Node wrapper for Qiniu Resource (Cloud) Storage API",
5
+ "main": "index.js",
6
+ "directories": {
7
+ "test": "test"
8
+ },
9
+ "scripts": {
10
+ "check-type": "tsc --noEmit",
11
+ "test": "NODE_ENV=test mocha -t 300000 --retries 3",
12
+ "cover": "nyc npm run test",
13
+ "report": "nyc report --reporter=html",
14
+ "lint": "eslint ."
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git://github.com/qiniu/nodejs-sdk.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/qiniu/nodejs-sdk/issues"
22
+ },
23
+ "keywords": [
24
+ "cloud",
25
+ "storage",
26
+ "s3",
27
+ "qiniu",
28
+ "web-service"
29
+ ],
30
+ "author": "sdk@qiniu.com",
31
+ "contributors": [
32
+ {
33
+ "name": "Xu Shiwei",
34
+ "email": "xushiweizh@gmail.com"
35
+ },
36
+ {
37
+ "name": "why404",
38
+ "email": "awhy.xu@gmail.com"
39
+ },
40
+ {
41
+ "name": "guhao",
42
+ "email": "guhao@qiniu.com"
43
+ },
44
+ {
45
+ "name": "jinxinxin",
46
+ "email": "jinxinxin@qiniu.com"
47
+ }
48
+ ],
49
+ "engines": {
50
+ "node": ">= 6"
51
+ },
52
+ "dependencies": {
53
+ "agentkeepalive": "^4.0.2",
54
+ "before": "^0.0.1",
55
+ "block-stream2": "^2.0.0",
56
+ "crc32": "^0.2.2",
57
+ "destroy": "^1.0.4",
58
+ "encodeurl": "^1.0.1",
59
+ "formstream": "^1.1.0",
60
+ "mime": "^2.4.4",
61
+ "mkdirp": "^0.5.5",
62
+ "mockdate": "^3.0.5",
63
+ "tunnel-agent": "^0.6.0",
64
+ "typescript": "^4.9.4",
65
+ "urllib": "^2.41.0"
66
+ },
67
+ "devDependencies": {
68
+ "@types/node": "^8.0.3",
69
+ "eslint": "^6.5.1",
70
+ "eslint-config-standard": "^14.1.0",
71
+ "eslint-plugin-import": "^2.11.0",
72
+ "eslint-plugin-node": "^10.0.0",
73
+ "eslint-plugin-promise": "^4.2.1",
74
+ "eslint-plugin-standard": "^4.0.1",
75
+ "mocha": "^6.2.1",
76
+ "nyc": "^14.1.1",
77
+ "should": "^13.2.3"
78
+ },
79
+ "license": "MIT"
80
+ }
@@ -0,0 +1,13 @@
1
+ const conf = require('../conf');
2
+
3
+ exports.Mac = Mac;
4
+
5
+ const defaultOptions = {
6
+ disableQiniuTimestampSignature: null
7
+ };
8
+
9
+ function Mac (accessKey, secretKey, options) {
10
+ this.accessKey = accessKey || conf.ACCESS_KEY;
11
+ this.secretKey = secretKey || conf.SECRET_KEY;
12
+ this.options = Object.assign({}, defaultOptions, options);
13
+ }
@@ -0,0 +1,149 @@
1
+ const url = require('url');
2
+ const crypto = require('crypto');
3
+ const urllib = require('urllib');
4
+ const util = require('./util');
5
+ const digest = require('./auth/digest.js');
6
+ const encodeUrl = require('encodeurl');
7
+
8
+ exports.CdnManager = CdnManager;
9
+
10
+ function CdnManager (mac) {
11
+ this.mac = mac || new digest.Mac();
12
+ }
13
+
14
+ // 获取域名日志下载链接
15
+ // @link http://developer.qiniu.com/article/fusion/api/log.html
16
+ //
17
+ // @param domains 域名列表 domains = ['obbid7qc6.qnssl.com','7xkh68.com1.z0.glb.clouddn.com']
18
+ // @param logDay 日期,例如 2016-07-01
19
+ // @param callbackFunc(err, respBody, respInfo)
20
+ CdnManager.prototype.getCdnLogList = function (domains, logDay, callbackFunc) {
21
+ var postBody = {
22
+ day: logDay,
23
+ domains: domains.join(';')
24
+ };
25
+ req(this.mac, '/v2/tune/log/list', postBody, callbackFunc);
26
+ };
27
+
28
+ // 获取域名访问流量数据
29
+ // @link http://developer.qiniu.com/article/fusion/api/traffic-bandwidth.html#batch-flux
30
+ //
31
+ // @param startDate 开始日期,例如:2016-07-01
32
+ // @param endDate 结束日期,例如:2016-07-03
33
+ // @param granularity 粒度,取值:5min/hour/day
34
+ // @param domains 域名列表 domain = ['obbid7qc6.qnssl.com','obbid7qc6.qnssl.com'];
35
+ // @param callbackFunc(err, respBody, respInfo)
36
+ CdnManager.prototype.getFluxData = function (startDate, endDate, granularity,
37
+ domains,
38
+ callbackFunc) {
39
+ var data = {
40
+ startDate: startDate,
41
+ endDate: endDate,
42
+ granularity: granularity,
43
+ domains: domains.join(';')
44
+ };
45
+ req(this.mac, '/v2/tune/flux', data, callbackFunc);
46
+ };
47
+
48
+ // 获取域名访问带宽数据
49
+ // @link http://developer.qiniu.com/article/fusion/api/traffic-bandwidth.html
50
+ // @param startDate 开始日期,例如:2016-07-01
51
+ // @param endDate 结束日期,例如:2016-07-03
52
+ // @param granularity 粒度,取值:5min/hour/day
53
+ // @param domains 域名列表 domain = ['obbid7qc6.qnssl.com','obbid7qc6.qnssl.com']
54
+ // @param callbackFunc(err, respBody, respInfo)
55
+ CdnManager.prototype.getBandwidthData = function (startDate, endDate,
56
+ granularity, domains,
57
+ callbackFunc) {
58
+ var data = {
59
+ startDate: startDate,
60
+ endDate: endDate,
61
+ granularity: granularity,
62
+ domains: domains.join(';')
63
+ };
64
+ req(this.mac, '/v2/tune/bandwidth', data, callbackFunc);
65
+ };
66
+
67
+ // 预取文件链接
68
+ // @link http://developer.qiniu.com/article/fusion/api/prefetch.html
69
+ //
70
+ // @param 预取urls urls = ['http://obbid7qc6.qnssl.com/023','http://obbid7qc6.qnssl.com/025']
71
+ // @param callbackFunc(err, respBody, respInfo)
72
+ CdnManager.prototype.prefetchUrls = function (urls, callbackFunc) {
73
+ var postBody = {
74
+ urls: urls
75
+ };
76
+ req(this.mac, '/v2/tune/prefetch', postBody, callbackFunc);
77
+ };
78
+
79
+ // 刷新链接
80
+ // @link http://developer.qiniu.com/article/fusion/api/refresh.html
81
+ // 刷新urls refreshUrls = ['http://obbid7qc6.qnssl.com/023','http://obbid7qc6.qnssl.com/025']
82
+ CdnManager.prototype.refreshUrls = function (urls, callbackFunc) {
83
+ this.refreshUrlsAndDirs(urls, null, callbackFunc);
84
+ };
85
+
86
+ // 刷新目录
87
+ // 刷新目录列表,每次最多不可以超过10个目录, 刷新目录需要额外开通权限,可以联系七牛技术支持处理
88
+ // @link http://developer.qiniu.com/article/fusion/api/refresh.html
89
+ // 刷新dirs refreshDirs = ['http://obbid7qc6.qnssl.com/wo/','http://obbid7qc6.qnssl.com/']
90
+ CdnManager.prototype.refreshDirs = function (dirs, callbackFunc) {
91
+ this.refreshUrlsAndDirs(null, dirs, callbackFunc);
92
+ };
93
+
94
+ CdnManager.prototype.refreshUrlsAndDirs = function (urls, dirs, callbackFunc) {
95
+ var postBody = {
96
+ urls: urls,
97
+ dirs: dirs
98
+ };
99
+ req(this.mac, '/v2/tune/refresh', postBody, callbackFunc);
100
+ };
101
+
102
+ // post 请求
103
+ function req (mac, reqPath, reqBody, callbackFunc) {
104
+ var url = 'http://fusion.qiniuapi.com' + reqPath;
105
+ var accessToken = util.generateAccessToken(mac, url, '');
106
+ var headers = {
107
+ 'Content-Type': 'application/json',
108
+ Authorization: accessToken
109
+ };
110
+ urllib.request(url, {
111
+ method: 'POST',
112
+ headers: headers,
113
+ data: reqBody,
114
+ dataType: 'json'
115
+ }, callbackFunc);
116
+ }
117
+
118
+ // 构建标准的基于时间戳的防盗链
119
+ // @param domain 自定义域名,例如 http://img.abc.com
120
+ // @param fileName 待访问的原始文件名,必须是utf8编码,不需要进行urlencode
121
+ // @param query 业务自身的查询参数,必须是utf8编码,不需要进行urlencode,
122
+ // 例如 {aa:"23", attname:"11111111111111"}
123
+ // @param encryptKey 时间戳防盗链的签名密钥,从七牛后台获取
124
+ // @param deadline 链接的有效期时间戳,是以秒为单位的Unix时间戳
125
+ // @return signedUrl 最终的带时间戳防盗链的url
126
+ CdnManager.prototype.createTimestampAntiLeechUrl = function (domain, fileName,
127
+ query, encryptKey, deadline) {
128
+ var urlToSign;
129
+ if (query != null) {
130
+ urlToSign = domain + '/' + encodeUrl(fileName) + '?' + query;
131
+ } else {
132
+ urlToSign = domain + '/' + encodeUrl(fileName);
133
+ }
134
+
135
+ var urlObj = new url.URL(urlToSign);
136
+ var pathname = urlObj.pathname;
137
+
138
+ var expireHex = deadline.toString(16);
139
+ var signedStr = encryptKey + pathname + expireHex;
140
+
141
+ var md5 = crypto.createHash('md5');
142
+ var toSignStr = md5.update(signedStr).digest('hex');
143
+
144
+ if (query != null) {
145
+ return urlToSign + '&sign=' + toSignStr + '&t=' + expireHex;
146
+ } else {
147
+ return urlToSign + '?sign=' + toSignStr + '&t=' + expireHex;
148
+ }
149
+ };