|
|
@ -63,28 +63,35 @@ export class UploadRoute extends Route {
|
|
|
|
// Uploads a file to the data directory and returns the filename
|
|
|
|
// Uploads a file to the data directory and returns the filename
|
|
|
|
this.router.use(async (req, res) => {
|
|
|
|
this.router.use(async (req, res) => {
|
|
|
|
let uploadConfirmation: IUploadConfirmation;
|
|
|
|
let uploadConfirmation: IUploadConfirmation;
|
|
|
|
if (req.session.userId) {
|
|
|
|
try {
|
|
|
|
if (req.files.profilePicture) {
|
|
|
|
if (req.session.userId) {
|
|
|
|
uploadConfirmation = await this.uploadProfilePicture(req);
|
|
|
|
if (req.files.profilePicture) {
|
|
|
|
} else if (req.files.groupPicture) {
|
|
|
|
uploadConfirmation = await this.uploadProfilePicture(req);
|
|
|
|
uploadConfirmation = await this.uploadGroupPicture(req);
|
|
|
|
} else if (req.files.groupPicture) {
|
|
|
|
} else if (req.files.postMedia) {
|
|
|
|
uploadConfirmation = await this.uploadGroupPicture(req);
|
|
|
|
uploadConfirmation = await this.uploadPostMedia(req);
|
|
|
|
} else if (req.files.postMedia) {
|
|
|
|
|
|
|
|
uploadConfirmation = await this.uploadPostMedia(req);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
res.status(status.BAD_REQUEST);
|
|
|
|
|
|
|
|
uploadConfirmation = {
|
|
|
|
|
|
|
|
error: "You did not provide a (valid) file.",
|
|
|
|
|
|
|
|
success: false,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
res.status(status.BAD_REQUEST);
|
|
|
|
res.status(status.UNAUTHORIZED);
|
|
|
|
uploadConfirmation = {
|
|
|
|
uploadConfirmation = {
|
|
|
|
error: "You did not provide a (valid) file.",
|
|
|
|
error: "You are not logged in.",
|
|
|
|
success: false,
|
|
|
|
success: false,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} catch (err) {
|
|
|
|
res.status(status.UNAUTHORIZED);
|
|
|
|
|
|
|
|
uploadConfirmation = {
|
|
|
|
uploadConfirmation = {
|
|
|
|
error: "You are not logged in.",
|
|
|
|
error: err,
|
|
|
|
success: false,
|
|
|
|
success: false,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (uploadConfirmation.error) {
|
|
|
|
if (uploadConfirmation?.error) {
|
|
|
|
res.status(httpStatus.BAD_REQUEST);
|
|
|
|
res.status(httpStatus.BAD_REQUEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res.json(uploadConfirmation);
|
|
|
|
res.json(uploadConfirmation);
|
|
|
|