Galery nearly finished. only access rights aren't loaded for editin
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user