Adjusted my scripts for running and added a new remote to github.
This commit is contained in:
@@ -82,7 +82,7 @@ export async function addProjectFileHandler(req, res) {
|
||||
name: req.file.originalname,
|
||||
file: req.file.buffer,
|
||||
size: req.file.size,
|
||||
mimeType: req.file.mimetype
|
||||
mimeType: req.file.mimetype,
|
||||
};
|
||||
} catch (error) {
|
||||
return res.status(400).json({ error: 'Invalid file data' });
|
||||
@@ -103,9 +103,9 @@ export async function addProjectFileHandler(req, res) {
|
||||
export async function deleteProjectFileHandler(req, res) {
|
||||
try {
|
||||
const fileId = parseInt(req.params.id);
|
||||
|
||||
|
||||
const deletedFile = await deleteProjectFile(fileId, req.user.id);
|
||||
|
||||
|
||||
if (!deletedFile) {
|
||||
return res.status(404).json({ error: 'File not found or unauthorized' });
|
||||
}
|
||||
@@ -129,31 +129,31 @@ export async function downloadProjectFilesHandler(req, res) {
|
||||
|
||||
res.set({
|
||||
'Content-Type': 'application/zip',
|
||||
'Content-Disposition': `attachment; filename="project_${fileId}_files.zip"`
|
||||
'Content-Disposition': `attachment; filename="project_${fileId}_files.zip"`,
|
||||
});
|
||||
|
||||
const archive = archiver('zip', { zlib: { level: 9 } });
|
||||
|
||||
archive.pipe(res);
|
||||
|
||||
files.forEach(f => {
|
||||
|
||||
files.forEach((f) => {
|
||||
const binaryData = f.file;
|
||||
|
||||
if (binaryData) {
|
||||
const bufferData = Buffer.from(binaryData);
|
||||
archive.append(bufferData, { name: f.name });
|
||||
}
|
||||
else {
|
||||
console.error(`ERROR: No binary data found for ${f.name}. Object was:`, f);
|
||||
} else {
|
||||
console.error(
|
||||
`ERROR: No binary data found for ${f.name}. Object was:`,
|
||||
f
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
await archive.finalize();
|
||||
|
||||
} catch (error) {
|
||||
if (!res.headersSent) {
|
||||
res.status(error.status || 500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,8 +195,8 @@ export async function addFile(projectId, userId, fileData) {
|
||||
file: fileData.file,
|
||||
size: fileData.size,
|
||||
mimeType: fileData.mimeType,
|
||||
projectId: projectId
|
||||
}
|
||||
projectId: projectId,
|
||||
},
|
||||
});
|
||||
|
||||
return newFile;
|
||||
@@ -204,12 +204,17 @@ export async function addFile(projectId, userId, fileData) {
|
||||
|
||||
export async function deleteFile(fileId, userId) {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
console.log('projectsRepo.deleteFile() called for fileId:', fileId, 'userId:', userId);
|
||||
console.log(
|
||||
'projectsRepo.deleteFile() called for fileId:',
|
||||
fileId,
|
||||
'userId:',
|
||||
userId
|
||||
);
|
||||
}
|
||||
|
||||
const file = await prisma.file.findUnique({
|
||||
where: { id: fileId },
|
||||
include: { project: true }
|
||||
include: { project: true },
|
||||
});
|
||||
|
||||
if (!file || file.project.userId !== userId) {
|
||||
@@ -236,7 +241,7 @@ export async function getFilesWithContent(projectId, userId) {
|
||||
file: true,
|
||||
size: true,
|
||||
mimeType: true,
|
||||
projectId: true
|
||||
}
|
||||
projectId: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
getProjectFilesHandler,
|
||||
addProjectFileHandler,
|
||||
deleteProjectFileHandler,
|
||||
downloadProjectFilesHandler
|
||||
downloadProjectFilesHandler,
|
||||
} from '../controllers/projectsController.js';
|
||||
import {
|
||||
validateGetAllQuery,
|
||||
@@ -21,9 +21,9 @@ import { authenticate } from '../middleware/authenticate.js';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
const upload = multer({
|
||||
storage: multer.memoryStorage(),
|
||||
limits: { fileSize: 10 * 1024 * 1024 }
|
||||
const upload = multer({
|
||||
storage: multer.memoryStorage(),
|
||||
limits: { fileSize: 10 * 1024 * 1024 },
|
||||
});
|
||||
|
||||
router.use(authenticate);
|
||||
@@ -37,7 +37,12 @@ router.delete('/:id', validateId, deleteProjectHandler);
|
||||
|
||||
// Project File Routes
|
||||
router.get('/:id/files', validateId, getProjectFilesHandler);
|
||||
router.post('/:id/files', validateId, upload.single('file'), addProjectFileHandler);
|
||||
router.post(
|
||||
'/:id/files',
|
||||
validateId,
|
||||
upload.single('file'),
|
||||
addProjectFileHandler
|
||||
);
|
||||
router.delete('/files/:id', validateId, deleteProjectFileHandler);
|
||||
router.get('/:id/files/download', validateId, downloadProjectFilesHandler);
|
||||
|
||||
|
||||
@@ -37,9 +37,9 @@ app.use((req, res, next) => {
|
||||
});
|
||||
|
||||
app.use((err, req, res, next) => {
|
||||
if (err.code === "LIMIT_FILE_SIZE") {
|
||||
return res.status(413).json({
|
||||
error: 'File size cannot exceed 10MB'
|
||||
if (err.code === 'LIMIT_FILE_SIZE') {
|
||||
return res.status(413).json({
|
||||
error: 'File size cannot exceed 10MB',
|
||||
});
|
||||
}
|
||||
console.log(err.stack);
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
getFilesByProjectId,
|
||||
getFilesWithContent,
|
||||
addFile,
|
||||
deleteFile
|
||||
deleteFile,
|
||||
} from '../repositories/projectsRepo.js';
|
||||
|
||||
export async function getAllProjects(userId, options = {}) {
|
||||
@@ -147,7 +147,10 @@ export async function addProjectFile(projectId, userId, fileData) {
|
||||
|
||||
export async function deleteProjectFile(fileId, userId) {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
console.log('projectsService.deleteProjectFile() called for fileId:', fileId);
|
||||
console.log(
|
||||
'projectsService.deleteProjectFile() called for fileId:',
|
||||
fileId
|
||||
);
|
||||
}
|
||||
|
||||
const deletedFile = await deleteFile(fileId, userId);
|
||||
|
||||
Reference in New Issue
Block a user