prostgles-server 2.0.178 → 2.0.179
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/AuthHandler.d.ts +4 -4
- package/dist/AuthHandler.d.ts.map +1 -1
- package/dist/DBSchemaBuilder.d.ts +6 -6
- package/dist/DBSchemaBuilder.d.ts.map +1 -1
- package/dist/DBSchemaBuilder.js +25 -8
- package/dist/DBSchemaBuilder.js.map +1 -1
- package/dist/DboBuilder.d.ts +20 -21
- package/dist/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder.js +1 -1
- package/dist/DboBuilder.js.map +1 -1
- package/dist/Prostgles.d.ts +8 -10
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js.map +1 -1
- package/dist/PublishParser.d.ts +37 -37
- package/dist/PublishParser.d.ts.map +1 -1
- package/dist/PublishParser.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/lib/AuthHandler.d.ts +148 -0
- package/lib/AuthHandler.d.ts.map +1 -0
- package/lib/AuthHandler.js +411 -0
- package/lib/AuthHandler.ts +3 -3
- package/lib/DBEventsManager.d.ts +38 -0
- package/lib/DBEventsManager.d.ts.map +1 -0
- package/lib/DBEventsManager.js +136 -0
- package/lib/DBSchemaBuilder.d.ts +11 -0
- package/lib/DBSchemaBuilder.d.ts.map +1 -0
- package/lib/DBSchemaBuilder.js +102 -0
- package/lib/DBSchemaBuilder.ts +62 -27
- package/lib/DboBuilder.d.ts +428 -0
- package/lib/DboBuilder.d.ts.map +1 -0
- package/lib/DboBuilder.js +3078 -0
- package/lib/DboBuilder.ts +25 -25
- package/lib/FileManager.d.ts +168 -0
- package/lib/FileManager.d.ts.map +1 -0
- package/lib/FileManager.js +474 -0
- package/lib/Filtering.d.ts +15 -0
- package/lib/Filtering.d.ts.map +1 -0
- package/lib/Filtering.js +299 -0
- package/lib/PostgresNotifListenManager.d.ts +27 -0
- package/lib/PostgresNotifListenManager.d.ts.map +1 -0
- package/lib/PostgresNotifListenManager.js +122 -0
- package/lib/Prostgles.d.ts +193 -0
- package/lib/Prostgles.d.ts.map +1 -0
- package/lib/Prostgles.js +579 -0
- package/lib/Prostgles.ts +6 -6
- package/lib/PubSubManager.d.ts +157 -0
- package/lib/PubSubManager.d.ts.map +1 -0
- package/lib/PubSubManager.js +1400 -0
- package/lib/PublishParser.d.ts +262 -0
- package/lib/PublishParser.d.ts.map +1 -0
- package/lib/PublishParser.js +390 -0
- package/lib/PublishParser.ts +39 -38
- package/lib/QueryBuilder.d.ts +124 -0
- package/lib/QueryBuilder.d.ts.map +1 -0
- package/lib/QueryBuilder.js +1349 -0
- package/lib/SyncReplication.d.ts +34 -0
- package/lib/SyncReplication.d.ts.map +1 -0
- package/lib/SyncReplication.js +411 -0
- package/lib/TableConfig.d.ts +175 -0
- package/lib/TableConfig.d.ts.map +1 -0
- package/lib/TableConfig.js +231 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +45 -0
- package/lib/index.ts +3 -4
- package/lib/shortestPath.d.ts +10 -0
- package/lib/shortestPath.d.ts.map +1 -0
- package/lib/shortestPath.js +111 -0
- package/lib/utils.d.ts +2 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +5 -0
- package/package.json +3 -3
- package/tests/client/PID.txt +1 -1
- package/tests/client/index.d.ts +1 -1
- package/tests/client/index.d.ts.map +1 -1
- package/tests/client_only_queries.d.ts +4 -0
- package/tests/client_only_queries.d.ts.map +1 -0
- package/tests/isomorphic_queries.d.ts +6 -0
- package/tests/isomorphic_queries.d.ts.map +1 -0
- package/tests/server/DBoGenerated.d.ts +97 -193
- package/tests/server/dboTypeCheck.d.ts +2 -0
- package/tests/server/dboTypeCheck.d.ts.map +1 -0
- package/tests/server/dboTypeCheck.js +14 -0
- package/tests/server/dboTypeCheck.ts +17 -0
- package/tests/server/index.d.ts +2 -0
- package/tests/server/index.d.ts.map +1 -0
- package/tests/server/index.js +11 -11
- package/tests/server/index.ts +23 -16
- package/tests/server/package-lock.json +5 -5
- package/tests/server/publishTypeCheck.d.ts +2 -0
- package/tests/server/publishTypeCheck.d.ts.map +1 -0
- package/tests/server/publishTypeCheck.js +120 -0
- package/tests/server/publishTypeCheck.ts +129 -0
- package/tests/server/tsconfig.json +4 -5
- package/tests/server_only_queries.d.ts +2 -0
- package/tests/server_only_queries.d.ts.map +1 -0
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.asSQLIdentifier = void 0;
|
|
27
|
+
const aws_sdk_1 = require("aws-sdk");
|
|
28
|
+
const fs = __importStar(require("fs"));
|
|
29
|
+
const FileType = __importStar(require("file-type"));
|
|
30
|
+
const sharp = __importStar(require("sharp"));
|
|
31
|
+
const prostgles_types_1 = require("prostgles-types");
|
|
32
|
+
const HOUR = 3600 * 1000;
|
|
33
|
+
const asSQLIdentifier = async (name, db) => {
|
|
34
|
+
return (await db.one("select format('%I', $1) as name", [name]))?.name;
|
|
35
|
+
};
|
|
36
|
+
exports.asSQLIdentifier = asSQLIdentifier;
|
|
37
|
+
class FileManager {
|
|
38
|
+
constructor(config, imageOptions) {
|
|
39
|
+
this.uploadAsMedia = async (params) => {
|
|
40
|
+
const { item, imageOptions } = params;
|
|
41
|
+
const { name, data, content_type } = item;
|
|
42
|
+
if (!data)
|
|
43
|
+
throw "No file provided";
|
|
44
|
+
if (!name || typeof name !== "string")
|
|
45
|
+
throw "Expecting a string name";
|
|
46
|
+
// const type = await this.getMIME(data, name, allowedExtensions, dissallowedExtensions);
|
|
47
|
+
let _data = data;
|
|
48
|
+
if (content_type.startsWith("image")) {
|
|
49
|
+
const compression = imageOptions?.compression;
|
|
50
|
+
if (compression) {
|
|
51
|
+
console.log("Resizing image");
|
|
52
|
+
let opts;
|
|
53
|
+
if ("contain" in compression) {
|
|
54
|
+
opts = {
|
|
55
|
+
fit: sharp.fit.contain,
|
|
56
|
+
...compression.contain
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
else if ("inside" in compression) {
|
|
60
|
+
opts = {
|
|
61
|
+
fit: sharp.fit.inside,
|
|
62
|
+
...compression.inside
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
_data = await sharp(data)
|
|
66
|
+
.resize(opts)
|
|
67
|
+
.withMetadata(Boolean(imageOptions?.keepMetadata))
|
|
68
|
+
// .jpeg({ quality: 80 })
|
|
69
|
+
.toBuffer();
|
|
70
|
+
}
|
|
71
|
+
else if (!imageOptions?.keepMetadata) {
|
|
72
|
+
/**
|
|
73
|
+
* Remove exif
|
|
74
|
+
*/
|
|
75
|
+
_data = await sharp(data)
|
|
76
|
+
.clone()
|
|
77
|
+
.toBuffer();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const res = await this.upload(_data, name, content_type);
|
|
81
|
+
return res;
|
|
82
|
+
};
|
|
83
|
+
this.parseSQLIdentifier = async (name) => (0, exports.asSQLIdentifier)(name, this.prostgles.db); // this.prostgles.dbo.sql<"value">("select format('%I', $1)", [name], { returnType: "value" } )
|
|
84
|
+
this.init = async (prg) => {
|
|
85
|
+
this.prostgles = prg;
|
|
86
|
+
// const { dbo, db, opts } = prg;
|
|
87
|
+
const { fileTable } = prg.opts;
|
|
88
|
+
if (!fileTable)
|
|
89
|
+
throw "fileTable missing";
|
|
90
|
+
const { tableName = "media", referencedTables = {} } = fileTable;
|
|
91
|
+
this.tableName = tableName;
|
|
92
|
+
const maxBfSizeMB = prg.opts.io?.engine?.opts?.maxHttpBufferSize / 1e6;
|
|
93
|
+
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`);
|
|
94
|
+
// throw "Why are constraints dissapearing?"
|
|
95
|
+
/**
|
|
96
|
+
* 1. Create media table
|
|
97
|
+
*/
|
|
98
|
+
if (!this.dbo[tableName]) {
|
|
99
|
+
console.log(`Creating fileTable ${(0, prostgles_types_1.asName)(tableName)} ...`);
|
|
100
|
+
await this.db.any(`CREATE EXTENSION IF NOT EXISTS pgcrypto `);
|
|
101
|
+
await this.db.any(`CREATE TABLE IF NOT EXISTS ${(0, prostgles_types_1.asName)(tableName)} (
|
|
102
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
103
|
+
name TEXT NOT NULL,
|
|
104
|
+
extension TEXT NOT NULL,
|
|
105
|
+
content_type TEXT NOT NULL,
|
|
106
|
+
url TEXT NOT NULL,
|
|
107
|
+
original_name TEXT NOT NULL,
|
|
108
|
+
|
|
109
|
+
description TEXT,
|
|
110
|
+
s3_url TEXT,
|
|
111
|
+
signed_url TEXT,
|
|
112
|
+
signed_url_expires BIGINT,
|
|
113
|
+
etag TEXT,
|
|
114
|
+
UNIQUE(name)
|
|
115
|
+
)`);
|
|
116
|
+
console.log(`Created fileTable ${(0, prostgles_types_1.asName)(tableName)}`);
|
|
117
|
+
await prg.refreshDBO();
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 2. Create media lookup tables
|
|
121
|
+
*/
|
|
122
|
+
await Promise.all(Object.keys(referencedTables).map(async (refTable) => {
|
|
123
|
+
if (!this.dbo[refTable])
|
|
124
|
+
throw `Referenced table (${refTable}) from fileTable.referencedTables record is missing`;
|
|
125
|
+
// const lookupTableName = asName(`lookup_${tableName}_${refTable}`);
|
|
126
|
+
const lookupTableName = await this.parseSQLIdentifier(`prostgles_lookup_${tableName}_${refTable}`);
|
|
127
|
+
const pKeyFields = (await this.dbo[refTable].getColumns()).filter(f => f.is_pkey);
|
|
128
|
+
if (pKeyFields.length !== 1)
|
|
129
|
+
throw `Could not make link table for ${refTable}. ${pKeyFields} must have exactly one primary key column. Current pkeys: ${pKeyFields.map(f => f.name)}`;
|
|
130
|
+
const pkField = pKeyFields[0];
|
|
131
|
+
const refType = referencedTables[refTable];
|
|
132
|
+
if (!this.dbo[lookupTableName]) {
|
|
133
|
+
// if(!(await dbo[lookupTableName].count())) await db.any(`DROP TABLE IF EXISTS ${lookupTableName};`);
|
|
134
|
+
const action = ` (${tableName} <-> ${refTable}) join table ${lookupTableName}`; // PRIMARY KEY
|
|
135
|
+
const query = `
|
|
136
|
+
CREATE TABLE ${lookupTableName} (
|
|
137
|
+
foreign_id ${pkField.udt_name} ${refType === "one" ? " PRIMARY KEY " : ""} REFERENCES ${(0, prostgles_types_1.asName)(refTable)}(${(0, prostgles_types_1.asName)(pkField.name)}),
|
|
138
|
+
media_id UUID NOT NULL REFERENCES ${(0, prostgles_types_1.asName)(tableName)}(id)
|
|
139
|
+
)
|
|
140
|
+
`;
|
|
141
|
+
console.log(`Creating ${action} ...`, lookupTableName);
|
|
142
|
+
await this.db.any(query);
|
|
143
|
+
console.log(`Created ${action}`);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
const cols = await this.dbo[lookupTableName].getColumns();
|
|
147
|
+
const badCols = cols.filter(c => !c.references);
|
|
148
|
+
await Promise.all(badCols.map(async (badCol) => {
|
|
149
|
+
console.error(`Prostgles: media ${lookupTableName} joining table has lost a reference constraint for column ${badCol.name}.` +
|
|
150
|
+
` This may have been caused by a DROP TABLE ... CASCADE.`);
|
|
151
|
+
let q = `
|
|
152
|
+
ALTER TABLE ${(0, prostgles_types_1.asName)(lookupTableName)}
|
|
153
|
+
ADD CONSTRAINT ${(lookupTableName + "_" + badCol.name + "_r")} FOREIGN KEY (${badCol.name})
|
|
154
|
+
`;
|
|
155
|
+
console.log("Trying to add the missing constraint back");
|
|
156
|
+
if (badCol.name === "foreign_id") {
|
|
157
|
+
q += `REFERENCES ${(0, prostgles_types_1.asName)(refTable)}(${(0, prostgles_types_1.asName)(pkField.name)}) `;
|
|
158
|
+
}
|
|
159
|
+
else if (badCol.name === "media_id") {
|
|
160
|
+
q += `REFERENCES ${(0, prostgles_types_1.asName)(tableName)}(id) `;
|
|
161
|
+
}
|
|
162
|
+
if (q) {
|
|
163
|
+
try {
|
|
164
|
+
await this.db.any(q);
|
|
165
|
+
console.log("Added missing constraint back");
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
console.error("Failed to add missing constraint", e);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
await prg.refreshDBO();
|
|
174
|
+
return true;
|
|
175
|
+
}));
|
|
176
|
+
/**
|
|
177
|
+
* 4. Serve media through express
|
|
178
|
+
*/
|
|
179
|
+
const { fileServeRoute = `/${tableName}`, expressApp: app } = fileTable;
|
|
180
|
+
this.fileRoute = fileServeRoute;
|
|
181
|
+
if (app) {
|
|
182
|
+
app.get(this.fileRoute + "/:name", async (req, res) => {
|
|
183
|
+
if (!this.dbo[tableName]) {
|
|
184
|
+
res.status(500).json({ err: `Internal error: media table (${tableName}) not valid` });
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
const mediaTable = this.dbo[tableName];
|
|
188
|
+
try {
|
|
189
|
+
const { name } = req.params;
|
|
190
|
+
if (typeof name !== "string" || !name)
|
|
191
|
+
throw "Invalid media name";
|
|
192
|
+
const media = await mediaTable.findOne({ name }, { select: { id: 1, name: 1, signed_url: 1, signed_url_expires: 1, content_type: 1 } }, { httpReq: req });
|
|
193
|
+
if (!media) {
|
|
194
|
+
/**
|
|
195
|
+
* Redirect to login !??
|
|
196
|
+
*/
|
|
197
|
+
// const mediaExists = await mediaTable.count({ name });
|
|
198
|
+
// if(mediaExists && this.prostgles.authHandler){
|
|
199
|
+
// } else {
|
|
200
|
+
// throw "Invalid media";
|
|
201
|
+
// }
|
|
202
|
+
throw "Invalid media";
|
|
203
|
+
}
|
|
204
|
+
if (this.s3Client) {
|
|
205
|
+
let url = media.signed_url;
|
|
206
|
+
const expires = +(media.signed_url_expires || 0);
|
|
207
|
+
const EXPIRES = Date.now() + HOUR;
|
|
208
|
+
if (!url || expires < EXPIRES) {
|
|
209
|
+
url = await this.getFileURL(media.name, 60 * 60);
|
|
210
|
+
await mediaTable.update({ name }, { signed_url: url, signed_url_expires: EXPIRES });
|
|
211
|
+
}
|
|
212
|
+
res.redirect(url);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
const pth = `${this.config.localFolderPath}/${media.name}`;
|
|
216
|
+
res.contentType(media.content_type);
|
|
217
|
+
res.sendFile(pth);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
catch (e) {
|
|
221
|
+
console.log(e);
|
|
222
|
+
res.status(404).json({ err: "Invalid/missing media" });
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
this.config = config;
|
|
228
|
+
this.imageOptions = imageOptions;
|
|
229
|
+
if ("region" in config) {
|
|
230
|
+
const { region, accessKeyId, secretAccessKey } = config;
|
|
231
|
+
this.s3Client = new aws_sdk_1.S3({
|
|
232
|
+
region,
|
|
233
|
+
credentials: { accessKeyId, secretAccessKey },
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
get dbo() {
|
|
238
|
+
if (!this.prostgles?.dbo)
|
|
239
|
+
throw "this.prostgles.dbo missing";
|
|
240
|
+
return this.prostgles.dbo;
|
|
241
|
+
}
|
|
242
|
+
;
|
|
243
|
+
get db() {
|
|
244
|
+
if (!this.prostgles?.db)
|
|
245
|
+
throw "this.prostgles.db missing";
|
|
246
|
+
return this.prostgles.db;
|
|
247
|
+
}
|
|
248
|
+
;
|
|
249
|
+
async getMIME(file, fileName, allowedExtensions, dissallowedExtensions, onlyFromName = true) {
|
|
250
|
+
const nameParts = fileName.split(".");
|
|
251
|
+
const nameExt = nameParts[nameParts.length - 1].toLowerCase(), mime = (0, prostgles_types_1.getKeys)(CONTENT_TYPE_TO_EXT).find(k => CONTENT_TYPE_TO_EXT[k].includes(nameExt));
|
|
252
|
+
let type = {
|
|
253
|
+
fileName,
|
|
254
|
+
mime,
|
|
255
|
+
ext: nameExt,
|
|
256
|
+
};
|
|
257
|
+
if (onlyFromName && !mime)
|
|
258
|
+
throw `Invalid file extension: content_type could not be found for extension(${nameExt})`;
|
|
259
|
+
if (!mime) {
|
|
260
|
+
/* Set correct/missing extension */
|
|
261
|
+
if (["xml", "txt", "csv", "tsv", "doc"].includes(nameExt)) {
|
|
262
|
+
type = { ...type, mime: ("text/" + nameExt), ext: nameExt };
|
|
263
|
+
}
|
|
264
|
+
else if (["svg"].includes(nameExt)) {
|
|
265
|
+
type = { ...type, mime: "image/svg+xml", ext: nameExt };
|
|
266
|
+
}
|
|
267
|
+
else if (Buffer.isBuffer(file)) {
|
|
268
|
+
const res = await FileType.fromBuffer(file);
|
|
269
|
+
type = {
|
|
270
|
+
...res,
|
|
271
|
+
fileName,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
else if (typeof file === "string") {
|
|
275
|
+
const res = await FileType.fromFile(file);
|
|
276
|
+
type = {
|
|
277
|
+
...res,
|
|
278
|
+
fileName,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
throw "Unexpected file. Expecting: Buffer | String";
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (allowedExtensions &&
|
|
286
|
+
!allowedExtensions.map(v => v.toLowerCase())?.includes(type.ext)) {
|
|
287
|
+
throw fileName + " -> File type ( " + type.ext + " ) not allowed. Expecting one of: " + allowedExtensions.map(v => v.toLowerCase()).join(", ");
|
|
288
|
+
}
|
|
289
|
+
else if (dissallowedExtensions &&
|
|
290
|
+
dissallowedExtensions.map(v => v.toLowerCase())?.includes(type.ext)) {
|
|
291
|
+
throw fileName + " -> File type ( " + type.ext + " ) not allowed";
|
|
292
|
+
}
|
|
293
|
+
if (!onlyFromName) {
|
|
294
|
+
let { ext } = type;
|
|
295
|
+
if (nameExt !== ext)
|
|
296
|
+
fileName = nameParts.slice(0, -1).join('') + "." + ext;
|
|
297
|
+
}
|
|
298
|
+
const res = {
|
|
299
|
+
...type,
|
|
300
|
+
fileName
|
|
301
|
+
};
|
|
302
|
+
if (!res.mime)
|
|
303
|
+
throw "Could not find mime";
|
|
304
|
+
return res;
|
|
305
|
+
}
|
|
306
|
+
// async getUploadURL(fileName: string): Promise<string> {
|
|
307
|
+
// const thisHour = new Date();
|
|
308
|
+
// thisHour.setMilliseconds(0);
|
|
309
|
+
// thisHour.setSeconds(0);
|
|
310
|
+
// thisHour.setMinutes(0);
|
|
311
|
+
// const now = Date.now();
|
|
312
|
+
// const HOUR = 60 * 60;
|
|
313
|
+
// const params = {
|
|
314
|
+
// Bucket: this.config.bucket,
|
|
315
|
+
// Key: fileName,
|
|
316
|
+
// Expires: Math.round(((now - (+thisHour))/1000 + 2 * HOUR )), // one hour
|
|
317
|
+
// ACL: "bucket-owner-full-control",
|
|
318
|
+
// ContentType: "image/png",
|
|
319
|
+
// };
|
|
320
|
+
// return await this.s3Client.getSignedUrlPromise("putObject", params)
|
|
321
|
+
// }
|
|
322
|
+
async upload(file, name, mime) {
|
|
323
|
+
return new Promise(async (resolve, reject) => {
|
|
324
|
+
if (!file) {
|
|
325
|
+
throw "No file. Expecting: Buffer | String";
|
|
326
|
+
}
|
|
327
|
+
if (!name) {
|
|
328
|
+
throw "No name. Expecting: String";
|
|
329
|
+
}
|
|
330
|
+
// let type = await this.getMIME(file, name, allowedExtensions);
|
|
331
|
+
const url = `${this.fileRoute}/${name}`;
|
|
332
|
+
if (!this.s3Client) {
|
|
333
|
+
const config = this.config;
|
|
334
|
+
try {
|
|
335
|
+
await fs.promises.mkdir(config.localFolderPath, { recursive: true });
|
|
336
|
+
fs.writeFileSync(`${config.localFolderPath}/${name}`, file);
|
|
337
|
+
resolve({
|
|
338
|
+
url,
|
|
339
|
+
etag: `none`,
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
catch (err) {
|
|
343
|
+
console.error("Error saving file locally", err);
|
|
344
|
+
reject("Internal error");
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
/* S3 Upload */
|
|
349
|
+
// ACL: "public-read",
|
|
350
|
+
/* ACL needs this permission:
|
|
351
|
+
"s3:PutObject",
|
|
352
|
+
"s3:PutObjectAcl",
|
|
353
|
+
"s3:GetObject",
|
|
354
|
+
"s3:GetObjectAcl",
|
|
355
|
+
*/
|
|
356
|
+
const params = {
|
|
357
|
+
Bucket: this.config.bucket,
|
|
358
|
+
Key: name,
|
|
359
|
+
ContentType: mime,
|
|
360
|
+
Body: file
|
|
361
|
+
};
|
|
362
|
+
this.s3Client.upload(params, (err, res) => {
|
|
363
|
+
if (err) {
|
|
364
|
+
reject("Something went wrong");
|
|
365
|
+
console.error(err);
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
// console.log("Uploaded file:", res)
|
|
369
|
+
resolve({
|
|
370
|
+
url,
|
|
371
|
+
etag: res.ETag,
|
|
372
|
+
s3_url: res.Location,
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
async getFileURL(fileName, expiresInSeconds = 30 * 60) {
|
|
380
|
+
const params = {
|
|
381
|
+
Bucket: this.config.bucket,
|
|
382
|
+
Key: fileName,
|
|
383
|
+
Expires: expiresInSeconds || 30 * 60
|
|
384
|
+
};
|
|
385
|
+
return await this.s3Client?.getSignedUrlPromise("getObject", params);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
exports.default = FileManager;
|
|
389
|
+
const CONTENT_TYPE_TO_EXT = {
|
|
390
|
+
"text/html": ["html", "htm", "shtml"],
|
|
391
|
+
"text/css": ["css"],
|
|
392
|
+
"text/xml": ["xml"],
|
|
393
|
+
"text/mathml": ["mml"],
|
|
394
|
+
"text/plain": ["txt"],
|
|
395
|
+
"text/vnd.sun.j2me.app-descriptor": ["jad"],
|
|
396
|
+
"text/vnd.wap.wml": ["wml"],
|
|
397
|
+
"text/x-component": ["htc"],
|
|
398
|
+
"image/gif": ["gif"],
|
|
399
|
+
"image/jpeg": ["jpeg", "jpg"],
|
|
400
|
+
"image/png": ["png"],
|
|
401
|
+
"image/tiff": ["tif", "tiff"],
|
|
402
|
+
"image/vnd.wap.wbmp": ["wbmp"],
|
|
403
|
+
"image/x-icon": ["ico"],
|
|
404
|
+
"image/x-jng": ["jng"],
|
|
405
|
+
"image/x-ms-bmp": ["bmp"],
|
|
406
|
+
"image/svg+xml": ["svg"],
|
|
407
|
+
"image/webp": ["webp"],
|
|
408
|
+
"application/x-javascript": ["js"],
|
|
409
|
+
"application/atom+xml": ["atom"],
|
|
410
|
+
"application/rss+xml": ["rss"],
|
|
411
|
+
"application/java-archive": ["jar", "war", "ear"],
|
|
412
|
+
"application/mac-binhex40": ["hqx"],
|
|
413
|
+
"application/msword": ["doc", "docx"],
|
|
414
|
+
"application/pdf": ["pdf"],
|
|
415
|
+
"application/postscript": ["ps", "eps", "ai"],
|
|
416
|
+
"application/rtf": ["rtf"],
|
|
417
|
+
"application/vnd.ms-excel": ["xls", "xlsx"],
|
|
418
|
+
"application/vnd.ms-powerpoint": ["ppt", "pptx"],
|
|
419
|
+
"application/vnd.wap.wmlc": ["wmlc"],
|
|
420
|
+
"application/vnd.google-earth.kml+xml": ["kml"],
|
|
421
|
+
"application/vnd.google-earth.kmz": ["kmz"],
|
|
422
|
+
"application/x-7z-compressed": ["7z"],
|
|
423
|
+
"application/x-cocoa": ["cco"],
|
|
424
|
+
"application/x-java-archive-diff": ["jardiff"],
|
|
425
|
+
"application/x-java-jnlp-file": ["jnlp"],
|
|
426
|
+
"application/x-makeself": ["run"],
|
|
427
|
+
"application/x-perl": ["pl", "pm"],
|
|
428
|
+
"application/x-pilot": ["prc", "pdb"],
|
|
429
|
+
"application/x-rar-compressed": ["rar"],
|
|
430
|
+
"application/x-redhat-package-manager": ["rpm"],
|
|
431
|
+
"application/x-sea": ["sea"],
|
|
432
|
+
"application/x-shockwave-flash": ["swf"],
|
|
433
|
+
"application/x-stuffit": ["sit"],
|
|
434
|
+
"application/x-tcl": ["tcl", "tk"],
|
|
435
|
+
"application/x-x509-ca-cert": ["der", "pem", "crt"],
|
|
436
|
+
"application/x-xpinstall": ["xpi"],
|
|
437
|
+
"application/xhtml+xml": ["xhtml"],
|
|
438
|
+
"application/zip": ["zip"],
|
|
439
|
+
"application/octet-stream": ["bin", "exe", "dll", "deb", "dmg", "eot", "iso", "img", "msi", "msp", "msm"],
|
|
440
|
+
"audio/midi": ["mid", "midi", "kar"],
|
|
441
|
+
"audio/mpeg": ["mp3"],
|
|
442
|
+
"audio/ogg": ["ogg"],
|
|
443
|
+
"audio/x-realaudio": ["ra"],
|
|
444
|
+
"video/3gpp": ["3gpp", "3gp"],
|
|
445
|
+
"video/mpeg": ["mpeg", "mpg"],
|
|
446
|
+
"video/quicktime": ["mov"],
|
|
447
|
+
"video/x-flv": ["flv"],
|
|
448
|
+
"video/x-mng": ["mng"],
|
|
449
|
+
"video/x-ms-asf": ["asx", "asf"],
|
|
450
|
+
"video/x-ms-wmv": ["wmv"],
|
|
451
|
+
"video/x-msvideo": ["avi"],
|
|
452
|
+
"video/mp4": ["m4v", "mp4"],
|
|
453
|
+
"video/webm": ["webm"],
|
|
454
|
+
};
|
|
455
|
+
/**
|
|
456
|
+
*
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
// if(content_type && typeof content_type !== "string") throw "Invalid content_type provided";
|
|
460
|
+
// if(title && typeof title !== "string") throw "Invalid title provided";
|
|
461
|
+
// let fExt = name.split(".").pop()
|
|
462
|
+
// if(content_type && name.split(".").length > 1 && fExt && fExt.length <= 4){
|
|
463
|
+
// type = {
|
|
464
|
+
// mime: content_type,
|
|
465
|
+
// ext: fExt,
|
|
466
|
+
// fileName: name,
|
|
467
|
+
// }
|
|
468
|
+
// } else {
|
|
469
|
+
// type = await this.getMIME(data, name);//, ["png", "jpg", "ogg", "webm", "pdf", "doc"]);
|
|
470
|
+
// }
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
*/
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SelectItem } from "./QueryBuilder";
|
|
2
|
+
import { FullFilter } from "prostgles-types";
|
|
3
|
+
/**
|
|
4
|
+
* Parse a single filter
|
|
5
|
+
* Ensure only single key objects reach this point
|
|
6
|
+
*/
|
|
7
|
+
declare type ParseFilterItemArgs = {
|
|
8
|
+
filter: FullFilter;
|
|
9
|
+
select?: SelectItem[];
|
|
10
|
+
tableAlias?: string;
|
|
11
|
+
pgp: any;
|
|
12
|
+
};
|
|
13
|
+
export declare const parseFilterItem: (args: ParseFilterItemArgs) => string;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=Filtering.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Filtering.d.ts","sourceRoot":"","sources":["Filtering.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAoB,UAAU,EAAsG,MAAM,iBAAiB,CAAC;AAGnK;;;EAGE;AACF,aAAK,mBAAmB,GAAG;IAAG,MAAM,EAAE,UAAU,CAAC;IAAC,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,GAAG,CAAA;CAAE,CAAC;AACzG,eAAO,MAAM,eAAe,SAAU,mBAAmB,KAAG,MA0S3D,CAAA"}
|