@ozdao/prometheus-framework 0.1.15 → 0.1.17
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/Breadcrumbs.vue_vue_type_style_index_0_lang-579e2c7a.mjs +1945 -0
- package/dist/Breadcrumbs.vue_vue_type_style_index_0_lang-cab2bcd2.js +1 -0
- package/dist/ButtonFollow-23c4d9fc.mjs +132 -0
- package/dist/ButtonFollow-bf5e6d42.js +1 -0
- package/dist/CardOrganization-63dcc83b.js +1 -0
- package/dist/CardOrganization-e530c9d5.mjs +230 -0
- package/dist/Chips-3dac276c.js +1 -0
- package/dist/Feed-4d9001aa.mjs +368 -0
- package/dist/Feed-51eef23f.js +1 -0
- package/dist/Feed-d78d4b91.mjs +439 -0
- package/dist/Feed-f4e9769e.js +1 -0
- package/dist/Gallery-1f82841a.mjs +357 -0
- package/dist/Gallery-dd29c7f6.js +1 -0
- package/dist/Image-a2c2ab9c.js +9 -0
- package/dist/Image-ad6d4f0f.mjs +477 -0
- package/dist/Popup-383abb2e.js +1 -0
- package/dist/Popup-f7a5e86b.mjs +76 -0
- package/dist/Product-b32fb0e1.js +7 -0
- package/dist/Product-d01e3a0d.mjs +839 -0
- package/dist/ProductEdit-2b4d1d88.js +1 -0
- package/dist/ProductEdit-5e479343.mjs +300 -0
- package/dist/ProfileBlogposts-070cb7e9.mjs +65 -0
- package/dist/ProfileBlogposts-b6bf0c42.js +1 -0
- package/dist/ProfileComments-8a0c489c.mjs +44 -0
- package/dist/ProfileComments-f0000ea6.js +1 -0
- package/dist/ProfileEvents-8b88287a.js +1 -0
- package/dist/ProfileEvents-d978617d.mjs +57 -0
- package/dist/ProfileLikes-d5f9f058.js +1 -0
- package/dist/ProfileLikes-f5ad4497.mjs +44 -0
- package/dist/ProfileOrganizations-422d1fa5.js +1 -0
- package/dist/ProfileOrganizations-6b1bc5b2.mjs +213 -0
- package/dist/Publics-640d32fc.mjs +123 -0
- package/dist/Publics-8595ab7e.js +1 -0
- package/dist/Socials-43293869.js +1 -0
- package/dist/Tab-dcd62005.js +1 -0
- package/dist/UploadImage-dfb36cdb.js +1 -0
- package/dist/UploadImage-e4418b43.mjs +83 -0
- package/dist/UploadImageMultiple-c9a7b54f.js +1 -0
- package/dist/UploadImageMultiple-d2d48f39.mjs +58 -0
- package/dist/auth-45a454f2.js +7 -0
- package/dist/auth-5cd34aae.mjs +905 -0
- package/dist/auth.client.cjs +8 -8
- package/dist/auth.client.js +42 -42
- package/dist/auth.validation-4b016fa5.js +1 -0
- package/dist/auth.validation-a52304cf.mjs +20 -0
- package/dist/backoffice.client.cjs +1 -0
- package/dist/backoffice.client.js +69 -0
- package/dist/carousel.es-cdfb392c.js +5 -0
- package/dist/community.client.cjs +1 -1
- package/dist/community.client.js +23 -22
- package/dist/components/EditImages/EditImages.vue.d.ts +7 -0
- package/dist/components/FieldPhone/FieldPhone(script-setup).vue.d.ts +3 -3
- package/dist/components/FieldPhone/FieldPhone.vue.d.ts +1 -1
- package/dist/events.client.cjs +2 -2
- package/dist/events.client.js +17 -16
- package/dist/files.server.js +149 -112
- package/dist/files.server.mjs +149 -112
- package/dist/gallery.server.js +127 -0
- package/dist/gallery.server.mjs +128 -0
- package/dist/index-2059e444.js +2 -0
- package/dist/index-4e469a71.mjs +941 -0
- package/dist/landing.client.cjs +1 -1
- package/dist/modules/gallery/components/sections/Gallery.vue.d.ts +2 -0
- package/dist/modules/icons/navigation/IconChevronRight.vue.d.ts +13 -1
- package/dist/modules/mobile/components/Menu/MenuItem.vue.d.ts +14 -2
- package/dist/organizations-81e762e7.mjs +122 -0
- package/dist/organizations-cf1ab766.js +1 -0
- package/dist/organizations.client-b692a78a.mjs +3018 -0
- package/dist/organizations.client-bdc9b044.js +3 -0
- package/dist/organizations.client.cjs +1 -1
- package/dist/organizations.client.js +44 -43
- package/dist/style.css +1 -1
- package/dist/users.client.cjs +1 -1
- package/dist/users.client.js +224 -184
- package/dist/vue-draggable-next.esm-bundler-21a209c6.js +10 -0
- package/dist/vuex.esm-bundler-685cf29f.js +5 -0
- package/package.json +10 -1
- package/src/components/EditImages/EditImages.vue +55 -0
- package/src/configurator/components/layouts/layoutConfigurator.vue +0 -40
- package/src/modules/auth/components/pages/EnterCode.vue +0 -1
- package/src/modules/backoffice/backoffice.client.js +15 -0
- package/src/modules/backoffice/components/layouts/Account.vue +48 -58
- package/src/modules/backoffice/router/backoffice.js +20 -0
- package/src/modules/files/controllers/files.controller.js +27 -131
- package/src/modules/files/middlewares/server/index.js +10 -0
- package/src/modules/files/middlewares/server/md.js +151 -0
- package/src/modules/files/middlewares/server/middlewareMulter.js +121 -0
- package/src/modules/files/routes/files.routes.js +20 -6
- package/src/modules/gallery/components/sections/Gallery.vue +414 -0
- package/src/modules/gallery/controllers/gallery.controller.js +87 -73
- package/src/modules/gallery/gallery.client.js +17 -0
- package/src/modules/gallery/gallery.server.js +13 -0
- package/src/modules/gallery/models/photo.model.js +20 -14
- package/src/modules/gallery/routes/gallery.routes.js +18 -9
- package/src/modules/gallery/store/gallery.js +25 -19
- package/src/modules/icons/navigation/IconChevronRight.vue +14 -2
- package/src/modules/mobile/components/Menu/Menu.vue +1 -1
- package/src/modules/mobile/components/Menu/MenuItem.vue +8 -2
- package/src/modules/users/components/pages/Profile.vue +22 -1
- package/src/modules/backoffice/components/pages/Profile.vue +0 -109
- package/src/modules/backoffice/components/pages/profile/ProfileEdit.vue +0 -132
@@ -1,151 +1,47 @@
|
|
1
|
-
const multer = require('multer');
|
2
|
-
const path = require('path');
|
3
|
-
const fs = require('fs');
|
4
|
-
|
5
|
-
const createMulterStorage = (folderName, publicPath) => {
|
6
|
-
|
7
|
-
return multer.diskStorage({
|
8
|
-
destination: function (req, file, cb) {
|
9
|
-
let user = {};
|
10
|
-
try {
|
11
|
-
user = JSON.parse(req.cookies.user);
|
12
|
-
} catch (err) {
|
13
|
-
return cb(new Error('Unable to parse user from cookies'));
|
14
|
-
}
|
15
|
-
|
16
|
-
if (!user._id) {
|
17
|
-
return cb(new Error('No user _id found in cookies'));
|
18
|
-
}
|
19
|
-
|
20
|
-
const userUploadPath = path.join(publicPath, 'users', String(user._id), folderName);
|
21
|
-
|
22
|
-
fs.mkdirSync(userUploadPath, { recursive: true });
|
23
|
-
|
24
|
-
cb(null, userUploadPath);
|
25
|
-
},
|
26
|
-
filename: function (req, file, cb) {
|
27
|
-
cb(null, Date.now() + path.extname(file.originalname));
|
28
|
-
}
|
29
|
-
});
|
30
|
-
}
|
31
|
-
|
32
|
-
const createStorage = (folderName, publicPath) => {
|
33
|
-
|
34
|
-
return multer.diskStorage({
|
35
|
-
destination: function (req, file, cb) {
|
36
|
-
let user = {};
|
37
|
-
try {
|
38
|
-
user = JSON.parse(req.cookies.user);
|
39
|
-
} catch (err) {
|
40
|
-
return cb(new Error('Unable to parse user from cookies'));
|
41
|
-
}
|
42
|
-
|
43
|
-
if (!user._id) {
|
44
|
-
return cb(new Error('No user _id found in cookies'));
|
45
|
-
}
|
46
|
-
|
47
|
-
const userUploadPath = path.join(publicPath, folderName);
|
48
|
-
|
49
|
-
fs.mkdirSync(userUploadPath, { recursive: true });
|
50
|
-
|
51
|
-
cb(null, userUploadPath);
|
52
|
-
},
|
53
|
-
filename: function (req, file, cb) {
|
54
|
-
cb(null, Date.now() + path.extname(file.originalname));
|
55
|
-
}
|
56
|
-
});
|
57
|
-
}
|
58
|
-
|
59
1
|
const controllerFactory = (db, publicPath) => {
|
60
|
-
const uploadImageController = async (req, res, next) => {
|
61
|
-
const upload = multer({ storage: createMulterStorage('blog', publicPath) }).single('file');
|
62
|
-
|
63
|
-
console.log(req.file)
|
64
|
-
|
65
|
-
upload(req, res, function(err) {
|
66
|
-
if (err instanceof multer.MulterError) {
|
67
|
-
console.log(err)
|
68
|
-
return res.status(500).json(err);
|
69
|
-
} else if (err) {
|
70
|
-
console.log(err)
|
71
|
-
return res.status(500).json(err);
|
72
|
-
}
|
73
|
-
if (!req.file) {
|
74
|
-
return res.status(400).send({ message: 'No file uploaded.' });
|
75
|
-
}
|
76
|
-
|
77
|
-
const user = JSON.parse(req.cookies.user);
|
78
|
-
|
79
|
-
res.status(200).send({
|
80
|
-
message: 'File uploaded successfully.',
|
81
|
-
filename: req.file.filename,
|
82
|
-
filepath: `/users/${user._id}/blog/${req.file.filename}`
|
83
|
-
});
|
84
|
-
});
|
85
|
-
};
|
86
2
|
|
87
3
|
const uploadFileController = async (req, res, next) => {
|
4
|
+
if (!req.file) {
|
5
|
+
return res.status(400).send({ message: 'No file uploaded.' });
|
6
|
+
}
|
88
7
|
|
89
|
-
|
90
|
-
const upload = multer({ storage: createStorage(folderName, publicPath) }).single('file');
|
91
|
-
|
92
|
-
console.log(folderName)
|
93
|
-
console.log(req.files)
|
94
|
-
|
95
|
-
upload(req, res, function(err) {
|
96
|
-
if (err instanceof multer.MulterError) {
|
97
|
-
console.log(err)
|
98
|
-
return res.status(500).json(err);
|
99
|
-
} else if (err) {
|
100
|
-
console.log(err)
|
101
|
-
return res.status(500).json(err);
|
102
|
-
}
|
103
|
-
if (!req.file) {
|
104
|
-
return res.status(400).send({ message: 'No file uploaded.' });
|
105
|
-
}
|
106
|
-
|
107
|
-
const user = JSON.parse(req.cookies.user);
|
108
|
-
|
8
|
+
try {
|
109
9
|
res.status(200).send({
|
110
10
|
message: 'File uploaded successfully.',
|
111
11
|
filename: req.file.filename,
|
112
|
-
filepath: `/${folderName}/${req.file.filename}`
|
12
|
+
filepath: `/${req.query.folderName || 'unsorted'}/${req.file.filename}`
|
113
13
|
});
|
114
|
-
})
|
14
|
+
} catch (error) {
|
15
|
+
console.error('Error in uploadFileController:', error);
|
16
|
+
return res.status(500).send({ message: 'Error during file processing.' });
|
17
|
+
}
|
115
18
|
};
|
116
19
|
|
117
|
-
const
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
upload(req, res, function(err) {
|
122
|
-
if (err instanceof multer.MulterError) {
|
123
|
-
console.log(err)
|
124
|
-
return res.status(500).json(err);
|
125
|
-
} else if (err) {
|
126
|
-
console.log(err)
|
127
|
-
return res.status(500).json(err);
|
128
|
-
}
|
129
|
-
if (!req.files || req.files.length === 0) {
|
130
|
-
return res.status(400).send({ message: 'No file uploaded.' });
|
131
|
-
}
|
132
|
-
|
133
|
-
const user = JSON.parse(req.cookies.user);
|
20
|
+
const uploadMultipleFileController = async (req, res, next) => {
|
21
|
+
if (!req.files || req.files.length === 0) {
|
22
|
+
return res.status(400).send({ message: 'No files uploaded.' });
|
23
|
+
}
|
134
24
|
|
135
|
-
|
136
|
-
|
25
|
+
try {
|
26
|
+
const fileResponses = req.files.map(file => ({
|
137
27
|
message: 'File uploaded successfully.',
|
138
28
|
filename: file.filename,
|
139
|
-
filepath: `/${folderName}/${file.filename}
|
140
|
-
}))
|
141
|
-
|
29
|
+
filepath: `/${req.query.folderName || 'unsorted'}/${file.filename}`
|
30
|
+
}));
|
31
|
+
|
32
|
+
// Your logic related to the DB or further processing can be here.
|
33
|
+
|
34
|
+
res.status(200).send(fileResponses);
|
35
|
+
} catch (error) {
|
36
|
+
console.error('Error in uploadMultipleFileController:', error);
|
37
|
+
return res.status(500).send({ message: 'Error during files processing.' });
|
38
|
+
}
|
142
39
|
};
|
143
40
|
|
144
41
|
return {
|
145
|
-
uploadImageController,
|
146
42
|
uploadFileController,
|
147
|
-
|
43
|
+
uploadMultipleFileController
|
148
44
|
};
|
149
45
|
};
|
150
46
|
|
151
|
-
module.exports = controllerFactory;
|
47
|
+
module.exports = controllerFactory;
|
@@ -0,0 +1,151 @@
|
|
1
|
+
const multer = require('multer');
|
2
|
+
const path = require('path');
|
3
|
+
const fs = require('fs');
|
4
|
+
|
5
|
+
const createMulterStorage = (folderName, publicPath) => {
|
6
|
+
|
7
|
+
return multer.diskStorage({
|
8
|
+
destination: function (req, file, cb) {
|
9
|
+
let user = {};
|
10
|
+
try {
|
11
|
+
user = JSON.parse(req.cookies.user);
|
12
|
+
} catch (err) {
|
13
|
+
return cb(new Error('Unable to parse user from cookies'));
|
14
|
+
}
|
15
|
+
|
16
|
+
if (!user._id) {
|
17
|
+
return cb(new Error('No user _id found in cookies'));
|
18
|
+
}
|
19
|
+
|
20
|
+
const userUploadPath = path.join(publicPath, 'users', String(user._id), folderName);
|
21
|
+
|
22
|
+
fs.mkdirSync(userUploadPath, { recursive: true });
|
23
|
+
|
24
|
+
cb(null, userUploadPath);
|
25
|
+
},
|
26
|
+
filename: function (req, file, cb) {
|
27
|
+
cb(null, Date.now() + path.extname(file.originalname));
|
28
|
+
}
|
29
|
+
});
|
30
|
+
}
|
31
|
+
|
32
|
+
const createStorage = (folderName, publicPath) => {
|
33
|
+
|
34
|
+
return multer.diskStorage({
|
35
|
+
destination: function (req, file, cb) {
|
36
|
+
let user = {};
|
37
|
+
try {
|
38
|
+
user = JSON.parse(req.cookies.user);
|
39
|
+
} catch (err) {
|
40
|
+
return cb(new Error('Unable to parse user from cookies'));
|
41
|
+
}
|
42
|
+
|
43
|
+
if (!user._id) {
|
44
|
+
return cb(new Error('No user _id found in cookies'));
|
45
|
+
}
|
46
|
+
|
47
|
+
const userUploadPath = path.join(publicPath, folderName);
|
48
|
+
|
49
|
+
fs.mkdirSync(userUploadPath, { recursive: true });
|
50
|
+
|
51
|
+
cb(null, userUploadPath);
|
52
|
+
},
|
53
|
+
filename: function (req, file, cb) {
|
54
|
+
cb(null, Date.now() + path.extname(file.originalname));
|
55
|
+
}
|
56
|
+
});
|
57
|
+
}
|
58
|
+
|
59
|
+
const controllerFactory = (db, publicPath) => {
|
60
|
+
const uploadImageController = async (req, res, next) => {
|
61
|
+
const upload = multer({ storage: createMulterStorage('blog', publicPath) }).single('file');
|
62
|
+
|
63
|
+
console.log(req.file)
|
64
|
+
|
65
|
+
upload(req, res, function(err) {
|
66
|
+
if (err instanceof multer.MulterError) {
|
67
|
+
console.log(err)
|
68
|
+
return res.status(500).json(err);
|
69
|
+
} else if (err) {
|
70
|
+
console.log(err)
|
71
|
+
return res.status(500).json(err);
|
72
|
+
}
|
73
|
+
if (!req.file) {
|
74
|
+
return res.status(400).send({ message: 'No file uploaded.' });
|
75
|
+
}
|
76
|
+
|
77
|
+
const user = JSON.parse(req.cookies.user);
|
78
|
+
|
79
|
+
res.status(200).send({
|
80
|
+
message: 'File uploaded successfully.',
|
81
|
+
filename: req.file.filename,
|
82
|
+
filepath: `/users/${user._id}/blog/${req.file.filename}`
|
83
|
+
});
|
84
|
+
});
|
85
|
+
};
|
86
|
+
|
87
|
+
const uploadFileController = async (req, res, next) => {
|
88
|
+
|
89
|
+
const folderName = req.query.folderName ? req.query.folderName : 'unsorted'; // получаем folderName из параметров запроса
|
90
|
+
const upload = multer({ storage: createStorage(folderName, publicPath) }).single('file');
|
91
|
+
|
92
|
+
console.log(folderName)
|
93
|
+
console.log(req.files)
|
94
|
+
|
95
|
+
upload(req, res, function(err) {
|
96
|
+
if (err instanceof multer.MulterError) {
|
97
|
+
console.log(err)
|
98
|
+
return res.status(500).json(err);
|
99
|
+
} else if (err) {
|
100
|
+
console.log(err)
|
101
|
+
return res.status(500).json(err);
|
102
|
+
}
|
103
|
+
if (!req.file) {
|
104
|
+
return res.status(400).send({ message: 'No file uploaded.' });
|
105
|
+
}
|
106
|
+
|
107
|
+
const user = JSON.parse(req.cookies.user);
|
108
|
+
|
109
|
+
res.status(200).send({
|
110
|
+
message: 'File uploaded successfully.',
|
111
|
+
filename: req.file.filename,
|
112
|
+
filepath: `/${folderName}/${req.file.filename}`
|
113
|
+
});
|
114
|
+
});
|
115
|
+
};
|
116
|
+
|
117
|
+
const uploadMultipleFile = async (req, res, next) => {
|
118
|
+
const folderName = req.query.folderName; // получаем folderName из параметров запроса
|
119
|
+
const upload = multer({ storage: createStorage(folderName) }).array('file');
|
120
|
+
|
121
|
+
upload(req, res, function(err) {
|
122
|
+
if (err instanceof multer.MulterError) {
|
123
|
+
console.log(err)
|
124
|
+
return res.status(500).json(err);
|
125
|
+
} else if (err) {
|
126
|
+
console.log(err)
|
127
|
+
return res.status(500).json(err);
|
128
|
+
}
|
129
|
+
if (!req.files || req.files.length === 0) {
|
130
|
+
return res.status(400).send({ message: 'No file uploaded.' });
|
131
|
+
}
|
132
|
+
|
133
|
+
const user = JSON.parse(req.cookies.user);
|
134
|
+
|
135
|
+
// send back all filenames and paths
|
136
|
+
res.status(200).send(req.files.map(file => ({
|
137
|
+
message: 'File uploaded successfully.',
|
138
|
+
filename: file.filename,
|
139
|
+
filepath: `/${folderName}/${file.filename}`,
|
140
|
+
})));
|
141
|
+
});
|
142
|
+
};
|
143
|
+
|
144
|
+
return {
|
145
|
+
uploadImageController,
|
146
|
+
uploadFileController,
|
147
|
+
uploadMultipleFile
|
148
|
+
};
|
149
|
+
};
|
150
|
+
|
151
|
+
module.exports = controllerFactory;
|
@@ -0,0 +1,121 @@
|
|
1
|
+
// middlewareFactory.js
|
2
|
+
const sharp = require('sharp');
|
3
|
+
const fs = require('fs');
|
4
|
+
const path = require('path');
|
5
|
+
const multer = require('multer');
|
6
|
+
|
7
|
+
const createStorage = (folderName, publicPath) => {
|
8
|
+
console.log(folderName)
|
9
|
+
console.log(publicPath)
|
10
|
+
|
11
|
+
return multer.diskStorage({
|
12
|
+
destination: function (req, file, cb) {
|
13
|
+
let user = {};
|
14
|
+
// try {
|
15
|
+
// user = JSON.parse(req.cookies.user);
|
16
|
+
// } catch (err) {
|
17
|
+
// return cb(new Error('Unable to parse user from cookies'));
|
18
|
+
// }
|
19
|
+
|
20
|
+
// if (!user._id) {
|
21
|
+
// return cb(new Error('No user _id found in cookies'));
|
22
|
+
// }
|
23
|
+
|
24
|
+
const userUploadPath = path.join(publicPath, folderName);
|
25
|
+
|
26
|
+
fs.mkdirSync(userUploadPath, { recursive: true });
|
27
|
+
|
28
|
+
cb(null, userUploadPath);
|
29
|
+
},
|
30
|
+
filename: function (req, file, cb) {
|
31
|
+
cb(null, Date.now() + path.extname(file.originalname));
|
32
|
+
}
|
33
|
+
});
|
34
|
+
}
|
35
|
+
|
36
|
+
const createThumbnail = async (originalPath, thumbnailPath) => {
|
37
|
+
try {
|
38
|
+
await sharp(originalPath)
|
39
|
+
.resize(200)
|
40
|
+
.toFile(thumbnailPath);
|
41
|
+
} catch (error) {
|
42
|
+
console.error("Error creating thumbnail:", error);
|
43
|
+
}
|
44
|
+
};
|
45
|
+
|
46
|
+
|
47
|
+
const middlewareFactory = (db, publicPath) => {
|
48
|
+
const uploadSingleFileMiddleware = async (req, res, next) => {
|
49
|
+
|
50
|
+
const folderName = req.query.folderName ? req.query.folderName : 'unsorted'; // получаем folderName из параметров запроса
|
51
|
+
const upload = multer({ storage: createStorage(folderName, publicPath) }).single('file');
|
52
|
+
console.log(folderName)
|
53
|
+
console.log(publicPath)
|
54
|
+
|
55
|
+
upload(req, res, function(err) {
|
56
|
+
if (err instanceof multer.MulterError) {
|
57
|
+
// A Multer error occurred when uploading.
|
58
|
+
return res.status(500).json(err);
|
59
|
+
} else if (err) {
|
60
|
+
// An unknown error occurred when uploading.
|
61
|
+
return res.status(500).json(err);
|
62
|
+
}
|
63
|
+
next(); // Everything went fine.
|
64
|
+
});
|
65
|
+
}
|
66
|
+
|
67
|
+
const uploadMultipleFilesMiddleware = async (req, res, next) => {
|
68
|
+
|
69
|
+
|
70
|
+
const folderName = req.query.folderName ? req.query.folderName : 'unsorted'; // получаем folderName из параметров запроса
|
71
|
+
const upload = multer({ storage: createStorage(folderName, publicPath) }).array('file');
|
72
|
+
|
73
|
+
upload(req, res, function(err) {
|
74
|
+
if (err instanceof multer.MulterError) {
|
75
|
+
return res.status(500).json(err);
|
76
|
+
} else if (err) {
|
77
|
+
return res.status(500).json(err);
|
78
|
+
}
|
79
|
+
next();
|
80
|
+
});
|
81
|
+
}
|
82
|
+
|
83
|
+
const generatePreviewMiddleware = async (req, res, next) => {
|
84
|
+
if (req.file) { // if a single file is uploaded
|
85
|
+
try {
|
86
|
+
const originalPath = req.file.path;
|
87
|
+
const thumbnailPath = path.join(
|
88
|
+
path.dirname(originalPath),
|
89
|
+
'thumbnail_' + path.basename(originalPath)
|
90
|
+
);
|
91
|
+
await createThumbnail(originalPath, thumbnailPath);
|
92
|
+
} catch (error) {
|
93
|
+
console.error('Error generating preview for single file:', error);
|
94
|
+
}
|
95
|
+
} else if (req.files) { // if multiple files are uploaded
|
96
|
+
try {
|
97
|
+
await Promise.all(req.files.map(async file => {
|
98
|
+
const originalPath = file.path;
|
99
|
+
const thumbnailPath = path.join(
|
100
|
+
path.dirname(originalPath),
|
101
|
+
'thumbnail_' + path.basename(originalPath)
|
102
|
+
);
|
103
|
+
await createThumbnail(originalPath, thumbnailPath);
|
104
|
+
}));
|
105
|
+
} catch (error) {
|
106
|
+
console.error('Error generating previews for multiple files:', error);
|
107
|
+
}
|
108
|
+
}
|
109
|
+
next();
|
110
|
+
};
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
return {
|
115
|
+
uploadSingleFileMiddleware,
|
116
|
+
uploadMultipleFilesMiddleware,
|
117
|
+
generatePreviewMiddleware
|
118
|
+
};
|
119
|
+
};
|
120
|
+
|
121
|
+
module.exports = middlewareFactory;
|
@@ -1,16 +1,19 @@
|
|
1
1
|
// Factories
|
2
2
|
const controllerFactory = require("../controllers/files.controller");
|
3
3
|
// Middlewares
|
4
|
-
const
|
4
|
+
const middlewareFactoryGlobal = require('@pf/src/modules/middlewares/server');
|
5
|
+
const middlewareFactoryFiles = require('../middlewares/server');
|
5
6
|
|
6
7
|
module.exports = function(app, db, origins, publicPath) {
|
7
8
|
const controller = controllerFactory(db, publicPath);
|
8
9
|
|
10
|
+
const { authJwt } = middlewareFactoryGlobal(db);
|
11
|
+
console.log('Public path is ' + publicPath)
|
12
|
+
const { middlewareMulter } = middlewareFactoryFiles(db, publicPath);
|
13
|
+
|
9
14
|
app.use(function(req, res, next) {
|
10
15
|
|
11
16
|
const origin = req.headers.origin;
|
12
|
-
|
13
|
-
console.log(origin)
|
14
17
|
|
15
18
|
if (origins.includes(origin)) {
|
16
19
|
res.setHeader('Access-Control-Allow-Origin', origin);
|
@@ -20,20 +23,31 @@ module.exports = function(app, db, origins, publicPath) {
|
|
20
23
|
|
21
24
|
next();
|
22
25
|
});
|
23
|
-
|
26
|
+
|
24
27
|
app.post(
|
25
28
|
"/api/upload/image",
|
29
|
+
[
|
30
|
+
middlewareMulter.uploadSingleFileMiddleware,
|
31
|
+
middlewareMulter.generatePreviewMiddleware
|
32
|
+
],
|
26
33
|
controller.uploadFileController
|
27
34
|
);
|
28
35
|
|
29
36
|
app.post(
|
30
37
|
"/api/upload/file",
|
38
|
+
[
|
39
|
+
middlewareMulter.uploadSingleFileMiddleware,
|
40
|
+
middlewareMulter.generatePreviewMiddleware
|
41
|
+
],
|
31
42
|
controller.uploadFileController
|
32
43
|
);
|
33
44
|
|
34
45
|
app.post(
|
35
46
|
"/api/upload/multiple",
|
36
|
-
|
47
|
+
[
|
48
|
+
middlewareMulter.uploadMultipleFilesMiddleware,
|
49
|
+
middlewareMulter.generatePreviewMiddleware
|
50
|
+
],
|
51
|
+
controller.uploadMultipleFileController
|
37
52
|
);
|
38
|
-
|
39
53
|
};
|