Initial LinkedSign platform
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
const sendSuccess = (res, data, statusCode = 200) => {
|
||||
return res.status(statusCode).json({
|
||||
success: true,
|
||||
data,
|
||||
error: null,
|
||||
});
|
||||
};
|
||||
|
||||
const sendError = (res, error, statusCode = 400) => {
|
||||
return res.status(statusCode).json({
|
||||
success: false,
|
||||
data: null,
|
||||
error,
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
sendSuccess,
|
||||
sendError,
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
const fs = require('fs/promises');
|
||||
const path = require('path');
|
||||
|
||||
const getUserCertificatePath = async (userId) => {
|
||||
const fullPath = path.resolve(
|
||||
'/home/mgonzalez/desarrollo/react/linkedsign/backend/storage/certificates/users',
|
||||
String(userId)
|
||||
);
|
||||
|
||||
await fs.mkdir(fullPath, { recursive: true });
|
||||
|
||||
return fullPath;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getUserCertificatePath,
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
const jwt = require('jsonwebtoken');
|
||||
const env = require('../config/env');
|
||||
|
||||
const signAccess = (payload) => {
|
||||
return jwt.sign(payload, env.jwt.secret, { expiresIn: env.jwt.accessExpires });
|
||||
};
|
||||
|
||||
const signRefresh = (payload) => {
|
||||
return jwt.sign(payload, env.jwt.secret, { expiresIn: env.jwt.refreshExpires });
|
||||
};
|
||||
|
||||
const verify = (token) => {
|
||||
return jwt.verify(token, env.jwt.secret);
|
||||
};
|
||||
|
||||
module.exports = { signAccess, signRefresh, verify };
|
||||
@@ -0,0 +1,31 @@
|
||||
const toBase64Url = (value) => {
|
||||
return Buffer.from(value)
|
||||
.toString('base64')
|
||||
.replace(/=/g, '')
|
||||
.replace(/\+/g, '-')
|
||||
.replace(/\//g, '_');
|
||||
};
|
||||
|
||||
const createMockJwt = (payload = {}) => {
|
||||
const header = {
|
||||
alg: 'HS256',
|
||||
typ: 'JWT',
|
||||
};
|
||||
|
||||
const body = {
|
||||
sub: payload.email || 'mock-user',
|
||||
role: 'user',
|
||||
iat: Math.floor(Date.now() / 1000),
|
||||
mock: true,
|
||||
};
|
||||
|
||||
return [
|
||||
toBase64Url(JSON.stringify(header)),
|
||||
toBase64Url(JSON.stringify(body)),
|
||||
'mock-signature',
|
||||
].join('.');
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
createMockJwt,
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
const fs = require('fs/promises');
|
||||
const path = require('path');
|
||||
const env = require('../config/env');
|
||||
|
||||
const getDocumentPath = async () => {
|
||||
const now = new Date();
|
||||
const year = String(now.getFullYear());
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const fullPath = path.join(env.storagePath, 'documents', year, month);
|
||||
await fs.mkdir(fullPath, { recursive: true });
|
||||
return fullPath;
|
||||
};
|
||||
|
||||
const getSignedDocumentPath = async () => {
|
||||
const now = new Date();
|
||||
const year = String(now.getFullYear());
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const fullPath = path.join(env.storagePath, 'signed', year, month);
|
||||
await fs.mkdir(fullPath, { recursive: true });
|
||||
return fullPath;
|
||||
};
|
||||
|
||||
const getCertificatePath = async (userId) => {
|
||||
const fullPath = path.join(env.storagePath, 'certificates', String(userId));
|
||||
await fs.mkdir(fullPath, { recursive: true });
|
||||
return fullPath;
|
||||
};
|
||||
|
||||
module.exports = { getDocumentPath, getSignedDocumentPath, getCertificatePath };
|
||||
Reference in New Issue
Block a user