Galery nearly finished. only access rights aren't loaded for editin

This commit is contained in:
Torsten Schulz
2024-09-22 20:50:19 +02:00
parent 7ab6939863
commit a2ee66c9de
11 changed files with 555 additions and 57 deletions

View File

@@ -11,6 +11,8 @@ class SocialNetworkController {
this.getImage = this.getImage.bind(this);
this.getImageVisibilityTypes = this.getImageVisibilityTypes.bind(this);
this.getFolderImageList = this.getFolderImageList.bind(this);
this.getImageByHash = this.getImageByHash.bind(this);
this.changeImage = this.changeImage.bind(this);
}
async userSearch(req, res) {
@@ -77,8 +79,9 @@ class SocialNetworkController {
async uploadImage(req, res) {
try {
const userId = req.headers.userid;
const imageData = req.body;
const image = await this.socialNetworkService.uploadImage(userId, imageData);
const file = req.file;
const formData = req.body;
const image = await this.socialNetworkService.uploadImage(userId, file, formData);
res.status(201).json(image);
} catch (error) {
console.error('Error in uploadImage:', error);
@@ -106,6 +109,38 @@ class SocialNetworkController {
res.status(500).json({ error: error.message });
}
}
async getImageByHash(req, res) {
try {
const userId = req.headers.userid;
const { hash } = req.params;
const filePath = await this.socialNetworkService.getImageFilePath(userId, hash);
console.log(filePath);
res.sendFile(filePath, err => {
if (err) {
console.error('Error sending file:', err);
res.status(500).json({ error: 'Error sending file' });
}
});
} catch (error) {
console.error('Error in getImageByHash:', error);
res.status(403).json({ error: error.message || 'Access denied or image not found' });
}
}
async changeImage(req, res) {
try {
const userId = req.headers.userid;
const { imageId } = req.params;
const { title, visibilities } = req.body;
const folderId = await this.socialNetworkService.changeImage(userId, imageId, title, visibilities);
console.log('--->', folderId);
res.status(201).json(await this.socialNetworkService.getFolderImageList(userId, folderId));
} catch (error) {
console.error('Error in getImageByHash:', error);
res.status(403).json({ error: error.message || 'Access denied or image not found' });
}
}
}
export default SocialNetworkController;