prostgles-server 2.0.189 → 2.0.192
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/dist/DboBuilder/insertDataParse.d.ts.map +1 -1
- package/dist/DboBuilder/insertDataParse.js +12 -3
- package/dist/DboBuilder/insertDataParse.js.map +1 -1
- package/dist/DboBuilder.d.ts +5 -4
- package/dist/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder.js +54 -153
- package/dist/DboBuilder.js.map +1 -1
- package/dist/FileManager.d.ts +20 -72
- package/dist/FileManager.d.ts.map +1 -1
- package/dist/FileManager.js +233 -164
- package/dist/FileManager.js.map +1 -1
- package/dist/PostgresNotifListenManager.d.ts.map +1 -1
- package/dist/PostgresNotifListenManager.js +3 -1
- package/dist/PostgresNotifListenManager.js.map +1 -1
- package/dist/Prostgles.d.ts +13 -2
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +8 -4
- package/dist/Prostgles.js.map +1 -1
- package/dist/TableConfig.d.ts +1 -2
- package/dist/TableConfig.d.ts.map +1 -1
- package/dist/TableConfig.js.map +1 -1
- package/lib/DboBuilder/insertDataParse.d.ts.map +1 -1
- package/lib/DboBuilder/insertDataParse.js +12 -3
- package/lib/DboBuilder/insertDataParse.ts +12 -3
- package/lib/DboBuilder.d.ts +5 -4
- package/lib/DboBuilder.d.ts.map +1 -1
- package/lib/DboBuilder.js +54 -153
- package/lib/DboBuilder.ts +67 -181
- package/lib/FileManager.d.ts +19 -71
- package/lib/FileManager.d.ts.map +1 -1
- package/lib/FileManager.js +233 -164
- package/lib/FileManager.ts +274 -191
- package/lib/PostgresNotifListenManager.d.ts.map +1 -1
- package/lib/PostgresNotifListenManager.js +3 -1
- package/lib/PostgresNotifListenManager.ts +4 -1
- package/lib/Prostgles.d.ts +13 -2
- package/lib/Prostgles.d.ts.map +1 -1
- package/lib/Prostgles.js +8 -4
- package/lib/Prostgles.ts +9 -5
- package/lib/TableConfig.d.ts +1 -2
- package/lib/TableConfig.d.ts.map +1 -1
- package/lib/TableConfig.ts +2 -4
- package/lib/fileType/core.js +1527 -0
- package/lib/fileType/supported.js +278 -0
- package/package.json +3 -3
- package/tests/client/PID.txt +1 -1
- package/tests/server/DBoGenerated.d.ts +1 -1
- package/tests/server/package-lock.json +5 -5
package/lib/FileManager.ts
CHANGED
|
@@ -3,12 +3,11 @@ import { S3 } from 'aws-sdk';
|
|
|
3
3
|
import { ManagedUpload } from 'aws-sdk/clients/s3';
|
|
4
4
|
import * as fs from 'fs';
|
|
5
5
|
|
|
6
|
-
import * as FileType from "file-type";
|
|
7
6
|
import * as sharp from "sharp";
|
|
8
7
|
|
|
9
8
|
import { DB, DBHandlerServer, Prostgles } from './Prostgles';
|
|
10
|
-
import { asName, getKeys } from 'prostgles-types';
|
|
11
|
-
import { TableHandler } from './DboBuilder';
|
|
9
|
+
import { ALLOWED_CONTENT_TYPE, ALLOWED_EXTENSION, asName, CONTENT_TYPE_TO_EXT, getKeys, isObject, ValidatedColumnInfo } from 'prostgles-types';
|
|
10
|
+
import { TableHandler, ViewHandler } from './DboBuilder';
|
|
12
11
|
|
|
13
12
|
const HOUR = 3600 * 1000;
|
|
14
13
|
|
|
@@ -89,7 +88,7 @@ export default class FileManager {
|
|
|
89
88
|
this.imageOptions = imageOptions;
|
|
90
89
|
|
|
91
90
|
if("region" in config){
|
|
92
|
-
const { region,accessKeyId, secretAccessKey } = config;
|
|
91
|
+
const { region, accessKeyId, secretAccessKey } = config;
|
|
93
92
|
this.s3Client = new S3({
|
|
94
93
|
region,
|
|
95
94
|
credentials: { accessKeyId, secretAccessKey },
|
|
@@ -97,81 +96,136 @@ export default class FileManager {
|
|
|
97
96
|
}
|
|
98
97
|
}
|
|
99
98
|
|
|
100
|
-
async
|
|
101
|
-
file: Buffer |
|
|
102
|
-
fileName: string,
|
|
103
|
-
allowedExtensions?: Array<ALLOWED_EXTENSION>,
|
|
104
|
-
dissallowedExtensions?: Array<ALLOWED_EXTENSION>,
|
|
105
|
-
onlyFromName = true
|
|
106
|
-
): Promise<{
|
|
107
|
-
mime: string;
|
|
108
|
-
ext: string | ALLOWED_EXTENSION;
|
|
99
|
+
async parseFile(args: {
|
|
100
|
+
file: Buffer | string;
|
|
109
101
|
fileName: string;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
mime = getKeys(CONTENT_TYPE_TO_EXT).find(k => (CONTENT_TYPE_TO_EXT[k] as readonly string[]).includes(nameExt));
|
|
116
|
-
|
|
117
|
-
let type = {
|
|
118
|
-
fileName,
|
|
119
|
-
mime,
|
|
120
|
-
ext: nameExt,
|
|
121
|
-
}
|
|
102
|
+
colName?: string;
|
|
103
|
+
tableName?: string;
|
|
104
|
+
}): Promise<{
|
|
105
|
+
mime: string | ALLOWED_CONTENT_TYPE;
|
|
106
|
+
ext: string | ALLOWED_EXTENSION;
|
|
122
107
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
108
|
+
/** File name is not returned because we fail if the extensions do not match */
|
|
109
|
+
// fileName: string;
|
|
110
|
+
}> {
|
|
111
|
+
const { file, fileName, tableName, colName } = args;
|
|
112
|
+
const config = this.prostgles?.opts.fileTable;
|
|
113
|
+
if(!config) throw new Error("File table config missing");
|
|
114
|
+
|
|
115
|
+
const buffer = typeof file === "string"? Buffer.from(file, 'utf8') : file;
|
|
116
|
+
const mime = await getFileType(buffer, fileName);
|
|
117
|
+
|
|
118
|
+
if(tableName && colName){
|
|
119
|
+
const tableConfig = config.referencedTables?.[tableName];
|
|
120
|
+
|
|
121
|
+
if(tableConfig && isObject(tableConfig) && tableConfig.referenceColumns[colName]){
|
|
122
|
+
const colConfig = tableConfig.referenceColumns[colName];
|
|
123
|
+
if(colConfig.maxFileSizeMB){
|
|
124
|
+
const actualBufferSize = Buffer.byteLength(buffer);
|
|
125
|
+
if((actualBufferSize/1e6) > colConfig.maxFileSizeMB){
|
|
126
|
+
throw new Error(`Provided file is larger than the ${colConfig.maxFileSizeMB}MB limit`);
|
|
127
|
+
}
|
|
136
128
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
129
|
+
|
|
130
|
+
if("acceptedContent" in colConfig && colConfig.acceptedContent){
|
|
131
|
+
const CONTENTS = [
|
|
132
|
+
"image",
|
|
133
|
+
"audio",
|
|
134
|
+
"video",
|
|
135
|
+
"text",
|
|
136
|
+
"application",
|
|
137
|
+
];
|
|
138
|
+
const allowedContent = ViewHandler._parseFieldFilter(colConfig.acceptedContent, false, CONTENTS);
|
|
139
|
+
if(!allowedContent.some(c => mime.mime.startsWith(c))){
|
|
140
|
+
throw new Error(`Dissallowed content type provided: ${mime.mime.split("/")[0]}. Allowed content types: ${allowedContent} `)
|
|
141
|
+
}
|
|
142
|
+
} else if("acceptedContentType" in colConfig && colConfig.acceptedContentType){
|
|
143
|
+
const allowedContentTypes = ViewHandler._parseFieldFilter(colConfig.acceptedContentType, false, getKeys(CONTENT_TYPE_TO_EXT));
|
|
144
|
+
|
|
145
|
+
if(!allowedContentTypes.some(c => c === mime.mime)){
|
|
146
|
+
throw new Error(`Dissallowed MIME provided: ${mime.mime}. Allowed MIME values: ${allowedContentTypes} `)
|
|
147
|
+
}
|
|
148
|
+
} else if("acceptedFileTypes" in colConfig && colConfig.acceptedFileTypes){
|
|
149
|
+
const allowedExtensions = ViewHandler._parseFieldFilter(colConfig.acceptedFileTypes, false, Object.values(CONTENT_TYPE_TO_EXT).flat());
|
|
150
|
+
|
|
151
|
+
if(!allowedExtensions.some(c => c === mime.ext)){
|
|
152
|
+
throw new Error(`Dissallowed extension provided: ${mime.ext}. Allowed extension values: ${allowedExtensions} `)
|
|
153
|
+
}
|
|
142
154
|
}
|
|
143
|
-
}
|
|
144
|
-
throw "Unexpected file. Expecting: Buffer | String";
|
|
145
|
-
}
|
|
155
|
+
}
|
|
146
156
|
}
|
|
147
157
|
|
|
148
|
-
|
|
149
|
-
allowedExtensions &&
|
|
150
|
-
!allowedExtensions.map(v => v.toLowerCase())?.includes(type.ext)
|
|
151
|
-
){
|
|
152
|
-
throw fileName + " -> File type ( " + type.ext + " ) not allowed. Expecting one of: " + allowedExtensions.map(v => v.toLowerCase()).join(", ");
|
|
153
|
-
|
|
154
|
-
} else if(
|
|
155
|
-
dissallowedExtensions &&
|
|
156
|
-
dissallowedExtensions.map(v => v.toLowerCase())?.includes(type.ext)
|
|
157
|
-
){
|
|
158
|
-
throw fileName + " -> File type ( " + type.ext + " ) not allowed";
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if(!onlyFromName){
|
|
163
|
-
let { ext } = type;
|
|
164
|
-
if(nameExt !== ext) fileName = nameParts.slice(0, -1).join('') + "." + ext;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const res = {
|
|
168
|
-
...type,
|
|
169
|
-
fileName
|
|
170
|
-
}
|
|
171
|
-
if(!res.mime) throw "Could not find mime"
|
|
172
|
-
return res as any;
|
|
158
|
+
return mime;
|
|
173
159
|
}
|
|
174
160
|
|
|
161
|
+
// private async getMIME(
|
|
162
|
+
// file: Buffer | string,
|
|
163
|
+
// fileName: string,
|
|
164
|
+
// allowedExtensions?: Array<ALLOWED_EXTENSION>,
|
|
165
|
+
// dissallowedExtensions?: Array<ALLOWED_EXTENSION>,
|
|
166
|
+
// onlyFromName = true
|
|
167
|
+
// ): Promise<{
|
|
168
|
+
// mime: string;
|
|
169
|
+
// ext: string | ALLOWED_EXTENSION;
|
|
170
|
+
// fileName: string;
|
|
171
|
+
// }> {
|
|
172
|
+
|
|
173
|
+
// const nameParts = fileName.split(".");
|
|
174
|
+
|
|
175
|
+
// const nameExt = nameParts[nameParts.length - 1].toLowerCase(),
|
|
176
|
+
// mime = getKeys(CONTENT_TYPE_TO_EXT).find(k => (CONTENT_TYPE_TO_EXT[k] as readonly string[]).includes(nameExt));
|
|
177
|
+
|
|
178
|
+
// let type = {
|
|
179
|
+
// fileName,
|
|
180
|
+
// mime,
|
|
181
|
+
// ext: nameExt,
|
|
182
|
+
// }
|
|
183
|
+
|
|
184
|
+
// if(onlyFromName && !mime) throw `Invalid file extension: content_type could not be found for extension(${nameExt})`;
|
|
185
|
+
|
|
186
|
+
// if(!mime){
|
|
187
|
+
// /* Set correct/missing extension */
|
|
188
|
+
// if(["xml", "txt", "csv", "tsv"].includes(nameExt)){
|
|
189
|
+
// type = { ...type, mime: ("text/" + nameExt) as any, ext: nameExt };
|
|
190
|
+
// } else if(["svg"].includes(nameExt)){
|
|
191
|
+
// type = { ...type, mime: "image/svg+xml", ext: nameExt };
|
|
192
|
+
// } else {
|
|
193
|
+
// const res = await getFileTypeFromBuffer(file);
|
|
194
|
+
|
|
195
|
+
// type = {
|
|
196
|
+
// ...(res as any),
|
|
197
|
+
// fileName,
|
|
198
|
+
// }
|
|
199
|
+
// }
|
|
200
|
+
// }
|
|
201
|
+
|
|
202
|
+
// if(
|
|
203
|
+
// allowedExtensions &&
|
|
204
|
+
// !allowedExtensions.map(v => v.toLowerCase())?.includes(type.ext)
|
|
205
|
+
// ){
|
|
206
|
+
// throw fileName + " -> File type ( " + type.ext + " ) not allowed. Expecting one of: " + allowedExtensions.map(v => v.toLowerCase()).join(", ");
|
|
207
|
+
|
|
208
|
+
// } else if(
|
|
209
|
+
// dissallowedExtensions &&
|
|
210
|
+
// dissallowedExtensions.map(v => v.toLowerCase())?.includes(type.ext)
|
|
211
|
+
// ){
|
|
212
|
+
// throw fileName + " -> File type ( " + type.ext + " ) not allowed";
|
|
213
|
+
|
|
214
|
+
// }
|
|
215
|
+
|
|
216
|
+
// if(!onlyFromName){
|
|
217
|
+
// let { ext } = type;
|
|
218
|
+
// if(nameExt !== ext) fileName = nameParts.slice(0, -1).join('') + "." + ext;
|
|
219
|
+
// }
|
|
220
|
+
|
|
221
|
+
// const res = {
|
|
222
|
+
// ...type,
|
|
223
|
+
// fileName
|
|
224
|
+
// }
|
|
225
|
+
// if(!res.mime) throw "Could not find mime"
|
|
226
|
+
// return res as any;
|
|
227
|
+
// }
|
|
228
|
+
|
|
175
229
|
// async getUploadURL(fileName: string): Promise<string> {
|
|
176
230
|
// const thisHour = new Date();
|
|
177
231
|
// thisHour.setMilliseconds(0);
|
|
@@ -317,6 +371,19 @@ export default class FileManager {
|
|
|
317
371
|
|
|
318
372
|
private parseSQLIdentifier = async (name: string ) => asSQLIdentifier(name, this.prostgles!.db!);// this.prostgles.dbo.sql<"value">("select format('%I', $1)", [name], { returnType: "value" } )
|
|
319
373
|
|
|
374
|
+
getColInfo = (args: { tableName: string; colName: string }): ValidatedColumnInfo["file"] | undefined => {
|
|
375
|
+
const { colName, tableName } = args;
|
|
376
|
+
const tableConfig = this.prostgles?.opts.fileTable?.referencedTables?.[tableName];
|
|
377
|
+
const isReferencingFileTable = this.dbo[tableName]?.columns?.some(c => c.name === colName && c.references && c.references?.ftable === this.tableName);
|
|
378
|
+
if(isReferencingFileTable){
|
|
379
|
+
if(tableConfig && typeof tableConfig !== "string"){
|
|
380
|
+
return tableConfig.referenceColumns[colName];
|
|
381
|
+
}
|
|
382
|
+
return { acceptedContent: "*" };
|
|
383
|
+
}
|
|
384
|
+
return undefined;
|
|
385
|
+
}
|
|
386
|
+
|
|
320
387
|
init = async (prg: Prostgles) => {
|
|
321
388
|
this.prostgles = prg;
|
|
322
389
|
|
|
@@ -330,6 +397,8 @@ export default class FileManager {
|
|
|
330
397
|
const maxBfSizeMB = (prg.opts.io?.engine?.opts?.maxHttpBufferSize || 1e6)/1e6;
|
|
331
398
|
console.log(`Prostgles: Initiated file manager. Max allowed file size: ${maxBfSizeMB}MB (maxHttpBufferSize = 1e6). To increase this set maxHttpBufferSize in socket.io server init options`);
|
|
332
399
|
|
|
400
|
+
// throw `this.db.tx(d => do everything in a transaction pls!!!!`;
|
|
401
|
+
|
|
333
402
|
// throw "Why are constraints dissapearing?"
|
|
334
403
|
/**
|
|
335
404
|
* 1. Create media table
|
|
@@ -361,64 +430,103 @@ export default class FileManager {
|
|
|
361
430
|
/**
|
|
362
431
|
* 2. Create media lookup tables
|
|
363
432
|
*/
|
|
364
|
-
await Promise.all(
|
|
365
|
-
if(!this.dbo[refTable]) throw `Referenced table (${refTable}) from fileTable.referencedTables
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
await Promise.all(badCols.map(async badCol => {
|
|
393
|
-
console.error(
|
|
394
|
-
`Prostgles: media ${lookupTableName} joining table has lost a reference constraint for column ${badCol.name}.` +
|
|
395
|
-
` This may have been caused by a DROP TABLE ... CASCADE.`
|
|
396
|
-
);
|
|
397
|
-
let q = `
|
|
398
|
-
ALTER TABLE ${asName(lookupTableName)}
|
|
399
|
-
ADD CONSTRAINT ${(lookupTableName + "_" + badCol.name + "_r")} FOREIGN KEY (${badCol.name})
|
|
400
|
-
`;
|
|
401
|
-
console.log("Trying to add the missing constraint back");
|
|
402
|
-
if(badCol.name === "foreign_id"){
|
|
403
|
-
q += `REFERENCES ${asName(refTable)}(${asName(pkField.name)}) `;
|
|
404
|
-
} else if(badCol.name === "media_id"){
|
|
405
|
-
q += `REFERENCES ${asName(tableName)}(id) `;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
if(q){
|
|
409
|
-
|
|
433
|
+
await Promise.all(getKeys(referencedTables).map(async refTable => {
|
|
434
|
+
if(!this.dbo[refTable]) throw `Referenced table (${refTable}) from fileTable.referencedTables prostgles init config is missing`;
|
|
435
|
+
const cols = await (this.dbo[refTable] as unknown as TableHandler).getColumns();
|
|
436
|
+
|
|
437
|
+
const tableConfig = referencedTables[refTable];
|
|
438
|
+
if(typeof tableConfig !== "string"){
|
|
439
|
+
|
|
440
|
+
for await (const colName of getKeys(tableConfig.referenceColumns)){
|
|
441
|
+
|
|
442
|
+
const existingCol = cols.find(c => c.name === colName);
|
|
443
|
+
if(existingCol){
|
|
444
|
+
if(existingCol.references?.ftable === tableName){
|
|
445
|
+
// All ok
|
|
446
|
+
} else {
|
|
447
|
+
if(existingCol.udt_name === "uuid"){
|
|
448
|
+
try {
|
|
449
|
+
const query = `ALTER TABLE ${asName(tableName)} ADD CONSTRAINT FOREIGN KEY (${asName(colName)}) REFERENCES ${asName(tableName)} (id);`;
|
|
450
|
+
console.log(`Referenced file column ${refTable} (${colName}) exists but is not referencing file table. Trying to add REFERENCE constraing...\n${query}`);
|
|
451
|
+
await this.db.any(query);
|
|
452
|
+
console.log("SUCCESS: " + query);
|
|
453
|
+
} catch(e){
|
|
454
|
+
throw new Error(`Could not add constraing. Err: ${e instanceof Error? e.message : JSON.stringify(e)}`)
|
|
455
|
+
}
|
|
456
|
+
} else {
|
|
457
|
+
throw new Error(`Referenced file column ${refTable} (${colName}) exists but is not of required type (UUID). Choose a different column name or ALTER the existing column to match the type and the data found in file table ${tableName}(id)`);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
} else {
|
|
410
461
|
try {
|
|
411
|
-
|
|
412
|
-
console.log(
|
|
413
|
-
|
|
462
|
+
const query = `ALTER TABLE ${asName(tableName)} ADD COLUMN ${asName(colName)} UUID REFERENCES ${asName(tableName)} (id);`
|
|
463
|
+
console.log(`Creating referenced file column ${refTable} (${colName})...\n${query}`);
|
|
464
|
+
await this.db.any(query);
|
|
465
|
+
console.log("SUCCESS: " + query);
|
|
414
466
|
} catch(e){
|
|
415
|
-
|
|
467
|
+
throw new Error(`FAILED. Err: ${e instanceof Error? e.message : JSON.stringify(e)}`)
|
|
416
468
|
}
|
|
417
469
|
}
|
|
470
|
+
|
|
471
|
+
}
|
|
472
|
+
} else {
|
|
418
473
|
|
|
419
|
-
})
|
|
474
|
+
const lookupTableName = await this.parseSQLIdentifier(`prostgles_lookup_${tableName}_${refTable}`);
|
|
475
|
+
const pKeyFields = cols.filter(f => f.is_pkey);
|
|
476
|
+
|
|
477
|
+
if(pKeyFields.length !== 1) throw `Could not make link table for ${refTable}. ${pKeyFields} must have exactly one primary key column. Current pkeys: ${pKeyFields.map(f => f.name)}`;
|
|
478
|
+
|
|
479
|
+
const pkField = pKeyFields[0];
|
|
480
|
+
const refType = referencedTables[refTable];
|
|
481
|
+
|
|
482
|
+
if(!this.dbo[lookupTableName]){
|
|
483
|
+
// if(!(await dbo[lookupTableName].count())) await db.any(`DROP TABLE IF EXISTS ${lookupTableName};`);
|
|
484
|
+
const action = ` (${tableName} <-> ${refTable}) join table ${lookupTableName}`; // PRIMARY KEY
|
|
485
|
+
const query = `
|
|
486
|
+
CREATE TABLE ${lookupTableName} (
|
|
487
|
+
foreign_id ${pkField.udt_name} ${refType === "one"? " PRIMARY KEY " : ""} REFERENCES ${asName(refTable)}(${asName(pkField.name)}),
|
|
488
|
+
media_id UUID NOT NULL REFERENCES ${asName(tableName)}(id)
|
|
489
|
+
)
|
|
490
|
+
`;
|
|
491
|
+
console.log(`Creating ${action} ...`, lookupTableName);
|
|
492
|
+
await this.db.any(query);
|
|
493
|
+
console.log(`Created ${action}`);
|
|
494
|
+
|
|
495
|
+
} else {
|
|
496
|
+
const cols = await this.dbo[lookupTableName].getColumns!();
|
|
497
|
+
const badCols = cols.filter(c => !c.references);
|
|
498
|
+
await Promise.all(badCols.map(async badCol => {
|
|
499
|
+
console.error(
|
|
500
|
+
`Prostgles: media ${lookupTableName} joining table has lost a reference constraint for column ${badCol.name}.` +
|
|
501
|
+
` This may have been caused by a DROP TABLE ... CASCADE.`
|
|
502
|
+
);
|
|
503
|
+
let q = `
|
|
504
|
+
ALTER TABLE ${asName(lookupTableName)}
|
|
505
|
+
ADD CONSTRAINT ${(lookupTableName + "_" + badCol.name + "_r")} FOREIGN KEY (${badCol.name})
|
|
506
|
+
`;
|
|
507
|
+
console.log("Trying to add the missing constraint back");
|
|
508
|
+
if(badCol.name === "foreign_id"){
|
|
509
|
+
q += `REFERENCES ${asName(refTable)}(${asName(pkField.name)}) `;
|
|
510
|
+
} else if(badCol.name === "media_id"){
|
|
511
|
+
q += `REFERENCES ${asName(tableName)}(id) `;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
if(q){
|
|
515
|
+
|
|
516
|
+
try {
|
|
517
|
+
await this.db.any(q)
|
|
518
|
+
console.log("Added missing constraint back");
|
|
519
|
+
|
|
520
|
+
} catch(e){
|
|
521
|
+
console.error("Failed to add missing constraint", e)
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
}));
|
|
526
|
+
}
|
|
420
527
|
}
|
|
421
528
|
|
|
529
|
+
|
|
422
530
|
await prg.refreshDBO();
|
|
423
531
|
return true;
|
|
424
532
|
}));
|
|
@@ -493,76 +601,51 @@ export default class FileManager {
|
|
|
493
601
|
}
|
|
494
602
|
}
|
|
495
603
|
|
|
496
|
-
const
|
|
497
|
-
|
|
498
|
-
"
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
"application/x-javascript": ["js"],
|
|
516
|
-
"application/atom+xml": ["atom"],
|
|
517
|
-
"application/rss+xml": ["rss"],
|
|
518
|
-
"application/java-archive": ["jar", "war", "ear"],
|
|
519
|
-
"application/mac-binhex40": ["hqx"],
|
|
520
|
-
"application/msword": ["doc", "docx"],
|
|
521
|
-
"application/pdf": ["pdf"],
|
|
522
|
-
"application/postscript": ["ps", "eps", "ai"],
|
|
523
|
-
"application/rtf": ["rtf"],
|
|
524
|
-
"application/vnd.ms-excel": ["xls", "xlsx"],
|
|
525
|
-
"application/vnd.ms-powerpoint": ["ppt", "pptx"],
|
|
526
|
-
"application/vnd.wap.wmlc": ["wmlc"],
|
|
527
|
-
"application/vnd.google-earth.kml+xml": ["kml"],
|
|
528
|
-
"application/vnd.google-earth.kmz": ["kmz"],
|
|
529
|
-
"application/x-7z-compressed": ["7z"],
|
|
530
|
-
"application/x-cocoa": ["cco"],
|
|
531
|
-
"application/x-java-archive-diff": ["jardiff"],
|
|
532
|
-
"application/x-java-jnlp-file": ["jnlp"],
|
|
533
|
-
"application/x-makeself": ["run"],
|
|
534
|
-
"application/x-perl": ["pl", "pm"],
|
|
535
|
-
"application/x-pilot": ["prc", "pdb"],
|
|
536
|
-
"application/x-rar-compressed": ["rar"],
|
|
537
|
-
"application/x-redhat-package-manager": ["rpm"],
|
|
538
|
-
"application/x-sea": ["sea"],
|
|
539
|
-
"application/x-shockwave-flash": ["swf"],
|
|
540
|
-
"application/x-stuffit": ["sit"],
|
|
541
|
-
"application/x-tcl": ["tcl", "tk"],
|
|
542
|
-
"application/x-x509-ca-cert": ["der", "pem", "crt"],
|
|
543
|
-
"application/x-xpinstall": ["xpi"],
|
|
544
|
-
"application/xhtml+xml": ["xhtml"],
|
|
545
|
-
"application/zip": ["zip"],
|
|
546
|
-
"application/octet-stream": ["bin", "exe", "dll", "deb", "dmg", "eot", "iso", "img", "msi", "msp", "msm"],
|
|
547
|
-
"audio/midi": ["mid", "midi", "kar"],
|
|
548
|
-
"audio/mpeg": ["mp3"],
|
|
549
|
-
"audio/ogg": ["ogg"],
|
|
550
|
-
"audio/x-realaudio": ["ra"],
|
|
551
|
-
"video/3gpp": ["3gpp", "3gp"],
|
|
552
|
-
"video/mpeg": ["mpeg", "mpg"],
|
|
553
|
-
"video/quicktime": ["mov"],
|
|
554
|
-
"video/x-flv": ["flv"],
|
|
555
|
-
"video/x-mng": ["mng"],
|
|
556
|
-
"video/x-ms-asf": ["asx", "asf"],
|
|
557
|
-
"video/x-ms-wmv": ["wmv"],
|
|
558
|
-
"video/x-msvideo": ["avi"],
|
|
559
|
-
"video/mp4": ["m4v", "mp4"],
|
|
560
|
-
"video/webm": ["webm"],
|
|
561
|
-
} as const;
|
|
562
|
-
|
|
563
|
-
export type ALLOWED_CONTENT_TYPE = keyof typeof CONTENT_TYPE_TO_EXT;
|
|
564
|
-
export type ALLOWED_EXTENSION = (typeof CONTENT_TYPE_TO_EXT)[ALLOWED_CONTENT_TYPE][number];
|
|
604
|
+
export const getFileTypeFromFilename = (fileName: string): { mime: ALLOWED_CONTENT_TYPE; ext: ALLOWED_EXTENSION } | undefined => {
|
|
605
|
+
|
|
606
|
+
const nameParts = fileName.split(".");
|
|
607
|
+
|
|
608
|
+
if(!nameParts.length) return undefined;
|
|
609
|
+
|
|
610
|
+
const nameExt = nameParts[nameParts.length - 1].toLowerCase(),
|
|
611
|
+
mime = getKeys(CONTENT_TYPE_TO_EXT).find(k => (CONTENT_TYPE_TO_EXT[k] as readonly string[]).includes(nameExt));
|
|
612
|
+
|
|
613
|
+
if(!mime) return undefined;
|
|
614
|
+
|
|
615
|
+
return {
|
|
616
|
+
mime,
|
|
617
|
+
ext: nameExt as ALLOWED_EXTENSION,
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// const fileType = require("file-type");
|
|
622
|
+
// const res = await fileType.fromBuffer(typeof file === "string"? Buffer.from(file, 'utf8') : file);
|
|
565
623
|
|
|
624
|
+
export const getFileType = async (file: Buffer | string, fileName: string): Promise<{ mime: ALLOWED_CONTENT_TYPE; ext: ALLOWED_EXTENSION }> => {
|
|
625
|
+
|
|
626
|
+
const { fileTypeFromBuffer } = await (eval('import("file-type")') as Promise<typeof import('file-type')>);
|
|
627
|
+
|
|
628
|
+
const fileNameMime = getFileTypeFromFilename(fileName);
|
|
629
|
+
if(!fileNameMime?.ext) throw new Error("File name must contain extenions")
|
|
630
|
+
const res = await fileTypeFromBuffer(typeof file === "string"? Buffer.from(file, 'utf8') : file);
|
|
631
|
+
|
|
632
|
+
if(!res) {
|
|
633
|
+
|
|
634
|
+
/* Set correct/missing extension */
|
|
635
|
+
const nameExt = fileNameMime?.ext;
|
|
636
|
+
if(["xml", "txt", "csv", "tsv", "svg"].includes(nameExt)){
|
|
637
|
+
return fileNameMime
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
throw new Error("Could not get the file type from file buffer");
|
|
641
|
+
} else {
|
|
642
|
+
|
|
643
|
+
if(!res.ext || fileNameMime?.ext.toLowerCase() !== res.ext.toLowerCase()){
|
|
644
|
+
throw new Error(`There is a mismatch between file name extension and actual buffer extension: ${fileNameMime?.ext } vs ${res.ext}`)
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
return res as any;
|
|
648
|
+
}
|
|
566
649
|
|
|
567
650
|
|
|
568
651
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostgresNotifListenManager.d.ts","sourceRoot":"","sources":["PostgresNotifListenManager.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,iCAAiC,CAAC;AACjD,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,oBAAY,iBAAiB,GAAG,CAAC,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;CAAE,KAAK,IAAI,CAAC;AACvI,qBAAa,0BAA0B;IACnC,UAAU,CAAC,EAAE,SAAS,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC;IAClD,KAAK,EAAE,EAAE,CAAC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BAAiB,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,UAAQ;IAS1F,IAAI,IAAI,OAAO,CAAC,0BAA0B,CAAC;IAQjD,OAAO;IAIP,cAAc;IA+Bd,OAAO,aAKN;IAED,aAAa,aAKZ;IAED,SAAS,CAAC,KAAK,GAAE,MAAM,GAAG,SAAa,EAAE,WAAW,GAAE,MAAM,GAAG,SAAa;CAsD/E"}
|
|
@@ -8,8 +8,10 @@ exports.PostgresNotifListenManager = void 0;
|
|
|
8
8
|
class PostgresNotifListenManager {
|
|
9
9
|
constructor(db_pg, notifListener, db_channel_name, noInit = false) {
|
|
10
10
|
this.destroy = () => {
|
|
11
|
-
if (this.connection)
|
|
11
|
+
if (this.connection) {
|
|
12
12
|
this.connection.done();
|
|
13
|
+
this.connection = undefined;
|
|
14
|
+
}
|
|
13
15
|
};
|
|
14
16
|
this.stopListening = () => {
|
|
15
17
|
if (this.db_channel_name) {
|
package/lib/Prostgles.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import TableConfigurator, { TableConfig } from "./TableConfig";
|
|
|
7
7
|
import { DboBuilder, DBHandlerServer, PRGLIOSocket } from "./DboBuilder";
|
|
8
8
|
export { DBHandlerServer };
|
|
9
9
|
export declare type PGP = pgPromise.IMain<{}, pg.IClient>;
|
|
10
|
-
import { AnyObject } from "prostgles-types";
|
|
10
|
+
import { AnyObject, FileColumnConfig } from "prostgles-types";
|
|
11
11
|
import { Publish, PublishMethods, PublishParams, PublishParser } from "./PublishParser";
|
|
12
12
|
import { DBEventsManager } from "./DBEventsManager";
|
|
13
13
|
export declare type DB = pgPromise.IDatabase<{}, pg.IClient>;
|
|
@@ -76,7 +76,18 @@ export declare type FileTableConfig = {
|
|
|
76
76
|
localConfig?: LocalConfig;
|
|
77
77
|
expressApp: ExpressApp;
|
|
78
78
|
referencedTables?: {
|
|
79
|
-
[tableName: string]: "one" | "many"
|
|
79
|
+
[tableName: string]: "one" | "many"
|
|
80
|
+
/**
|
|
81
|
+
* If defined then will try to create (if necessary) a column in the files table which will reference this table's primary key (must have one)
|
|
82
|
+
* */
|
|
83
|
+
/**
|
|
84
|
+
* If defined then will try to create (if necessary) this column which will reference files_table(id)
|
|
85
|
+
* Prostgles UI will use these hints (obtained through tableHandler.getInfo())
|
|
86
|
+
* */
|
|
87
|
+
| {
|
|
88
|
+
type: "column";
|
|
89
|
+
referenceColumns: Record<string, FileColumnConfig>;
|
|
90
|
+
};
|
|
80
91
|
};
|
|
81
92
|
imageOptions?: ImageOptions;
|
|
82
93
|
};
|
package/lib/Prostgles.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Prostgles.d.ts","sourceRoot":"","sources":["Prostgles.ts"],"names":[],"mappings":";AAMA,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,GAAG,QAAQ,iCAAiC,CAAC,CAAC;AACvD,OAAO,WAAW,EAAE,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAIjF,OAAO,WAAW,EAAE,EAAc,IAAI,EAAE,MAAM,eAAe,CAAC;AAG9D,OAAO,iBAAiB,EAAE,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG/D,OAAO,EAAE,UAAU,EAAE,eAAe,EAA2C,YAAY,EAAE,MAAM,cAAc,CAAC;AAElH,OAAO,EAAE,eAAe,EAAE,CAAA;AAC1B,oBAAY,GAAG,GAAG,SAAS,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC;AAElD,OAAO,EAA8C,SAAS,EAAkD,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"Prostgles.d.ts","sourceRoot":"","sources":["Prostgles.ts"],"names":[],"mappings":";AAMA,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,GAAG,QAAQ,iCAAiC,CAAC,CAAC;AACvD,OAAO,WAAW,EAAE,EAAE,YAAY,EAAE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WAAW,CAAC;IAE1B,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IAEtC,OAAO,CAAC,SAAS,EAAE,MAAM;gBAIb,MAAM,EAAE,oBAAoB;IA+BxC,SAAS,UAAS;IAEZ,cAAc,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;IA+B9D,OAAO;IAIP,aAAa;;;;IAMb,OAAO,CAAC,WAAW;IASnB,aAAa,CAAC,KAAK,UAAQ;IAmB3B,UAAU,iCAUT;IAED,WAAW,UAAS;IACpB,0BAA0B,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC;IACtC,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,aAAa,EAAE,EAAE,EAAE,EAAE,KAAK,GAAG,GAAG,OAAO,CAAC;QAChE,EAAE,EAAE,aAAa,CAAC;QAClB,GAAG,EAAE,EAAE,CAAC;QACR,GAAG,EAAE,GAAG,CAAC;QACT,EAAE,CAAC,EAAE,GAAG,CAAC;QACT,OAAO,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;KACjC,CAAC;IAuJI,UAAU,CAAC,QAAQ,EAAE,MAAM;IA0BjC,gBAAgB,EAAE,GAAG,EAAE,CAAM;IACvB,eAAe;IAsGrB,gBAAgB,WAAkB,GAAG,mBAkFpC;CACF;AAqCD,wBAAsB,WAAW,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAE1D"}
|
package/lib/Prostgles.js
CHANGED
|
@@ -116,9 +116,13 @@ class Prostgles {
|
|
|
116
116
|
this.loaded = false;
|
|
117
117
|
this.destroyed = false;
|
|
118
118
|
this.refreshDBO = async () => {
|
|
119
|
-
if (this._dboBuilder)
|
|
120
|
-
this._dboBuilder.
|
|
121
|
-
|
|
119
|
+
if (this._dboBuilder) {
|
|
120
|
+
await this._dboBuilder.build();
|
|
121
|
+
// this._dboBuilder.destroy();
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
this.dboBuilder = await DboBuilder_1.DboBuilder.create(this);
|
|
125
|
+
}
|
|
122
126
|
if (!this.dboBuilder)
|
|
123
127
|
throw "this.dboBuilder";
|
|
124
128
|
this.dbo = this.dboBuilder.dbo;
|
|
@@ -316,7 +320,7 @@ class Prostgles {
|
|
|
316
320
|
this.schema_checkIntervalMillis = setInterval(async () => {
|
|
317
321
|
const dbuilder = await DboBuilder_1.DboBuilder.create(this);
|
|
318
322
|
if (dbuilder.tsTypesDefinition !== this.dboBuilder.tsTypesDefinition) {
|
|
319
|
-
this.refreshDBO();
|
|
323
|
+
await this.refreshDBO();
|
|
320
324
|
this.init(onReady);
|
|
321
325
|
}
|
|
322
326
|
}, this.opts.watchSchemaType.checkIntervalMillis);
|