@simitgroup/simpleapp-generator 2.0.2-v-alpha → 2.0.2-w-alpha
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/ReleaseNote.md +9 -0
- package/dist/buildinschemas/autoincreament.d.ts +3 -0
- package/dist/buildinschemas/autoincreament.d.ts.map +1 -0
- package/dist/buildinschemas/autoincreament.js +39 -0
- package/dist/buildinschemas/autoincreament.js.map +1 -0
- package/dist/buildinschemas/docnoformat.d.ts +3 -0
- package/dist/buildinschemas/docnoformat.d.ts.map +1 -0
- package/dist/buildinschemas/docnoformat.js +58 -0
- package/dist/buildinschemas/docnoformat.js.map +1 -0
- package/dist/buildinschemas/documentevent.d.ts +3 -0
- package/dist/buildinschemas/documentevent.d.ts.map +1 -0
- package/dist/buildinschemas/documentevent.js +48 -0
- package/dist/buildinschemas/documentevent.js.map +1 -0
- package/dist/buildinschemas/webhooklog.d.ts +3 -0
- package/dist/buildinschemas/webhooklog.d.ts.map +1 -0
- package/dist/buildinschemas/webhooklog.js +79 -0
- package/dist/buildinschemas/webhooklog.js.map +1 -0
- package/dist/framework.d.ts.map +1 -1
- package/dist/framework.js +8 -18
- package/dist/framework.js.map +1 -1
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +8 -18
- package/dist/generate.js.map +1 -1
- package/dist/index.js +7 -17
- package/dist/index.js.map +1 -1
- package/dist/libs.d.ts.map +1 -1
- package/dist/processors/bpmnbuilder.d.ts.map +1 -1
- package/dist/processors/bpmnbuilder.js +7 -17
- package/dist/processors/bpmnbuilder.js.map +1 -1
- package/dist/processors/jrxmlbuilder.d.ts.map +1 -1
- package/dist/processors/jrxmlbuilder.js +7 -17
- package/dist/processors/jrxmlbuilder.js.map +1 -1
- package/dist/processors/jsonschemabuilder.d.ts.map +1 -1
- package/dist/processors/jsonschemabuilder.js.map +1 -1
- package/package.json +1 -1
- package/templates/nest/src/simple-app/_core/features/mini-app/mini-app-manager/mini-app-manager.controller.ts.eta +2 -3
- package/templates/nest/src/simple-app/_core/features/profile/profile.controller.ts.eta +6 -6
- package/templates/nest/src/simple-app/_core/features/profile/profile.schema.ts.eta +36 -4
- package/templates/nest/src/simple-app/_core/features/user-context/user-context.type.ts.eta +43 -13
- package/templates/nest/src/simple-app/_core/features/user-context/user.context.ts.eta +57 -37
- package/templates/nest/src/simple-app/_core/framework/schemas/simple-app.schema.ts.eta +4 -3
- package/templates/nest/src/simple-app/_core/utils/dayjs.ts.eta +14 -9
- package/templates/nuxt/app.vue.eta +46 -47
- package/templates/nuxt/plugins/10.simpleapp-event.ts.eta +102 -92
- package/templates/nuxt/plugins/20.simpleapp-userstore.ts.eta +69 -51
- package/templates/nuxt/server/api/profile/[...].ts.eta +153 -161
|
@@ -4,173 +4,165 @@
|
|
|
4
4
|
* last change 2024-02-23
|
|
5
5
|
* Author: Ks Tan
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
import
|
|
7
|
+
|
|
8
|
+
import { getServerSession } from "#auth";
|
|
9
|
+
import axios from "axios";
|
|
9
10
|
import fs from "node:fs";
|
|
10
|
-
import {
|
|
11
|
-
import type { Session } from 'next-auth';
|
|
12
|
-
import { pathJoin } from '~/server/utils/path';
|
|
13
|
-
|
|
14
|
-
export default defineEventHandler(async (event:any) => {
|
|
15
|
-
type additionalprops = {accessToken?:string}
|
|
16
|
-
let session:any=null
|
|
17
|
-
// console.log("profile api-------------------------")
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
session = await getServerSession(event)
|
|
21
|
-
|
|
22
|
-
} catch (error) {
|
|
23
|
-
return sendRedirect(event, '/login', 401)
|
|
24
|
-
}
|
|
25
|
-
if(!session) {
|
|
26
|
-
return sendRedirect(event, "/login", 302);
|
|
27
|
-
}
|
|
28
|
-
return new Promise<any>(async (resolve, reject) => {
|
|
29
|
-
|
|
30
|
-
const seperateSymbol = '.';
|
|
31
|
-
const documentLink = event.context.params?._ ?? ''
|
|
32
|
-
const accessToken = session?.accessToken;
|
|
33
|
-
let forwardData: any = {};
|
|
34
|
-
|
|
35
|
-
const req = event.node.req;
|
|
36
|
-
|
|
37
|
-
if (!accessToken || typeof accessToken !== "string") {
|
|
38
|
-
return sendRedirect(event, "/login", 302);
|
|
39
|
-
}
|
|
11
|
+
import { pathJoin } from "~/server/utils/path";
|
|
40
12
|
|
|
41
|
-
|
|
13
|
+
export default defineEventHandler(async (event: any) => {
|
|
14
|
+
type additionalprops = { accessToken?: string };
|
|
15
|
+
let session: any = null;
|
|
16
|
+
// console.log("profile api-------------------------")
|
|
42
17
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
18
|
+
try {
|
|
19
|
+
session = await getServerSession(event);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
return sendRedirect(event, "/login", 302);
|
|
22
|
+
}
|
|
23
|
+
if (!session) {
|
|
24
|
+
return sendRedirect(event, "/login", 302);
|
|
25
|
+
}
|
|
26
|
+
return new Promise<any>(async (resolve, reject) => {
|
|
27
|
+
const seperateSymbol = ".";
|
|
28
|
+
const documentLink = event.context.params?._ ?? "";
|
|
29
|
+
const accessToken = session?.accessToken;
|
|
30
|
+
let forwardData: any = {};
|
|
47
31
|
|
|
48
|
-
|
|
49
|
-
// xOrg = xOrg + forwardData._branch;
|
|
50
|
-
// delete forwardData._branch;
|
|
51
|
-
// }
|
|
52
|
-
|
|
53
|
-
const frontEndRes = event.node.res;
|
|
54
|
-
|
|
55
|
-
const url = process.env.SIMPLEAPP_BACKEND_URL + `/profile/${documentLink}`;
|
|
56
|
-
// console.warn('backend server-----',req.method,url,forwardData)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const axiosConfig: any = {
|
|
60
|
-
method: req.method,
|
|
61
|
-
url: url,
|
|
62
|
-
headers: {
|
|
63
|
-
Authorization: `Bearer ${accessToken}`,
|
|
64
|
-
},
|
|
65
|
-
data: forwardData,
|
|
66
|
-
params: forwardData,
|
|
67
|
-
}
|
|
32
|
+
const req = event.node.req;
|
|
68
33
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
// console.log("axiosConfig",axiosConfig)
|
|
74
|
-
// if(key === 'system') {
|
|
75
|
-
// axiosConfig.headers["X-Global"] = true;
|
|
76
|
-
// delete axiosConfig.headers["X-Org"];
|
|
77
|
-
// }
|
|
78
|
-
|
|
79
|
-
// if(otherLink.includes('avatar')) {
|
|
80
|
-
// axiosConfig.responseType = 'arraybuffer';
|
|
81
|
-
// // axiosConfig.headers['Acceptable'] = 'text/html,image/avif,image/webp,image/apng';
|
|
82
|
-
// }
|
|
83
|
-
|
|
84
|
-
axios(axiosConfig).then((res) => {
|
|
85
|
-
// console.log("RRes",res)
|
|
86
|
-
if (res.headers['content-type'] === 'image/png') {
|
|
87
|
-
// Set the response headers for the image
|
|
88
|
-
frontEndRes.setHeader('Content-Type', 'image/png');
|
|
89
|
-
frontEndRes.setHeader('Content-Disposition', 'inline');
|
|
90
|
-
|
|
91
|
-
// Send the image data as the response body
|
|
92
|
-
frontEndRes.end(Buffer.from(res.data, 'binary'));
|
|
93
|
-
}else if(documentLink.includes('images/')){
|
|
94
|
-
// console.log(documentLink," Resdata of base64 photo",res.data.length)
|
|
95
|
-
let imageData
|
|
96
|
-
frontEndRes.setHeader('Content-Type', 'image/png');
|
|
97
|
-
|
|
98
|
-
// console.log("load image for",documentLink)
|
|
99
|
-
if( res.data.length){
|
|
100
|
-
// console.log("obtain base64 from server length:",res.data.length)
|
|
101
|
-
imageData = base64ToBuffer(res.data);
|
|
102
|
-
|
|
103
|
-
}else{
|
|
104
|
-
// console.log("server no image, use default image")
|
|
105
|
-
const folder = 'public/images/'
|
|
106
|
-
let filename = ''
|
|
107
|
-
if(documentLink.includes('student')) filename='student.png';
|
|
108
|
-
else if(documentLink.includes('teacher')) filename='teacher.png';
|
|
109
|
-
else if(documentLink.includes('organization')) filename='organization.png';
|
|
110
|
-
else filename='unknown.png';
|
|
111
|
-
const fullpath = folder+filename;
|
|
112
|
-
// console.log("photo path",fullpath)
|
|
113
|
-
if(fs.existsSync(fullpath)){
|
|
114
|
-
imageData = fs.readFileSync(fullpath)
|
|
115
|
-
}else{
|
|
116
|
-
console.log(fullpath,'does not exists')
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
frontEndRes.end(Buffer.from(imageData, 'binary'));
|
|
120
|
-
|
|
121
|
-
} else {
|
|
122
|
-
// For non-image responses, set the Content-Type header and send the response body
|
|
123
|
-
// setHeader(event, 'Content-type', <string>res.headers['Content-Type']);
|
|
34
|
+
if (!accessToken || typeof accessToken !== "string") {
|
|
35
|
+
return sendRedirect(event, "/login", 302);
|
|
36
|
+
}
|
|
124
37
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
38
|
+
if (req.method == "POST" || req.method == "PUT" || req.method == "PATCH") {
|
|
39
|
+
forwardData = await readBody(event);
|
|
40
|
+
} else {
|
|
41
|
+
forwardData = getQuery(event);
|
|
42
|
+
}
|
|
129
43
|
|
|
130
|
-
|
|
44
|
+
// if(typeof forwardData === "object" && "_branch" in forwardData) {
|
|
45
|
+
// xOrg = xOrg + forwardData._branch;
|
|
46
|
+
// delete forwardData._branch;
|
|
47
|
+
// }
|
|
48
|
+
|
|
49
|
+
const frontEndRes = event.node.res;
|
|
50
|
+
|
|
51
|
+
const url = process.env.SIMPLEAPP_BACKEND_URL + `/profile/${documentLink}`;
|
|
52
|
+
// console.warn('backend server-----',req.method,url,forwardData)
|
|
53
|
+
|
|
54
|
+
const axiosConfig: any = {
|
|
55
|
+
method: req.method,
|
|
56
|
+
url: url,
|
|
57
|
+
headers: {
|
|
58
|
+
Authorization: `Bearer ${accessToken}`,
|
|
59
|
+
},
|
|
60
|
+
data: forwardData,
|
|
61
|
+
params: forwardData,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
if (documentLink == "avatar") {
|
|
65
|
+
axiosConfig.url = pathJoin([
|
|
66
|
+
useRuntimeConfig().public.imageUrl,
|
|
67
|
+
documentLink,
|
|
68
|
+
]);
|
|
69
|
+
delete axiosConfig.params;
|
|
70
|
+
}
|
|
71
|
+
// console.log("axiosConfig",axiosConfig)
|
|
72
|
+
// if(key === 'system') {
|
|
73
|
+
// axiosConfig.headers["X-Global"] = true;
|
|
74
|
+
// delete axiosConfig.headers["X-Org"];
|
|
75
|
+
// }
|
|
76
|
+
|
|
77
|
+
// if(otherLink.includes('avatar')) {
|
|
78
|
+
// axiosConfig.responseType = 'arraybuffer';
|
|
79
|
+
// // axiosConfig.headers['Acceptable'] = 'text/html,image/avif,image/webp,image/apng';
|
|
80
|
+
// }
|
|
81
|
+
|
|
82
|
+
axios(axiosConfig)
|
|
83
|
+
.then((res) => {
|
|
84
|
+
// console.log("RRes",res)
|
|
85
|
+
if (res.headers["content-type"] === "image/png") {
|
|
86
|
+
// Set the response headers for the image
|
|
87
|
+
frontEndRes.setHeader("Content-Type", "image/png");
|
|
88
|
+
frontEndRes.setHeader("Content-Disposition", "inline");
|
|
89
|
+
|
|
90
|
+
// Send the image data as the response body
|
|
91
|
+
frontEndRes.end(Buffer.from(res.data, "binary"));
|
|
92
|
+
} else if (documentLink.includes("images/")) {
|
|
93
|
+
// console.log(documentLink," Resdata of base64 photo",res.data.length)
|
|
94
|
+
let imageData;
|
|
95
|
+
frontEndRes.setHeader("Content-Type", "image/png");
|
|
96
|
+
|
|
97
|
+
// console.log("load image for",documentLink)
|
|
98
|
+
if (res.data.length) {
|
|
99
|
+
// console.log("obtain base64 from server length:",res.data.length)
|
|
100
|
+
imageData = base64ToBuffer(res.data);
|
|
101
|
+
} else {
|
|
102
|
+
// console.log("server no image, use default image")
|
|
103
|
+
const folder = "public/images/";
|
|
104
|
+
let filename = "";
|
|
105
|
+
if (documentLink.includes("student")) filename = "student.png";
|
|
106
|
+
else if (documentLink.includes("teacher")) filename = "teacher.png";
|
|
107
|
+
else if (documentLink.includes("organization"))
|
|
108
|
+
filename = "organization.png";
|
|
109
|
+
else filename = "unknown.png";
|
|
110
|
+
const fullpath = folder + filename;
|
|
111
|
+
// console.log("photo path",fullpath)
|
|
112
|
+
if (fs.existsSync(fullpath)) {
|
|
113
|
+
imageData = fs.readFileSync(fullpath);
|
|
114
|
+
} else {
|
|
115
|
+
console.log(fullpath, "does not exists");
|
|
131
116
|
}
|
|
117
|
+
}
|
|
118
|
+
frontEndRes.end(Buffer.from(imageData, "binary"));
|
|
119
|
+
} else {
|
|
120
|
+
// For non-image responses, set the Content-Type header and send the response body
|
|
121
|
+
// setHeader(event, 'Content-type', <string>res.headers['Content-Type']);
|
|
132
122
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
123
|
+
frontEndRes.statusCode = res.status;
|
|
124
|
+
if (res.statusText) {
|
|
125
|
+
frontEndRes.statusMessage = res.statusText;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
resolve(res.data);
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
.catch((error) => {
|
|
132
|
+
if (!error?.response) {
|
|
133
|
+
console.log("backend server no response ", error.code);
|
|
134
|
+
reject({
|
|
135
|
+
statusMessage: "backendServerDownMessage",
|
|
136
|
+
statusCode: 503,
|
|
137
|
+
});
|
|
138
|
+
} else {
|
|
139
|
+
if (error.response?.status && error.response.status == 401) {
|
|
140
|
+
return sendRedirect(event, "/login", 302);
|
|
141
|
+
}
|
|
142
|
+
reject({
|
|
143
|
+
statusMessage: error.response.statusText,
|
|
144
|
+
statusCode: error.response.status,
|
|
145
|
+
data: error.response.data,
|
|
146
|
+
}); // resolve({ status: 'ok' })
|
|
147
|
+
// throw createError({ statusMessage: 'Bad Requests', statusCode: 404 })
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// resolve({
|
|
152
|
+
// status: 'ok'
|
|
153
|
+
// })
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
function base64ToBuffer(base64String: string) {
|
|
158
|
+
// Split the base64 string into parts
|
|
159
|
+
const parts = base64String.split(",");
|
|
160
|
+
const contentType = parts[0].split(":")[1];
|
|
161
|
+
const base64Data = parts[1];
|
|
162
|
+
|
|
163
|
+
// Decode the base64 data
|
|
164
|
+
const binaryString = atob(base64Data);
|
|
165
|
+
const buffer = new Buffer.from(binaryString, "binary");
|
|
166
|
+
|
|
167
|
+
return buffer;
|
|
168
|
+
}
|