@ejfdelgado/ejflab-back 1.1.0
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/LICENSE +201 -0
- package/README.md +2 -0
- package/package.json +57 -0
- package/srv/AudIASrv.mjs +218 -0
- package/srv/AuthorizationSrv.mjs +213 -0
- package/srv/ComputeEngineSrv.mjs +289 -0
- package/srv/EmailHandler.mjs +54 -0
- package/srv/Image2MeshSrv.mjs +101 -0
- package/srv/ImagiationSrv.mjs +408 -0
- package/srv/KeysSrv.mjs +104 -0
- package/srv/MainHandler.mjs +140 -0
- package/srv/MainReplacer.mjs +77 -0
- package/srv/MfaSrv.mjs +266 -0
- package/srv/MilvusSrv.mjs +152 -0
- package/srv/MinioSrv.mjs +154 -0
- package/srv/MongoSrv.mjs +320 -0
- package/srv/MyError.mjs +48 -0
- package/srv/MyFileService.mjs +392 -0
- package/srv/MyFileServiceLocal.mjs +177 -0
- package/srv/MyPdf.mjs +37 -0
- package/srv/MyShell.mjs +205 -0
- package/srv/MySqlSrv.mjs +43 -0
- package/srv/Network.mjs +111 -0
- package/srv/OpenCVSrv.mjs +27 -0
- package/srv/PageSrv.mjs +234 -0
- package/srv/PayUSrv.mjs +186 -0
- package/srv/PayUSrvConstants.mjs +46 -0
- package/srv/PostgresSrv.mjs +109 -0
- package/srv/SecretsSrv.mjs +126 -0
- package/srv/SocketIOCall.mjs +494 -0
- package/srv/TupleSrv.mjs +141 -0
- package/srv/UtilesSrv.mjs +8 -0
- package/srv/callprocessors/AskIceServersProcessor.mjs +14 -0
- package/srv/callprocessors/AskRoomProcessor.mjs +15 -0
- package/srv/callprocessors/CallUserProcessor.mjs +17 -0
- package/srv/callprocessors/ChatSetSawProcessor.mjs +42 -0
- package/srv/callprocessors/CheckSrcResponseProcessor.mjs +28 -0
- package/srv/callprocessors/ClientChangeProcessor.mjs +19 -0
- package/srv/callprocessors/CloseVideoChatProcessor.mjs +16 -0
- package/srv/callprocessors/DestroyModelProcessor.mjs +16 -0
- package/srv/callprocessors/DisconnectProcessor.mjs +53 -0
- package/srv/callprocessors/GenericProcessor.mjs +7 -0
- package/srv/callprocessors/GetModelProcessor.mjs +11 -0
- package/srv/callprocessors/IncludeOtherPeersProcessor.mjs +12 -0
- package/srv/callprocessors/LoadFlowChartProcessor.mjs +103 -0
- package/srv/callprocessors/MakeAnswerProcessor.mjs +17 -0
- package/srv/callprocessors/OnIceCandidateProcessor.mjs +13 -0
- package/srv/callprocessors/OpenVideoChatProcessor.mjs +17 -0
- package/srv/callprocessors/PauseFlowChartProcessor.mjs +16 -0
- package/srv/callprocessors/ProcessResponseProcessor.mjs +123 -0
- package/srv/callprocessors/ReadSrcResponseProcessor.mjs +30 -0
- package/srv/callprocessors/RegisterProcessorProcessor.mjs +23 -0
- package/srv/callprocessors/RegisterSourceProcessor.mjs +22 -0
- package/srv/callprocessors/SendChatProcessor.mjs +71 -0
- package/srv/callprocessors/StartFlowChartProcessor.mjs +48 -0
- package/srv/callprocessors/StopFlowChartProcessor.mjs +16 -0
- package/srv/callprocessors/SubscribemeProcessor.mjs +13 -0
- package/srv/callprocessors/UpdateMyInformationProcessor.mjs +30 -0
- package/srv/common/FirebasConfig.mjs +160 -0
- package/srv/common/General.mjs +69 -0
- package/srv/common/MimeTypeMap.mjs +142 -0
- package/srv/common/MyStore.mjs +169 -0
- package/srv/common/Usuario.mjs +101 -0
- package/srv/common/Utilidades.mjs +43 -0
@@ -0,0 +1,71 @@
|
|
1
|
+
import { SimpleObj } from "@ejfdelgado/ejflab-common/src/SimpleObj.js";
|
2
|
+
import { GenericProcessor } from "./GenericProcessor.mjs";
|
3
|
+
|
4
|
+
|
5
|
+
export class SendChatProcessor extends GenericProcessor {
|
6
|
+
MAX_COUNT_TIMESTAMS = 6;
|
7
|
+
constructor(context, io, socket) {
|
8
|
+
super(context, io, socket);
|
9
|
+
}
|
10
|
+
execute(args) {
|
11
|
+
const { text, author, open } = args;
|
12
|
+
const room = this.context.getRoomFromSocket(this.socket);
|
13
|
+
const roomData = this.context.getRoomLiveTupleModel(room);
|
14
|
+
if (!roomData.model.data) {
|
15
|
+
roomData.model.data = {};
|
16
|
+
}
|
17
|
+
if (!roomData.model.data.chat) {
|
18
|
+
roomData.model.data.chat = [];
|
19
|
+
}
|
20
|
+
const now = new Date().getTime();
|
21
|
+
roomData.model.data.chat.push({
|
22
|
+
text,
|
23
|
+
date: now,
|
24
|
+
author: {
|
25
|
+
uid: author,
|
26
|
+
},
|
27
|
+
});
|
28
|
+
let changes = roomData.builder.trackDifferences(roomData.model, [], null, ["data", "data.chat"]);
|
29
|
+
roomData.model = roomData.builder.affect(changes);
|
30
|
+
// Also notify last message time
|
31
|
+
const roomPublicData = this.context.getRoomLiveTupleModel("public");
|
32
|
+
if (roomPublicData.model.data) {
|
33
|
+
const tupleKey = `data.lastmsg.${room}.${author}.arr`;
|
34
|
+
const arr = SimpleObj.getValue(roomPublicData.model, tupleKey, []);
|
35
|
+
arr.push(now);
|
36
|
+
const sobrantes = arr.length - this.MAX_COUNT_TIMESTAMS;
|
37
|
+
if (sobrantes > 0) {
|
38
|
+
arr.splice(0, sobrantes);
|
39
|
+
}
|
40
|
+
SimpleObj.recreate(roomPublicData.model, tupleKey, arr);
|
41
|
+
const changePaths = [
|
42
|
+
"data",
|
43
|
+
"data.lastmsg",
|
44
|
+
`data.lastmsg.${room}`,
|
45
|
+
`data.lastmsg.${room}.${author}`,
|
46
|
+
`data.lastmsg.${room}.${author}.arr`
|
47
|
+
];
|
48
|
+
let changes2 = roomPublicData.builder.trackDifferences(roomPublicData.model, [], null, changePaths);
|
49
|
+
roomPublicData.model = roomPublicData.builder.affect(changes2);
|
50
|
+
|
51
|
+
if (open) {
|
52
|
+
// Get the other id
|
53
|
+
let otherId;
|
54
|
+
if (room.startsWith(author)) {
|
55
|
+
otherId = room.substring(author.length + 1);
|
56
|
+
} else {
|
57
|
+
otherId = room.substring(0, room.length - (author.length + 1));
|
58
|
+
}
|
59
|
+
console.log(`I'm ${author} and other is ${otherId}`);
|
60
|
+
const otherSocket = SimpleObj.getValue(roomPublicData.model, `data.people.${otherId}.socket`, null);
|
61
|
+
if (otherSocket) {
|
62
|
+
this.io.to(otherSocket).emit("openChat", {
|
63
|
+
room,
|
64
|
+
});
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
}
|
71
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { GenericProcessor } from "./GenericProcessor.mjs";
|
2
|
+
|
3
|
+
export class StartFlowChartProcessor extends GenericProcessor {
|
4
|
+
constructor(context, io, socket) {
|
5
|
+
super(context, io, socket);
|
6
|
+
}
|
7
|
+
async execute(args) {
|
8
|
+
let { room } = args;
|
9
|
+
if (!room) {
|
10
|
+
if (this.socket) {
|
11
|
+
room = this.context.getRoomFromSocket(this.socket);
|
12
|
+
} else {
|
13
|
+
room = "public";
|
14
|
+
}
|
15
|
+
}
|
16
|
+
const instance = await this.context.getFlowChartExec(room);
|
17
|
+
if (!instance) {
|
18
|
+
console.log(`No instance for room ${room}`);
|
19
|
+
return;
|
20
|
+
}
|
21
|
+
const roomData = this.context.getRoomLiveTupleModel(room);
|
22
|
+
const now = new Date().getTime();
|
23
|
+
// weird
|
24
|
+
const data1 = instance.getData();
|
25
|
+
roomData.model.data = data1;
|
26
|
+
roomData.model.data.scope.start = now;
|
27
|
+
let changes1 = roomData.builder.trackDifferences(roomData.model, [], null, ["data", "data.scope"]);
|
28
|
+
roomData.model = roomData.builder.affect(changes1);
|
29
|
+
instance.executeIteration(async (status) => {
|
30
|
+
const data = instance.getData();
|
31
|
+
//data['scope'].current = now;
|
32
|
+
roomData.model.data = data;
|
33
|
+
roomData.model.currentNodes = status.currentNodes;
|
34
|
+
roomData.model.history = status.history;
|
35
|
+
|
36
|
+
let changes = roomData.builder.trackDifferences(roomData.model, [], null, ["data", "currentNodes", "history"]);
|
37
|
+
roomData.model = roomData.builder.affect(changes);
|
38
|
+
if (changes.total > 0) {
|
39
|
+
roomData.model.version = roomData.model.version + 1;
|
40
|
+
changes = roomData.builder.trackDifferences(roomData.model, [], null, ["version"]);
|
41
|
+
roomData.model = roomData.builder.affect(changes);
|
42
|
+
}
|
43
|
+
|
44
|
+
}).then(() => {
|
45
|
+
this.io.to(room).emit("flowchartEnd", {});
|
46
|
+
});
|
47
|
+
}
|
48
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { GenericProcessor } from "./GenericProcessor.mjs";
|
2
|
+
|
3
|
+
export class StopFlowChartProcessor extends GenericProcessor {
|
4
|
+
constructor(context, io, socket) {
|
5
|
+
super(context, io, socket);
|
6
|
+
}
|
7
|
+
async execute(args) {
|
8
|
+
const room = this.context.getRoomFromSocket(this.socket);
|
9
|
+
const instance = await this.context.getFlowChartExec(room);
|
10
|
+
if (!instance) {
|
11
|
+
console.log(`No instance to stop`);
|
12
|
+
return;
|
13
|
+
}
|
14
|
+
instance.stop();
|
15
|
+
}
|
16
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { GenericProcessor } from "./GenericProcessor.mjs";
|
2
|
+
|
3
|
+
|
4
|
+
export class SubscribemeProcessor extends GenericProcessor {
|
5
|
+
constructor(context, io, socket) {
|
6
|
+
super(context, io, socket);
|
7
|
+
}
|
8
|
+
execute(args) {
|
9
|
+
const { ref } = args;
|
10
|
+
console.log(`Joining ${this.socket.id} to ${ref}`);
|
11
|
+
this.socket.join(ref);
|
12
|
+
}
|
13
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { GenericProcessor } from "./GenericProcessor.mjs";
|
2
|
+
|
3
|
+
|
4
|
+
export class UpdateMyInformationProcessor extends GenericProcessor {
|
5
|
+
constructor(context, io, socket) {
|
6
|
+
super(context, io, socket);
|
7
|
+
}
|
8
|
+
execute(args) {
|
9
|
+
const { userUID, data } = args;
|
10
|
+
const room = this.context.getRoomFromSocket(this.socket);
|
11
|
+
const roomData = this.context.getRoomLiveTupleModel(room);
|
12
|
+
if (!roomData.model.data) {
|
13
|
+
roomData.model.data = {};
|
14
|
+
}
|
15
|
+
if (!roomData.model.data.people) {
|
16
|
+
roomData.model.data.people = {};
|
17
|
+
}
|
18
|
+
data.socket = this.socket.id;
|
19
|
+
let oldValue = roomData.model.data.people[userUID];
|
20
|
+
if (oldValue) {
|
21
|
+
data.since = oldValue.since;
|
22
|
+
}
|
23
|
+
if (!data.since) {
|
24
|
+
data.since = new Date().getTime();
|
25
|
+
}
|
26
|
+
roomData.model.data.people[userUID] = data;
|
27
|
+
let changes = roomData.builder.trackDifferences(roomData.model, [], null, ["data", "data.people"]);
|
28
|
+
roomData.model = roomData.builder.affect(changes);
|
29
|
+
}
|
30
|
+
}
|
@@ -0,0 +1,160 @@
|
|
1
|
+
import { initializeApp } from 'firebase-admin/app';
|
2
|
+
import { getAuth } from 'firebase-admin/auth';
|
3
|
+
import { MyError } from '../MyError.mjs';
|
4
|
+
import { Usuario } from './Usuario.mjs';
|
5
|
+
import fs from "fs";
|
6
|
+
import { General } from './General.mjs';
|
7
|
+
import { MyConstants } from '@ejfdelgado/ejflab-common/src/MyConstants.js';
|
8
|
+
|
9
|
+
function getFirebaseConfig() {
|
10
|
+
const firebaseJson = fs.readFileSync(MyConstants.FIREBASE_CONFIG_FILE, { encoding: "utf8" });
|
11
|
+
return JSON.parse(firebaseJson);
|
12
|
+
}
|
13
|
+
|
14
|
+
try {
|
15
|
+
initializeApp(getFirebaseConfig());
|
16
|
+
} catch (err) {
|
17
|
+
console.log(err);
|
18
|
+
console.log("Firebase capability not configured");
|
19
|
+
}
|
20
|
+
function getOAuthToken(req) {
|
21
|
+
const authcookie = General.readParam(req, "authcookie")
|
22
|
+
if (authcookie == "1" && "yo" in req.cookies) {
|
23
|
+
let token = req.cookies["yo"];
|
24
|
+
return token;
|
25
|
+
}
|
26
|
+
if ('authentication' in req.headers) {
|
27
|
+
return req.headers.authentication.replace(/bearer\s*/ig, '');
|
28
|
+
}
|
29
|
+
if ('rawHeaders' in req) {
|
30
|
+
const lista = req.rawHeaders;
|
31
|
+
const tamanio = lista.length / 2;
|
32
|
+
for (let i = 0; i < tamanio; i++) {
|
33
|
+
const key = lista[i * 2];
|
34
|
+
const value = lista[i * 2 + 1];
|
35
|
+
//'authorization' es interno!
|
36
|
+
if (['x-forwarded-authorization'].indexOf(key.toLowerCase()) >= 0) {
|
37
|
+
return value.replace(/bearer\s*/ig, '');
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
if ('authorization' in req.headers) {
|
42
|
+
return req.headers.authorization.replace(/bearer\s*/ig, '');
|
43
|
+
}
|
44
|
+
if ('Authorization' in req.headers) {
|
45
|
+
return req.headers.Authorization.replace(/bearer\s*/ig, '');
|
46
|
+
}
|
47
|
+
return null;
|
48
|
+
}
|
49
|
+
|
50
|
+
async function checkAutenticated(req) {
|
51
|
+
const sessionToken = getOAuthToken(req);
|
52
|
+
return new Promise((resolve, reject) => {
|
53
|
+
if (!sessionToken) {
|
54
|
+
reject(new MyError("Missing Authorization header.", 403));
|
55
|
+
return;
|
56
|
+
}
|
57
|
+
getAuth()
|
58
|
+
.verifyIdToken(sessionToken)
|
59
|
+
.then((decodedToken) => {
|
60
|
+
resolve({
|
61
|
+
decodedToken,
|
62
|
+
sessionToken,
|
63
|
+
});
|
64
|
+
})
|
65
|
+
.catch((error) => {
|
66
|
+
reject(new MyError(error.message, 403));
|
67
|
+
});
|
68
|
+
});
|
69
|
+
}
|
70
|
+
|
71
|
+
async function disableUser(uid) {
|
72
|
+
return new Promise((resolve, reject) => {
|
73
|
+
getAuth()
|
74
|
+
.updateUser(uid, { disabled: true, })
|
75
|
+
.then(() => {
|
76
|
+
resolve();
|
77
|
+
})
|
78
|
+
.catch((error) => {
|
79
|
+
reject(new MyError(error.message, 403));
|
80
|
+
});
|
81
|
+
});
|
82
|
+
}
|
83
|
+
|
84
|
+
async function checkAuthenticated(req, res, next) {
|
85
|
+
try {
|
86
|
+
const {
|
87
|
+
decodedToken,
|
88
|
+
sessionToken,
|
89
|
+
} = await checkAutenticated(req);
|
90
|
+
res.locals.token = decodedToken;
|
91
|
+
res.locals.sessionToken = sessionToken;
|
92
|
+
res.locals.user = new Usuario(res.locals.token);
|
93
|
+
await next();
|
94
|
+
} catch (err) {
|
95
|
+
res.status(428).send({ message: err.message });
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
async function checkAuthenticatedSilent(req, res, next) {
|
100
|
+
try {
|
101
|
+
const {
|
102
|
+
decodedToken,
|
103
|
+
sessionToken,
|
104
|
+
} = await checkAutenticated(req);
|
105
|
+
res.locals.token = decodedToken;
|
106
|
+
res.locals.sessionToken = sessionToken;
|
107
|
+
res.locals.user = new Usuario(res.locals.token);
|
108
|
+
await next();
|
109
|
+
} catch (err) {
|
110
|
+
//console.log(err);
|
111
|
+
res.locals.token = null;
|
112
|
+
res.locals.user = null;
|
113
|
+
await next();
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
async function isAdmin(req, res, next) {
|
118
|
+
const fixedAdmins = [
|
119
|
+
"edgar.jose.fernando.delgado@gmail.com",
|
120
|
+
"info@pais.tv",
|
121
|
+
];
|
122
|
+
try {
|
123
|
+
const token = res.locals.token;
|
124
|
+
const estaEnListaAdmins = (fixedAdmins.indexOf(token.email) >= 0);
|
125
|
+
const esDominioPanal = token.email.endsWith("@pais.tv");
|
126
|
+
if (!(esDominioPanal || estaEnListaAdmins)) {
|
127
|
+
res.status(403).send({ message: `Acción no permitida para ${token.email}` });
|
128
|
+
} else {
|
129
|
+
await next();
|
130
|
+
}
|
131
|
+
|
132
|
+
} catch (err) {
|
133
|
+
res.status(428).send({ message: err.message });
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
async function checkVerified(req, res, next) {
|
138
|
+
try {
|
139
|
+
const token = res.locals.token;
|
140
|
+
if (token.email_verified == false) {
|
141
|
+
res.status(424).send({ message: "Para continuar primero debes verificar tu correo" });
|
142
|
+
} else {
|
143
|
+
await next();
|
144
|
+
}
|
145
|
+
|
146
|
+
} catch (err) {
|
147
|
+
res.status(428).send({ message: err.message });
|
148
|
+
}
|
149
|
+
}
|
150
|
+
|
151
|
+
export {
|
152
|
+
getFirebaseConfig,
|
153
|
+
getOAuthToken,
|
154
|
+
checkAutenticated,
|
155
|
+
checkAuthenticated,
|
156
|
+
checkAuthenticatedSilent,
|
157
|
+
checkVerified,
|
158
|
+
isAdmin,
|
159
|
+
disableUser,
|
160
|
+
}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import md5 from 'md5';
|
2
|
+
|
3
|
+
export class General {
|
4
|
+
static readMaxOffset(req, MAX_READ_SIZE) {
|
5
|
+
const offsetR = parseInt(General.readParam(req, "offset"));
|
6
|
+
const maxR = parseInt(General.readParam(req, "max"));
|
7
|
+
let offset = 0;
|
8
|
+
if (!isNaN(offsetR)) {
|
9
|
+
offset = Math.max(0, offsetR);
|
10
|
+
}
|
11
|
+
let max = 0;
|
12
|
+
if (!isNaN(maxR)) {
|
13
|
+
max = Math.min(MAX_READ_SIZE, maxR);
|
14
|
+
}
|
15
|
+
return {
|
16
|
+
max,
|
17
|
+
offset,
|
18
|
+
};
|
19
|
+
}
|
20
|
+
static readParam(req, name, pred = null) {
|
21
|
+
const nameLower = name.toLowerCase();
|
22
|
+
if (req.body && name in req.body) {
|
23
|
+
return req.body[name];
|
24
|
+
} else if (req.query && name in req.query) {
|
25
|
+
return req.query[name];
|
26
|
+
} else if (req.query && nameLower in req.query) {
|
27
|
+
return req.query[nameLower];
|
28
|
+
} else if (req.params && name in req.params) {
|
29
|
+
return req.params[name];
|
30
|
+
} else if (req.locals?.extra) {
|
31
|
+
if (name in req.locals.extra) {
|
32
|
+
return req.locals.extra[name];
|
33
|
+
}
|
34
|
+
}
|
35
|
+
return pred;
|
36
|
+
}
|
37
|
+
static getSuffixPath(keyName, suffix) {
|
38
|
+
const keyNameXs = keyName.replace(/^(.+)\.([^./]+)$/ig, `$1${suffix}.$2`);
|
39
|
+
if (keyNameXs == keyName) {
|
40
|
+
// fallback when no extension
|
41
|
+
return keyName + suffix;
|
42
|
+
}
|
43
|
+
return keyNameXs;
|
44
|
+
}
|
45
|
+
static randomIntFromInterval(min, max) {
|
46
|
+
return Math.floor(Math.random() * (max - min + 1) + min);
|
47
|
+
}
|
48
|
+
static toBase64(texto) {
|
49
|
+
return Buffer.from(texto, 'utf8').toString('base64');
|
50
|
+
}
|
51
|
+
static fromBase64(texto) {
|
52
|
+
return Buffer.from(texto, "base64").toString('utf8');
|
53
|
+
}
|
54
|
+
static getNameParts() {
|
55
|
+
const ahora = new Date();
|
56
|
+
const epochText = ahora.getTime() + "";
|
57
|
+
return {
|
58
|
+
year: ahora.getFullYear(),
|
59
|
+
month: ('0' + (ahora.getMonth() + 1)).slice(-2),
|
60
|
+
day: ('0' + ahora.getDate()).slice(-2),
|
61
|
+
hours: ('0' + ahora.getHours()).slice(-2),
|
62
|
+
minutes: ('0' + ahora.getMinutes()).slice(-2),
|
63
|
+
seconds: ('0' + ahora.getSeconds()).slice(-2),
|
64
|
+
millis: ('00' + ahora.getMilliseconds()).slice(-3),
|
65
|
+
epoch: epochText,
|
66
|
+
hash: md5(epochText),
|
67
|
+
};
|
68
|
+
}
|
69
|
+
}
|
@@ -0,0 +1,142 @@
|
|
1
|
+
export const EXTENSION_MAP = {
|
2
|
+
abs: "audio/x-mpeg",
|
3
|
+
ai: "application/postscript",
|
4
|
+
aif: "audio/x-aiff",
|
5
|
+
aifc: "audio/x-aiff",
|
6
|
+
aiff: "audio/x-aiff",
|
7
|
+
aim: "application/x-aim",
|
8
|
+
art: "image/x-jg",
|
9
|
+
asf: "video/x-ms-asf",
|
10
|
+
asx: "video/x-ms-asf",
|
11
|
+
au: "audio/basic",
|
12
|
+
avi: "video/x-msvideo",
|
13
|
+
avx: "video/x-rad-screenplay",
|
14
|
+
bcpio: "application/x-bcpio",
|
15
|
+
bin: "application/octet-stream",
|
16
|
+
bmp: "image/bmp",
|
17
|
+
body: "text/html",
|
18
|
+
cdf: "application/x-cdf",
|
19
|
+
cer: "application/x-x509-ca-cert",
|
20
|
+
class: "application/java",
|
21
|
+
cpio: "application/x-cpio",
|
22
|
+
csh: "application/x-csh",
|
23
|
+
css: "text/css",
|
24
|
+
dib: "image/bmp",
|
25
|
+
doc: "application/msword",
|
26
|
+
dtd: "text/plain",
|
27
|
+
dv: "video/x-dv",
|
28
|
+
dvi: "application/x-dvi",
|
29
|
+
eps: "application/postscript",
|
30
|
+
etx: "text/x-setext",
|
31
|
+
exe: "application/octet-stream",
|
32
|
+
gif: "image/gif",
|
33
|
+
gtar: "application/x-gtar",
|
34
|
+
gz: "application/x-gzip",
|
35
|
+
hdf: "application/x-hdf",
|
36
|
+
hqx: "application/mac-binhex40",
|
37
|
+
htc: "text/x-component",
|
38
|
+
htm: "text/html",
|
39
|
+
html: "text/html",
|
40
|
+
ief: "image/ief",
|
41
|
+
jad: "text/vnd.sun.j2me.app-descriptor",
|
42
|
+
jar: "application/octet-stream",
|
43
|
+
java: "text/plain",
|
44
|
+
jnlp: "application/x-java-jnlp-file",
|
45
|
+
jpe: "image/jpeg",
|
46
|
+
jpeg: "image/jpeg",
|
47
|
+
jpg: "image/jpeg",
|
48
|
+
js: "text/javascript",
|
49
|
+
kar: "audio/x-midi",
|
50
|
+
latex: "application/x-latex",
|
51
|
+
m3u: "audio/x-mpegurl",
|
52
|
+
mac: "image/x-macpaint",
|
53
|
+
man: "application/x-troff-man",
|
54
|
+
me: "application/x-troff-me",
|
55
|
+
mid: "audio/x-midi",
|
56
|
+
midi: "audio/x-midi",
|
57
|
+
mif: "application/x-mif",
|
58
|
+
mjs: "text/javascript",
|
59
|
+
mov: "video/quicktime",
|
60
|
+
movie: "video/x-sgi-movie",
|
61
|
+
mp1: "audio/x-mpeg",
|
62
|
+
mp2: "audio/x-mpeg",
|
63
|
+
mp3: "audio/x-mpeg",
|
64
|
+
mpa: "audio/x-mpeg",
|
65
|
+
mpe: "video/mpeg",
|
66
|
+
mpeg: "video/mpeg",
|
67
|
+
mpega: "audio/x-mpeg",
|
68
|
+
mpg: "video/mpeg",
|
69
|
+
mpv2: "video/mpeg2",
|
70
|
+
ms: "application/x-wais-source",
|
71
|
+
nc: "application/x-netcdf",
|
72
|
+
oda: "application/oda",
|
73
|
+
pbm: "image/x-portable-bitmap",
|
74
|
+
pct: "image/pict",
|
75
|
+
pdf: "application/pdf",
|
76
|
+
pgm: "image/x-portable-graymap",
|
77
|
+
pic: "image/pict",
|
78
|
+
pict: "image/pict",
|
79
|
+
pls: "audio/x-scpls",
|
80
|
+
png: "image/png",
|
81
|
+
pnm: "image/x-portable-anymap",
|
82
|
+
pnt: "image/x-macpaint",
|
83
|
+
ppm: "image/x-portable-pixmap",
|
84
|
+
ps: "application/postscript",
|
85
|
+
psd: "image/x-photoshop",
|
86
|
+
qt: "video/quicktime",
|
87
|
+
qti: "image/x-quicktime",
|
88
|
+
qtif: "image/x-quicktime",
|
89
|
+
ras: "image/x-cmu-raster",
|
90
|
+
rgb: "image/x-rgb",
|
91
|
+
rm: "application/vnd.rn-realmedia",
|
92
|
+
roff: "application/x-troff",
|
93
|
+
rtf: "application/rtf",
|
94
|
+
rtx: "text/richtext",
|
95
|
+
sh: "application/x-sh",
|
96
|
+
shar: "application/x-shar",
|
97
|
+
smf: "audio/x-midi",
|
98
|
+
snd: "audio/basic",
|
99
|
+
src: "application/x-wais-source",
|
100
|
+
sv4cpio: "application/x-sv4cpio",
|
101
|
+
sv4crc: "application/x-sv4crc",
|
102
|
+
svg: "image/svg+xml",
|
103
|
+
swf: "application/x-shockwave-flash",
|
104
|
+
t: "application/x-troff",
|
105
|
+
tar: "application/x-tar",
|
106
|
+
tcl: "application/x-tcl",
|
107
|
+
tex: "application/x-tex",
|
108
|
+
texi: "application/x-texinfo",
|
109
|
+
texinfo: "application/x-texinfo",
|
110
|
+
tif: "image/tiff",
|
111
|
+
tiff: "image/tiff",
|
112
|
+
tr: "application/x-troff",
|
113
|
+
tsv: "text/tab-separated-values",
|
114
|
+
txt: "text/plain",
|
115
|
+
ulw: "audio/basic",
|
116
|
+
ustar: "application/x-ustar",
|
117
|
+
xbm: "image/x-xbitmap",
|
118
|
+
xpm: "image/x-xpixmap",
|
119
|
+
xwd: "image/x-xwindowdump",
|
120
|
+
wav: "audio/x-wav",
|
121
|
+
wbmp: "image/vnd.wap.wbmp",
|
122
|
+
wml: "text/vnd.wap.wml",
|
123
|
+
wmlc: "application/vnd.wap.wmlc",
|
124
|
+
wmls: "text/vnd.wap.wmlscript",
|
125
|
+
wmlscriptc: "application/vnd.wap.wmlscriptc",
|
126
|
+
wrl: "x-world/x-vrml",
|
127
|
+
Z: "application/x-compress",
|
128
|
+
z: "application/x-compress",
|
129
|
+
zip: "application/zip",
|
130
|
+
};
|
131
|
+
|
132
|
+
export function guessMimeType(path) {
|
133
|
+
const partesExt = /[.]([^/.]+)$/.exec(path);
|
134
|
+
if (partesExt == null) {
|
135
|
+
return "application/octet-stream";
|
136
|
+
}
|
137
|
+
const guessed = EXTENSION_MAP[partesExt[1]];
|
138
|
+
if (guessed != undefined) {
|
139
|
+
return guessed;
|
140
|
+
}
|
141
|
+
return "application/octet-stream";
|
142
|
+
}
|