5htp-core 0.5.1-5 → 0.5.1-7
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 +1 -1
- package/src/client/components/Table/index.tsx +2 -2
- package/src/common/errors/index.tsx +23 -0
- package/src/server/services/database/index.ts +4 -3
- package/src/server/services/disks/driver.ts +1 -1
- package/src/server/services/disks/drivers/local/index.ts +4 -2
- package/src/server/services/router/index.ts +10 -7
- package/src/server/services/router/request/index.ts +0 -3
- package/src/server/services/router/response/index.ts +8 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "5htp-core",
|
|
3
3
|
"description": "Convenient TypeScript framework designed for Performance and Productivity.",
|
|
4
|
-
"version": "0.5.1-
|
|
4
|
+
"version": "0.5.1-7",
|
|
5
5
|
"author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
|
|
6
6
|
"repository": "git://github.com/gaetanlegac/5htp-core.git",
|
|
7
7
|
"license": "MIT",
|
|
@@ -170,11 +170,11 @@ export default function Liste<TRow extends TDonneeInconnue>({
|
|
|
170
170
|
|
|
171
171
|
render = (
|
|
172
172
|
<div class="row sp-05">
|
|
173
|
-
{cell.map((item, i) => (
|
|
173
|
+
{cell.map((item, i) => typeof item === 'string' ? (
|
|
174
174
|
<span class={"badge bg light" + ((i % 7) + 1)}>
|
|
175
175
|
{item}
|
|
176
176
|
</span>
|
|
177
|
-
))}
|
|
177
|
+
) : item)}
|
|
178
178
|
</div>
|
|
179
179
|
)
|
|
180
180
|
|
|
@@ -154,6 +154,27 @@ export class AuthRequired extends CoreError {
|
|
|
154
154
|
public static msgDefaut = "Please Login to Continue.";
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
export class UpgradeRequired extends CoreError {
|
|
158
|
+
public http = 402;
|
|
159
|
+
public title = "Upgrade Required";
|
|
160
|
+
public static msgDefaut = "Please Upgrade to Continue.";
|
|
161
|
+
|
|
162
|
+
public constructor(
|
|
163
|
+
message: string,
|
|
164
|
+
public feature: string,
|
|
165
|
+
details?: TErrorDetails
|
|
166
|
+
) {
|
|
167
|
+
super(message, details);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public json(): TJsonError & { feature: string } {
|
|
171
|
+
return {
|
|
172
|
+
...super.json(),
|
|
173
|
+
feature: this.feature,
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
157
178
|
export class Forbidden extends CoreError {
|
|
158
179
|
public http = 403;
|
|
159
180
|
public title = "Access Denied";
|
|
@@ -235,6 +256,8 @@ export const fromJson = ({ code, message, ...details }: TJsonError) => {
|
|
|
235
256
|
|
|
236
257
|
case 401: return new AuthRequired( message, details );
|
|
237
258
|
|
|
259
|
+
case 402: return new UpgradeRequired( message, details.feature, details );
|
|
260
|
+
|
|
238
261
|
case 403: return new Forbidden( message, details );
|
|
239
262
|
|
|
240
263
|
case 404: return new NotFound( message, details );
|
|
@@ -255,8 +255,9 @@ export default class SQL extends Service<Config, Hooks, Application, Services> {
|
|
|
255
255
|
}).join(' ').trim();
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
public equalities = (data: TObjetDonnees,
|
|
259
|
-
keys.map(k => '' + k + ' = ' + this.esc( data[k] ))
|
|
258
|
+
public equalities = (data: TObjetDonnees, forStorage: boolean = false) => {
|
|
259
|
+
return Object.keys(data).map(k => '' + k + ' = ' + this.esc( data[k], forStorage ))
|
|
260
|
+
}
|
|
260
261
|
|
|
261
262
|
/*----------------------------------
|
|
262
263
|
- OPERATIONS: LOW LEVELf
|
|
@@ -380,7 +381,7 @@ export default class SQL extends Service<Config, Hooks, Application, Services> {
|
|
|
380
381
|
}
|
|
381
382
|
|
|
382
383
|
// Create equalities
|
|
383
|
-
const egalitesData = this.equalities(data).join(', ')
|
|
384
|
+
const egalitesData = this.equalities(data, true).join(', ')
|
|
384
385
|
const egalitesWhere = this.equalities(where).join(' AND ')
|
|
385
386
|
|
|
386
387
|
// Build query
|
|
@@ -76,7 +76,9 @@ export default class LocalFS<
|
|
|
76
76
|
bucketName: TBucketName,
|
|
77
77
|
filename: string
|
|
78
78
|
) {
|
|
79
|
-
|
|
79
|
+
const bucketDir = this.config.buckets[bucketName];
|
|
80
|
+
const fullPath = path.join( this.rootDir, bucketDir, filename || '.' );
|
|
81
|
+
return fullPath;
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
public async readDir( bucketName: TBucketName, dirname?: string ) {
|
|
@@ -135,7 +137,7 @@ export default class LocalFS<
|
|
|
135
137
|
const fullPath = path.join( this.rootDir, bucketDir, filename );
|
|
136
138
|
|
|
137
139
|
this.config.debug && console.log(`readFile ${fullPath}`);
|
|
138
|
-
return fs.readFileSync( fullPath )
|
|
140
|
+
return fs.readFileSync( fullPath );
|
|
139
141
|
}
|
|
140
142
|
|
|
141
143
|
public createReadStream( bucketName: TBucketName, filename: string ) {
|
|
@@ -583,11 +583,8 @@ declare type Routes = {
|
|
|
583
583
|
private async handleError( e: CoreError, request: ServerRequest<ServerRouter> ) {
|
|
584
584
|
|
|
585
585
|
const code = 'http' in e ? e.http : 500;
|
|
586
|
-
const route = this.errors[code];
|
|
587
|
-
if (route === undefined)
|
|
588
|
-
throw new Error(`No route for error code ${code}`);
|
|
589
586
|
|
|
590
|
-
const response = new ServerResponse(request).status(code)
|
|
587
|
+
const response = new ServerResponse(request).status(code)
|
|
591
588
|
|
|
592
589
|
// Rapport / debug
|
|
593
590
|
if (code === 500) {
|
|
@@ -605,18 +602,24 @@ declare type Routes = {
|
|
|
605
602
|
} else {
|
|
606
603
|
|
|
607
604
|
// For debugging HTTP errors
|
|
608
|
-
if (this.app.env.profile === "dev")
|
|
609
|
-
console.warn(e)
|
|
605
|
+
/*if (this.app.env.profile === "dev")
|
|
606
|
+
console.warn(e);*/
|
|
610
607
|
|
|
611
608
|
await this.app.runHook('error.' + code, e, request);
|
|
612
609
|
}
|
|
613
610
|
|
|
614
611
|
// Return error based on the request format
|
|
615
612
|
if (request.accepts("html")) {
|
|
613
|
+
|
|
614
|
+
const route = this.errors[code];
|
|
615
|
+
if (route === undefined)
|
|
616
|
+
throw new Error(`No route for error code ${code}`);
|
|
617
|
+
|
|
616
618
|
const jsonError = errorToJson(e);
|
|
617
|
-
await response.runController(route, {
|
|
619
|
+
await response.setRoute(route).runController(route, {
|
|
618
620
|
error: jsonError
|
|
619
621
|
});
|
|
622
|
+
|
|
620
623
|
} else if (request.accepts("json")) {
|
|
621
624
|
const jsonError = errorToJson(e);
|
|
622
625
|
await response.json(jsonError);
|
|
@@ -310,8 +310,15 @@ export default class ServerResponse<
|
|
|
310
310
|
}
|
|
311
311
|
|
|
312
312
|
// envoi filename
|
|
313
|
-
const file = await disk.readFile('data', filename, {
|
|
313
|
+
const file = await disk.readFile('data', filename, {
|
|
314
|
+
encoding: 'buffer'
|
|
315
|
+
});
|
|
314
316
|
this.data = file;
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
// Mimetype
|
|
320
|
+
this.headers['Content-Type'] = 'image/jpeg';
|
|
321
|
+
|
|
315
322
|
return this.end();
|
|
316
323
|
}
|
|
317
324
|
|