yaml-admin-api 0.0.52 → 0.0.54
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
|
@@ -8,7 +8,7 @@ const { makeMongoSortFromYml } = require('./crud-common.js');
|
|
|
8
8
|
* @param {*} db
|
|
9
9
|
* @param {*} yml
|
|
10
10
|
*/
|
|
11
|
-
const generateChartApi = async (app, db, yml) => {
|
|
11
|
+
const generateChartApi = async (app, db, yml, api_prefix) => {
|
|
12
12
|
const { front } = yml;
|
|
13
13
|
const dashboard = front?.dashboard;
|
|
14
14
|
if (!dashboard)
|
|
@@ -281,7 +281,7 @@ const generateChartApi = async (app, db, yml) => {
|
|
|
281
281
|
/**
|
|
282
282
|
* TODO : globalFilterDelegate not implemented
|
|
283
283
|
*/
|
|
284
|
-
app.get(
|
|
284
|
+
app.get(`${api_prefix}/api/chart/${id}`, auth.isAuthenticated, async (req, res) => {
|
|
285
285
|
try {
|
|
286
286
|
const { x } = chart;
|
|
287
287
|
let r
|
|
@@ -24,6 +24,7 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
|
|
|
24
24
|
const api_host = yml["api-host"].uri;
|
|
25
25
|
let isS3 = yml.upload.s3
|
|
26
26
|
let host_image = isS3 ? yml.upload.s3.base_url : yml.upload.local.base_url
|
|
27
|
+
let api_prefix = options?.api_prefix || ''
|
|
27
28
|
|
|
28
29
|
const uploader = yml.upload.s3 ? withConfigS3({
|
|
29
30
|
access_key_id: yml.upload.s3.access_key_id,
|
|
@@ -177,7 +178,7 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
|
|
|
177
178
|
}
|
|
178
179
|
|
|
179
180
|
//list
|
|
180
|
-
app.get(
|
|
181
|
+
app.get(`${api_prefix}/${entity_name}`, auth.isAuthenticated, asyncErrorHandler(async (req, res) => {
|
|
181
182
|
//검색 파라미터
|
|
182
183
|
var s = {};
|
|
183
184
|
var _sort = req.query._sort;
|
|
@@ -289,7 +290,7 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
|
|
|
289
290
|
};
|
|
290
291
|
|
|
291
292
|
//create
|
|
292
|
-
app.post(
|
|
293
|
+
app.post(`${api_prefix}/${entity_name}`, auth.isAuthenticated, asyncErrorHandler(async (req, res) => {
|
|
293
294
|
|
|
294
295
|
await recalcurateAutoGenerateIndex(db, entity_name)
|
|
295
296
|
|
|
@@ -329,7 +330,7 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
|
|
|
329
330
|
|
|
330
331
|
|
|
331
332
|
//edit
|
|
332
|
-
app.put(
|
|
333
|
+
app.put(`${api_prefix}/${entity_name}/:id`, auth.isAuthenticated, asyncErrorHandler(async (req, res) => {
|
|
333
334
|
let entityId = parseKey(req.params.id)
|
|
334
335
|
|
|
335
336
|
const entity = await constructEntity(req, entityId);
|
|
@@ -370,7 +371,7 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
|
|
|
370
371
|
}));
|
|
371
372
|
|
|
372
373
|
//view
|
|
373
|
-
app.get(
|
|
374
|
+
app.get(`${api_prefix}/${entity_name}/:id`, auth.isAuthenticated, asyncErrorHandler(async (req, res) => {
|
|
374
375
|
let f = {}
|
|
375
376
|
f[key_field.name] = parseKey(req.params.id)
|
|
376
377
|
const m = await db.collection(entity_name).findOne(f);
|
|
@@ -387,7 +388,7 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
|
|
|
387
388
|
}))
|
|
388
389
|
|
|
389
390
|
//delete
|
|
390
|
-
app.delete(
|
|
391
|
+
app.delete(`${api_prefix}/${entity_name}/:id`, auth.isAuthenticated, asyncErrorHandler(async (req, res) =>{
|
|
391
392
|
let f = {}
|
|
392
393
|
f[key_field.name] = parseKey(req.params.id)
|
|
393
394
|
const entity = await db.collection(entity_name).findOne(f);
|
|
@@ -417,7 +418,7 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
|
|
|
417
418
|
|
|
418
419
|
|
|
419
420
|
if (yml_entity.crud?.export) {
|
|
420
|
-
app.post(
|
|
421
|
+
app.post(`${api_prefix}/excel/${entity_name}/export`, auth.isAuthenticated, asyncErrorHandler(async (req, res) => {
|
|
421
422
|
const filename = `${entity_name}_`
|
|
422
423
|
const fields = yml_entity.crud.export.fields.map(field => ({
|
|
423
424
|
label: field.name,
|
|
@@ -457,7 +458,7 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
|
|
|
457
458
|
}
|
|
458
459
|
|
|
459
460
|
if (yml_entity.crud?.import) {
|
|
460
|
-
app.post(
|
|
461
|
+
app.post(`${api_prefix}/excel/${entity_name}/import`, auth.isAuthenticated, asyncErrorHandler(async (req, res) => {
|
|
461
462
|
const { base64 } = req.body
|
|
462
463
|
const buf = Buffer.from(base64, 'base64');
|
|
463
464
|
const workbook = XLSX.read(buf, { type: 'buffer' });
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const member = require('../member/member.js');
|
|
2
2
|
|
|
3
|
-
const generateLoginApi = async(app, db, yml) => {
|
|
3
|
+
const generateLoginApi = async(app, db, yml, prefix) => {
|
|
4
4
|
console.log('generateLoginApi', yml.login["jwt-secret"])
|
|
5
|
-
await member(app, db, yml)
|
|
5
|
+
await member(app, db, yml, prefix)
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
module.exports = {
|
package/src/member/member.js
CHANGED
|
@@ -1,32 +1,36 @@
|
|
|
1
1
|
const {withConfig} = require('../login/auth.js');
|
|
2
2
|
|
|
3
|
-
module.exports = async function (app, db, yml,
|
|
3
|
+
module.exports = async function (app, db, yml, api_prefix) {
|
|
4
4
|
const auth = withConfig({ db, jwt_secret: yml.login["jwt-secret"], passwordEncoding: yml.login["password-encoding"] });
|
|
5
5
|
|
|
6
|
-
app.get('/member/login',
|
|
6
|
+
app.get(api_prefix + '/member/login',
|
|
7
7
|
auth.authenticate,
|
|
8
8
|
function (req, res) {
|
|
9
9
|
res.json({ r: true, token: req.token, member: req.user });
|
|
10
10
|
}
|
|
11
11
|
);
|
|
12
12
|
|
|
13
|
-
app.get('/member/islogin',
|
|
13
|
+
app.get(api_prefix + '/member/islogin',
|
|
14
14
|
auth.isAuthenticated,
|
|
15
15
|
async function (req, res) {
|
|
16
16
|
res.json({ r: true, member: req.user });
|
|
17
17
|
}
|
|
18
18
|
);
|
|
19
19
|
|
|
20
|
-
app.post('/member/login',
|
|
20
|
+
app.post(api_prefix + '/member/login',
|
|
21
21
|
auth.authenticate,
|
|
22
22
|
function (req, res) {
|
|
23
23
|
res.json({ r: true, token: req.token, member: req.user });
|
|
24
24
|
}
|
|
25
25
|
);
|
|
26
26
|
|
|
27
|
-
app.get('/member/logout', async (req, res) => {
|
|
27
|
+
app.get(api_prefix + '/member/logout', async (req, res) => {
|
|
28
28
|
req.logout();
|
|
29
29
|
res.json({ r: true });
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
+
app.get(api_prefix + '/member/test', async (req, res) => {
|
|
33
|
+
res.json({ r: true });
|
|
34
|
+
});
|
|
35
|
+
|
|
32
36
|
};
|
|
@@ -19,8 +19,10 @@ const generateS3UploadApi = async ({ app, db, yml, options }) => {
|
|
|
19
19
|
})
|
|
20
20
|
return s3
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
|
|
23
|
+
const api_prefix = options?.api_prefix || ''
|
|
24
|
+
|
|
25
|
+
app.get(api_prefix+'/api/media/url/put/:ext', auth.isAuthenticated, async function(req, res){
|
|
24
26
|
let s3 = getS3()
|
|
25
27
|
let member_no = req.user.member_no || req.user.id;;
|
|
26
28
|
let fileName = await genEntityIdWithKey(db, 'file');
|
|
@@ -37,7 +39,7 @@ const generateS3UploadApi = async ({ app, db, yml, options }) => {
|
|
|
37
39
|
res.json(r);
|
|
38
40
|
});
|
|
39
41
|
|
|
40
|
-
app.get('/api/media/url/secure/put/:ext', auth.isAuthenticated, async function(req, res){
|
|
42
|
+
app.get(api_prefix+'/api/media/url/secure/put/:ext', auth.isAuthenticated, async function(req, res){
|
|
41
43
|
let s3 = getS3()
|
|
42
44
|
let member_no = req.user.member_no || req.user.id;;
|
|
43
45
|
let fileName = await genEntityIdWithKey(db, 'file');
|
|
@@ -55,7 +57,7 @@ const generateS3UploadApi = async ({ app, db, yml, options }) => {
|
|
|
55
57
|
});
|
|
56
58
|
|
|
57
59
|
// request uploadId
|
|
58
|
-
app.get('/api/media/url/secure/init/:ext', auth.isAuthenticated, async function (req, res) {
|
|
60
|
+
app.get(api_prefix+'/api/media/url/secure/init/:ext', auth.isAuthenticated, async function (req, res) {
|
|
59
61
|
let s3 = getS3();
|
|
60
62
|
let member_no = req.user.member_no || req.user.id;
|
|
61
63
|
let fileName = await genEntityIdWithKey(db, 'file');
|
|
@@ -74,7 +76,7 @@ const generateS3UploadApi = async ({ app, db, yml, options }) => {
|
|
|
74
76
|
});
|
|
75
77
|
|
|
76
78
|
// request presigned url
|
|
77
|
-
app.post('/api/media/url/secure/part', auth.isAuthenticated, async function (req, res) {
|
|
79
|
+
app.post(api_prefix+'/api/media/url/secure/part', auth.isAuthenticated, async function (req, res) {
|
|
78
80
|
let s3 = getS3();
|
|
79
81
|
let { key, uploadId, partNumber } = req.body;
|
|
80
82
|
|
|
@@ -91,7 +93,7 @@ const generateS3UploadApi = async ({ app, db, yml, options }) => {
|
|
|
91
93
|
});
|
|
92
94
|
|
|
93
95
|
// merge file
|
|
94
|
-
app.post('/api/media/url/secure/complete', auth.isAuthenticated, async function (req, res) {
|
|
96
|
+
app.post(api_prefix+'/api/media/url/secure/complete', auth.isAuthenticated, async function (req, res) {
|
|
95
97
|
let s3 = getS3();
|
|
96
98
|
let { key, uploadId, parts } = req.body;
|
|
97
99
|
|
|
@@ -108,7 +110,7 @@ const generateS3UploadApi = async ({ app, db, yml, options }) => {
|
|
|
108
110
|
});
|
|
109
111
|
|
|
110
112
|
// 청크파일 삭제
|
|
111
|
-
app.post('/api/media/url/secure/abort', auth.isAuthenticated, async (req, res) => {
|
|
113
|
+
app.post(api_prefix+'/api/media/url/secure/abort', auth.isAuthenticated, async (req, res) => {
|
|
112
114
|
try {
|
|
113
115
|
const { key, uploadId } = req.body;
|
|
114
116
|
const s3 = getS3();
|
|
@@ -126,7 +128,7 @@ const generateS3UploadApi = async ({ app, db, yml, options }) => {
|
|
|
126
128
|
}
|
|
127
129
|
});
|
|
128
130
|
|
|
129
|
-
app.post('/api/media/url/put', auth.isAuthenticated, async function(req, res) {
|
|
131
|
+
app.post(api_prefix+'/api/media/url/put', auth.isAuthenticated, async function(req, res) {
|
|
130
132
|
let s3 = getS3()
|
|
131
133
|
let member_no = req.user.member_no || req.user.id;
|
|
132
134
|
const {ext_list} = req.body
|
|
@@ -146,7 +148,7 @@ const generateS3UploadApi = async ({ app, db, yml, options }) => {
|
|
|
146
148
|
res.json(r);
|
|
147
149
|
})
|
|
148
150
|
|
|
149
|
-
app.post('/api/media/url/secure/put', auth.isAuthenticated, async function(req, res) {
|
|
151
|
+
app.post(api_prefix+'/api/media/url/secure/put', auth.isAuthenticated, async function(req, res) {
|
|
150
152
|
let s3 = getS3()
|
|
151
153
|
let member_no = req.user.member_no || req.user.id;
|
|
152
154
|
const {ext_list} = req.body
|
|
@@ -171,8 +173,9 @@ const generateLocalUploadApi = async ({ app, db, yml, options }) => {
|
|
|
171
173
|
const auth = withConfig({ db, jwt_secret: yml.login["jwt-secret"] });
|
|
172
174
|
const { path, path_private } = yml.upload.local;
|
|
173
175
|
|
|
176
|
+
const api_prefix = options?.api_prefix || ''
|
|
174
177
|
// Accept raw binary for local upload and stream to disk
|
|
175
|
-
app.put('/api/local/media/upload', auth.isAuthenticated, async function(req, res) {
|
|
178
|
+
app.put(api_prefix+'/api/local/media/upload', auth.isAuthenticated, async function(req, res) {
|
|
176
179
|
let member_no = req.user.member_no || req.user.id;
|
|
177
180
|
let {ext, name} = req.query
|
|
178
181
|
let fileName = await genEntityIdWithKey(db, 'file')
|
|
@@ -193,7 +196,7 @@ const generateLocalUploadApi = async ({ app, db, yml, options }) => {
|
|
|
193
196
|
});
|
|
194
197
|
})
|
|
195
198
|
|
|
196
|
-
app.put('/api/local/media/upload/secure', auth.isAuthenticated, async function(req, res) {
|
|
199
|
+
app.put(api_prefix+'/api/local/media/upload/secure', auth.isAuthenticated, async function(req, res) {
|
|
197
200
|
let member_no = req.user.member_no || req.user.id;
|
|
198
201
|
let {ext, name} = req.query
|
|
199
202
|
|
package/src/yml-admin-api.js
CHANGED
|
@@ -18,7 +18,10 @@ const changeEnv = (yamlString, env = {}) => {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
async function registerRoutes(app, options = {}) {
|
|
21
|
-
const { yamlPath, yamlString, env, yamlJson } = options;
|
|
21
|
+
const { yamlPath, yamlString, env, yamlJson, api_prefix } = options;
|
|
22
|
+
if(!api_prefix)
|
|
23
|
+
api_prefix = ''
|
|
24
|
+
|
|
22
25
|
let yml;
|
|
23
26
|
|
|
24
27
|
if(yamlJson) {
|
|
@@ -50,8 +53,8 @@ async function registerRoutes(app, options = {}) {
|
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
await generateLoginApi(app, db, yml)
|
|
54
|
-
await generateChartApi(app, db, yml)
|
|
56
|
+
await generateLoginApi(app, db, yml, api_prefix)
|
|
57
|
+
await generateChartApi(app, db, yml, api_prefix)
|
|
55
58
|
|
|
56
59
|
entity && Object.keys(entity).forEach(async (entity_name) => {
|
|
57
60
|
await generateEntityApi({
|
|
@@ -71,7 +74,7 @@ async function registerRoutes(app, options = {}) {
|
|
|
71
74
|
|
|
72
75
|
//local secure download api
|
|
73
76
|
const auth = withConfig({ db, jwt_secret: yml.login["jwt-secret"] });
|
|
74
|
-
app.get('/local-secure-download', auth.isAuthenticated, async (req, res) => {
|
|
77
|
+
app.get(api_prefix + '/local-secure-download', auth.isAuthenticated, async (req, res) => {
|
|
75
78
|
const {key} = req.query;
|
|
76
79
|
const a = `${yml.upload.local.path_private}/${key}`
|
|
77
80
|
const file = await fs.readFile(a)
|