mirror of
https://github.com/gnmyt/LicenseAPI.git
synced 2026-01-11 18:51:47 +00:00
Integrate public/private key creation in projects.ts controller
This commit is contained in:
@ -7,6 +7,7 @@ import { License } from "@models/License";
|
|||||||
import {Permission} from "@models/Permission";
|
import {Permission} from "@models/Permission";
|
||||||
import {Group} from "@models/Group";
|
import {Group} from "@models/Group";
|
||||||
import {MetaData} from "@models/MetaData";
|
import {MetaData} from "@models/MetaData";
|
||||||
|
import {generateKeyPair} from "node:crypto";
|
||||||
|
|
||||||
export const checkProjectAccess = (requiredPermission: IKeyRole) => async (userId: string, projectId: string) => {
|
export const checkProjectAccess = (requiredPermission: IKeyRole) => async (userId: string, projectId: string) => {
|
||||||
if (!Types.ObjectId.isValid(projectId))
|
if (!Types.ObjectId.isValid(projectId))
|
||||||
@ -64,10 +65,18 @@ export const getProjectUnsafe = async (projectId: string): Promise<IProject | nu
|
|||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createProject = async (name: string, userId: string) => {
|
export const createProject = (name: string, userId: string) => {
|
||||||
await Project.create({ name, creatorId: userId });
|
return new Promise((resolve, reject) => generateKeyPair('rsa', {
|
||||||
|
modulusLength: 4096, publicKeyEncoding: {type: 'spki', format: 'pem'},
|
||||||
|
privateKeyEncoding: {type: 'pkcs8', format: 'pem'}
|
||||||
|
}, async (err, publicKey, privateKey) => {
|
||||||
|
if (err) return reject({code: 5000, message: "An error occurred while generating the key pair"});
|
||||||
|
|
||||||
return {};
|
await Project.create({name, creatorId: userId, privateKey, publicKey});
|
||||||
|
|
||||||
|
resolve(true);
|
||||||
|
})
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteProject = async (id: string, userId: string) => {
|
export const deleteProject = async (id: string, userId: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user