@kne/fastify-aliyun 1.1.0 → 1.1.2

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.
package/index.js CHANGED
@@ -18,6 +18,9 @@ module.exports = fp(
18
18
  endpoint: 'http://nls-gateway-cn-shanghai.aliyuncs.com/stream/v1/tts'
19
19
  }
20
20
  },
21
+ oss: {
22
+ baseDir: 'default'
23
+ },
21
24
  prefix: `/api/v${packageJson.version.split('.')[0]}/aliyun`,
22
25
  createAuthenticate: () => {
23
26
  return [];
@@ -3,11 +3,11 @@ const { RPCClient } = require('@alicloud/pop-core');
3
3
  const fetch = require('node-fetch');
4
4
  const fileType = require('file-type');
5
5
  module.exports = fp(async (fastify, options) => {
6
- const { servers } = fastify.aliyun;
6
+ const { services } = fastify.aliyun;
7
7
  const getToken = async () => {
8
8
  if (options.cache.has('nls:token')) {
9
9
  const Token = options.cache.get('nls:token');
10
- return { token: Token.Id };
10
+ return { token: Token.Id, appKey: options.nls.appKey };
11
11
  }
12
12
  const client = new RPCClient({
13
13
  accessKeyId: options.nls.token.accessKeyId,
@@ -51,7 +51,7 @@ module.exports = fp(async (fastify, options) => {
51
51
  file: { toBuffer: () => buffer, filename: `${audioName || 'audio'}.${type.ext}`, mimetype: type.mime }
52
52
  });
53
53
  };
54
- servers.nls = {
54
+ services.nls = {
55
55
  getToken,
56
56
  tts
57
57
  };
@@ -2,12 +2,13 @@ const OSS = require('ali-oss');
2
2
  const fp = require('fastify-plugin');
3
3
 
4
4
  module.exports = fp(async (fastify, options) => {
5
- const { servers } = fastify.aliyun;
5
+ const { services } = fastify.aliyun;
6
6
  const client = new OSS({
7
7
  region: options.oss.region,
8
8
  accessKeyId: options.oss.accessKeyId,
9
9
  accessKeySecret: options.oss.accessKeySecret,
10
- bucket: options.oss.bucket
10
+ bucket: options.oss.bucket,
11
+ secure: true
11
12
  });
12
13
 
13
14
  const uploadFile = async ({ file, filename }) => {
@@ -27,10 +28,11 @@ module.exports = fp(async (fastify, options) => {
27
28
  return client.signatureUrl(`${options.oss.baseDir}/${filename}`, { expires: expires || 3600 });
28
29
  };
29
30
 
30
- servers.oss = {
31
+ services.oss = {
31
32
  client,
32
33
  uploadFile,
33
34
  uploadFileStream,
34
- getFileLink
35
+ getFileLink,
36
+ downloadFile
35
37
  };
36
38
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kne/fastify-aliyun",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "对接阿里云服务",
5
5
  "main": "index.js",
6
6
  "scripts": {