yaml-admin-api 0.0.111 → 0.0.112

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yaml-admin-api",
3
- "version": "0.0.111",
3
+ "version": "0.0.112",
4
4
  "license": "MIT",
5
5
  "description": "YAML Admin API package",
6
6
  "type": "commonjs",
@@ -6,8 +6,8 @@ class Uploader {
6
6
  this._uploader = uploader;
7
7
  }
8
8
 
9
- async getSecureUrl(key, auth) {
10
- return await this._uploader.getUrlSecure(key, auth);
9
+ async getSecureUrl(key) {
10
+ return await this._uploader.getUrlSecure(key);
11
11
  }
12
12
 
13
13
  async upload(key, stream) {
@@ -22,7 +22,7 @@ class Uploader {
22
22
  return await this._uploader.getUrl(key);
23
23
  }
24
24
 
25
- static init(yml) {
25
+ static init(yml, auth) {
26
26
  const api_host = yml['api-host']?.uri;
27
27
  const raw = yml.upload.s3
28
28
  ? withConfigS3({
@@ -39,6 +39,7 @@ class Uploader {
39
39
  path_private: yml.upload.local.path_private,
40
40
  base_url: yml.upload.local.base_url,
41
41
  api_host,
42
+ auth,
42
43
  });
43
44
  Uploader._instance = new Uploader(raw);
44
45
  return Uploader._instance;
@@ -193,7 +193,7 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
193
193
  url= host_image + '/' + url
194
194
 
195
195
  if(private) {
196
- url = await uploader.getSecureUrl(key, auth);
196
+ url = await uploader.getSecureUrl(key);
197
197
  }
198
198
 
199
199
  return url
@@ -580,7 +580,7 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
580
580
  const currentTime = moment().format('YYYYMMDD_HHmmss');
581
581
  const key = `excel/${filename}${currentTime}.xlsx`;
582
582
  await uploader.uploadSecure(key, excelBuffer);
583
- let url = await uploader.getSecureUrl(key, auth);
583
+ let url = await uploader.getSecureUrl(key);
584
584
  return res.json({ r: true, url });
585
585
  }))
586
586
  }
@@ -1,7 +1,7 @@
1
1
  const moment = require('moment')
2
2
  const fs = require('fs')
3
3
 
4
- const withConfigLocal = ({path, path_private, base_url, api_host}) => {
4
+ const withConfigLocal = ({path, path_private, base_url, api_host, auth}) => {
5
5
 
6
6
  const upload = async (key, stream) => {
7
7
  return await fs.writeFileSync(path + '/' + key, stream)
@@ -11,7 +11,7 @@ const withConfigLocal = ({path, path_private, base_url, api_host}) => {
11
11
  return await fs.writeFileSync(path_private + '/' + key, stream)
12
12
  }
13
13
 
14
- const getUrlSecure = async (Key, auth) => {
14
+ const getUrlSecure = async (Key) => {
15
15
  let r = `${api_host}/local-secure-download?key=${Key}`
16
16
  let shortToken = await auth.genenrateShortToken()
17
17
  r += `&token=${shortToken}`
@@ -44,8 +44,6 @@ async function registerRoutes(app, options = {}) {
44
44
 
45
45
 
46
46
 
47
- const uploader = Uploader.init(yml);
48
-
49
47
  const {database, entity} = yml;
50
48
  let db = null;
51
49
  if(database) {
@@ -57,9 +55,14 @@ async function registerRoutes(app, options = {}) {
57
55
  }
58
56
  }
59
57
 
58
+ //local secure download api
59
+ const auth = withConfig({ db, jwt_secret: yml.login["jwt-secret"] });
60
+
61
+ const uploader = Uploader.init(yml, auth);
62
+
60
63
  await generateLoginApi(app, db, yml, api_prefix)
61
64
  await generateChartApi(app, db, yml, api_prefix)
62
-
65
+
63
66
  entity && Object.keys(entity).forEach(async (entity_name) => {
64
67
  await generateEntityApi({
65
68
  app, db,
@@ -75,9 +78,6 @@ async function registerRoutes(app, options = {}) {
75
78
  yml,
76
79
  options,
77
80
  })
78
-
79
- //local secure download api
80
- const auth = withConfig({ db, jwt_secret: yml.login["jwt-secret"] });
81
81
  app.get(api_prefix + '/local-secure-download', auth.isAuthenticated, async (req, res) => {
82
82
  const {key} = req.query;
83
83
  const a = `${yml.upload.local.path_private}/${key}`