@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
@@ -0,0 +1,414 @@
|
|
1
|
+
<template>
|
2
|
+
<div class="pos-relative w-100">
|
3
|
+
<!-- <GradientOverlay> -->
|
4
|
+
<div class="w-100 o-hidden">
|
5
|
+
<div class=" pd-medium flex-nowrap flex pd-t-thin pd-b-thin o-scroll">
|
6
|
+
|
7
|
+
<button v-if="isEditablePath" @click="openModal(null)" class="mn-r-small t-white t-black bg-second button-small button">Add photos +</button>
|
8
|
+
<!--
|
9
|
+
<a
|
10
|
+
v-for="category in categories"
|
11
|
+
:key="category"
|
12
|
+
@click="filter(category)"
|
13
|
+
class="h3 uppercase mn-r-big"
|
14
|
+
:class="{ 't-transp': selectedCategory !== category }"
|
15
|
+
>
|
16
|
+
{{ $t('gallery.categories.' + category) }}
|
17
|
+
</a> -->
|
18
|
+
|
19
|
+
</div>
|
20
|
+
</div>
|
21
|
+
<!-- <GradientOverlay/> -->
|
22
|
+
|
23
|
+
<div ref="grid" class="pd-medium cols-4 gap-thin">
|
24
|
+
<!-- :class="['grid-item pd-small', item.size.value, ...item.categories]" -->
|
25
|
+
<div
|
26
|
+
v-for="(item, index) in filteredGallery"
|
27
|
+
:key="item.id"
|
28
|
+
:data-id="item.id"
|
29
|
+
>
|
30
|
+
|
31
|
+
<transition name="scaleIn" mode="in-out">
|
32
|
+
<img
|
33
|
+
v-if="!isEditablePath && grid"
|
34
|
+
:src="'https://thecommunephuket.com/photos/' + item.cover"
|
35
|
+
class="w-100 h-100 o-hidden radius-medium object-fit-cover"
|
36
|
+
@click="openModal(item.image)"
|
37
|
+
/>
|
38
|
+
<div class="pd-small radius-small bg-white" v-else>
|
39
|
+
{{item._id}}
|
40
|
+
<img :src="'https://thecommunephuket.com/photos/' + item.cover" class="w-100 radius-small mn-small h-10r object-fit-cover " @click="openModal(item)" />
|
41
|
+
|
42
|
+
<p class="t-black p-small mn-small">
|
43
|
+
<span class="uppercase t-transp ">Size</span>
|
44
|
+
<br>
|
45
|
+
<span class="pd-2px radius-big d-inline-block bg-grey">{{item.size.name}}</span>
|
46
|
+
</p>
|
47
|
+
|
48
|
+
<p class="t-black p-small mn-small uppe">
|
49
|
+
<span class="uppercase t-transp">Categories</span>
|
50
|
+
<br>
|
51
|
+
<span class="pd-2px radius-big d-inline-block bg-grey t-semi" v-for="category in item.categories">{{category}}</span>
|
52
|
+
</p>
|
53
|
+
|
54
|
+
<div class="flex-nowrap flex">
|
55
|
+
<!-- <button class="mn-r-thin button-small w-100 button" @click="editPhoto(item)">Edit</button> -->
|
56
|
+
<button class="button-small w-100 button" @click="deletePhoto(item._id)">Delete</button>
|
57
|
+
</div>
|
58
|
+
</div>
|
59
|
+
</transition>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<!-- Loader -->
|
63
|
+
<!-- <div v-show="loading" class="loader">Loading...</div> -->
|
64
|
+
<!-- Sentinel -->
|
65
|
+
<div ref="sentinel" class="sentinel"></div>
|
66
|
+
|
67
|
+
<transition name="modal">
|
68
|
+
<div v-show="selectedImage.image !== false && modal === 'modal'" class="modal pd-thin">
|
69
|
+
<div class="modal-content radius-big">
|
70
|
+
<div class="">
|
71
|
+
<span class="close" @click="closeModal">×</span>
|
72
|
+
<img :src="'https://thecommunephuket.com/photos/' + selectedImage.image">
|
73
|
+
</div>
|
74
|
+
</div>
|
75
|
+
</div>
|
76
|
+
</transition>
|
77
|
+
|
78
|
+
<transition name="modal">
|
79
|
+
|
80
|
+
<div v-if="selectedImage.image !== false && modal === 'edit-modal'" class="flex-v-center flex m modal pd-big">
|
81
|
+
<div class="modal-content radius-small pd-medium bg-white">
|
82
|
+
<span class="close" @click="closeModal">×</span>
|
83
|
+
<img v-if="typeof previewImage === 'string'" :src="previewImage" class="radius-small w-100 mn-small h-20r object-fit-cover " />
|
84
|
+
<img v-if="typeof previewImage === 'object' && selectedImage.image !== null" class="radius-small w-100 mn-small h-20r object-fit-cover " :src="'/photos/' + selectedImage.cover">
|
85
|
+
|
86
|
+
|
87
|
+
<Select
|
88
|
+
:options="sizeOptions"
|
89
|
+
label="Size"
|
90
|
+
v-model:select="selectedImage.size"
|
91
|
+
placeholder="Select Size"
|
92
|
+
class="
|
93
|
+
bg-grey
|
94
|
+
pd-thin
|
95
|
+
radius-small
|
96
|
+
mn-thin
|
97
|
+
t-black
|
98
|
+
"
|
99
|
+
/>
|
100
|
+
|
101
|
+
<Field
|
102
|
+
v-model:field="selectedImage.categories"
|
103
|
+
type="text"
|
104
|
+
label="Categories"
|
105
|
+
placeholder="Enter categories for image (comma separated)"
|
106
|
+
class="
|
107
|
+
bg-grey
|
108
|
+
pd-thin
|
109
|
+
radius-small
|
110
|
+
mn-medium
|
111
|
+
t-black
|
112
|
+
"
|
113
|
+
/>
|
114
|
+
|
115
|
+
<EditImages :images="uploadedImages" @update:images="onUpdatedImages" :uploadPath="'photos'" class="mn-semi"/>
|
116
|
+
|
117
|
+
<Button :submit="selectedImage._id ? updatePhoto : createPhoto" :callback="closeModal" class="mn-thin">
|
118
|
+
{{selectedImage._id ? 'Update' : 'Create'}}
|
119
|
+
</Button>
|
120
|
+
</div>
|
121
|
+
</div>
|
122
|
+
</transition>
|
123
|
+
</div>
|
124
|
+
</div>
|
125
|
+
</template>
|
126
|
+
|
127
|
+
<script setup>
|
128
|
+
import { ref, onMounted, reactive, computed } from 'vue'
|
129
|
+
import { Button, Field, Select, Upload } from '@ozdao/prometheus-framework'
|
130
|
+
import { state, actions } from '@pf/src/modules/gallery/store/gallery';
|
131
|
+
|
132
|
+
import EditImages from '@pf/src/components/EditImages/EditImages.vue';
|
133
|
+
|
134
|
+
import { useRoute } from 'vue-router'
|
135
|
+
|
136
|
+
const route = useRoute()
|
137
|
+
|
138
|
+
const isEditablePath = ref(true)
|
139
|
+
|
140
|
+
// Gallery Grid
|
141
|
+
const grid = ref(null)
|
142
|
+
|
143
|
+
const categories = ['all', 'place', 'drinks', 'people', 'events']
|
144
|
+
|
145
|
+
// Pagination
|
146
|
+
let page = 1
|
147
|
+
const limit = 10
|
148
|
+
|
149
|
+
let sentinel = ref(null)
|
150
|
+
let loading = ref(false)
|
151
|
+
|
152
|
+
const uploadedImages = ref([])
|
153
|
+
|
154
|
+
const onUpdatedImages = (newImages) => {
|
155
|
+
uploadedImages.value = newImages
|
156
|
+
}
|
157
|
+
|
158
|
+
const filteredGallery = computed(() => {
|
159
|
+
if (selectedCategory.value === 'all') {
|
160
|
+
return state.gallery
|
161
|
+
} else {
|
162
|
+
return state.gallery.filter(item => item.categories.includes(selectedCategory.value))
|
163
|
+
}
|
164
|
+
})
|
165
|
+
|
166
|
+
const loadMore = async () => {
|
167
|
+
loading.value = true
|
168
|
+
await actions.fetchGallery(page, limit)
|
169
|
+
loading.value = false
|
170
|
+
}
|
171
|
+
|
172
|
+
// Popup
|
173
|
+
const modal = ref(null)
|
174
|
+
// Popup
|
175
|
+
const selectedImage = ref({
|
176
|
+
categories: '',
|
177
|
+
size: '',
|
178
|
+
image: false
|
179
|
+
})
|
180
|
+
|
181
|
+
const previewImage = ref(null)
|
182
|
+
|
183
|
+
const openModal = (image) => {
|
184
|
+
console.log(isEditablePath.value)
|
185
|
+
if(isEditablePath.value) {
|
186
|
+
// Если мы находимся на пути /account/gallery, открываем редактирование
|
187
|
+
openEditModal(image)
|
188
|
+
} else {
|
189
|
+
// В противном случае открываем просмотр
|
190
|
+
modal.value = "modal"
|
191
|
+
selectedImage.value.image = image
|
192
|
+
disableScroll()
|
193
|
+
}
|
194
|
+
}
|
195
|
+
|
196
|
+
const openEditModal = (image) => {
|
197
|
+
modal.value = "edit-modal"
|
198
|
+
selectedImage.value = image || {
|
199
|
+
categories: '',
|
200
|
+
size: '',
|
201
|
+
image: null
|
202
|
+
}
|
203
|
+
disableScroll()
|
204
|
+
}
|
205
|
+
|
206
|
+
const closeModal = () => {
|
207
|
+
selectedImage.value = {
|
208
|
+
categories: '',
|
209
|
+
size: '',
|
210
|
+
image: false
|
211
|
+
}
|
212
|
+
previewImage.value = null;
|
213
|
+
enableScroll()
|
214
|
+
}
|
215
|
+
|
216
|
+
const disableScroll = () => {
|
217
|
+
document.body.style.overflow = 'hidden'
|
218
|
+
document.documentElement.style.overflow = 'hidden'
|
219
|
+
}
|
220
|
+
|
221
|
+
const enableScroll = () => {
|
222
|
+
document.body.style.overflow = ''
|
223
|
+
document.documentElement.style.overflow = ''
|
224
|
+
}
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
const sizeOptions = [
|
229
|
+
{ name: 'Small', value: '' },
|
230
|
+
{ name: 'Regular',value: 'grid-item--width1 grid-item--height1' },
|
231
|
+
{ name: 'Medium', value: 'grid-item--width2 grid-item--height2' },
|
232
|
+
{ name: 'Big', value: 'grid-item--width3 grid-item--height3' },
|
233
|
+
];
|
234
|
+
|
235
|
+
|
236
|
+
const deletePhoto = async (id) => {
|
237
|
+
await actions.deletePhoto(id);
|
238
|
+
};
|
239
|
+
|
240
|
+
const editPhoto = (photo) => {
|
241
|
+
openModal(photo);
|
242
|
+
};
|
243
|
+
|
244
|
+
const updatePhoto = async () => {
|
245
|
+
await actions.updatePhoto(selectedImage.value)
|
246
|
+
closeModal()
|
247
|
+
}
|
248
|
+
|
249
|
+
|
250
|
+
// To handle file input change
|
251
|
+
const onFileChange = (e) => {
|
252
|
+
const files = e.files;
|
253
|
+
selectedImage.value.image = files; // Assign the files array to the image property
|
254
|
+
|
255
|
+
// Show a preview of the first image if multiple files are selected
|
256
|
+
if (files && files.length > 0) {
|
257
|
+
const reader = new FileReader()
|
258
|
+
reader.onload = e => {
|
259
|
+
previewImage.value = e.target.result;
|
260
|
+
}
|
261
|
+
reader.readAsDataURL(files[0]);
|
262
|
+
}
|
263
|
+
}
|
264
|
+
|
265
|
+
// Function to create photo
|
266
|
+
const createPhoto = async (e) => {
|
267
|
+
// Your function body
|
268
|
+
if (uploadedImages.length < 1 || !selectedImage.value.categories || !selectedImage.value.size) {
|
269
|
+
console.error('All fields are required.')
|
270
|
+
return
|
271
|
+
}
|
272
|
+
|
273
|
+
await actions.createPhoto({
|
274
|
+
images: uploadedImages.value,
|
275
|
+
size: selectedImage.value.size,
|
276
|
+
categories: typeof selectedImage.value.categories === 'string' ? selectedImage.value.categories.split(',').map(item => item.trim()) : selectedImage.value.categories
|
277
|
+
})
|
278
|
+
closeModal()
|
279
|
+
}
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
let selectedCategory = ref('all')
|
284
|
+
|
285
|
+
const filter = (category) => {
|
286
|
+
selectedCategory.value = category
|
287
|
+
}
|
288
|
+
|
289
|
+
onMounted(async () => {
|
290
|
+
await actions.fetchGallery(page, limit)
|
291
|
+
|
292
|
+
if (typeof window !== 'undefined') {
|
293
|
+
const observer = new IntersectionObserver(entries => {
|
294
|
+
if (entries.some(entry => entry.isIntersecting)) {
|
295
|
+
page += 1
|
296
|
+
loadMore()
|
297
|
+
}
|
298
|
+
})
|
299
|
+
|
300
|
+
observer.observe(sentinel.value)
|
301
|
+
}
|
302
|
+
})
|
303
|
+
|
304
|
+
</script>
|
305
|
+
|
306
|
+
<style scoped>
|
307
|
+
.grid {
|
308
|
+
width: 100%;
|
309
|
+
}
|
310
|
+
.grid-item {
|
311
|
+
width: 33%;
|
312
|
+
height: 33vh;
|
313
|
+
}
|
314
|
+
|
315
|
+
.grid-item--width1 {
|
316
|
+
width: 50%;
|
317
|
+
}
|
318
|
+
.grid-item--height1 {
|
319
|
+
height: 50vh;
|
320
|
+
}
|
321
|
+
|
322
|
+
.grid-item--width2 {
|
323
|
+
width: 66%;
|
324
|
+
}
|
325
|
+
.grid-item--height2 {
|
326
|
+
height: 66vh;
|
327
|
+
}
|
328
|
+
|
329
|
+
.grid-item--width3 {
|
330
|
+
width: 100%;
|
331
|
+
}
|
332
|
+
.grid-item--height3 {
|
333
|
+
height: 100vh;
|
334
|
+
}
|
335
|
+
|
336
|
+
.modal {
|
337
|
+
position: fixed;
|
338
|
+
z-index: 1;
|
339
|
+
left: 0;
|
340
|
+
top: 0;
|
341
|
+
width: 100%;
|
342
|
+
height: 100%;
|
343
|
+
overflow: auto;
|
344
|
+
background-color: rgba(0,0,0,0.9);
|
345
|
+
z-index: 50;
|
346
|
+
}
|
347
|
+
|
348
|
+
.modal-content {
|
349
|
+
margin: auto;
|
350
|
+
/* display: flex;*/
|
351
|
+
z-index: 5;
|
352
|
+
width: 100%;
|
353
|
+
height: 100%;
|
354
|
+
overflow: scroll;
|
355
|
+
}
|
356
|
+
|
357
|
+
.close {
|
358
|
+
position: fixed;
|
359
|
+
top: 3rem;
|
360
|
+
right: 4rem;
|
361
|
+
|
362
|
+
color: #f1f1f1;
|
363
|
+
font-size: 40px;
|
364
|
+
font-weight: bold;
|
365
|
+
transition: 0.3s;
|
366
|
+
z-index: 10;
|
367
|
+
}
|
368
|
+
|
369
|
+
.close:hover,
|
370
|
+
.close:focus {
|
371
|
+
color: #bbb;
|
372
|
+
text-decoration: none;
|
373
|
+
cursor: pointer;
|
374
|
+
}
|
375
|
+
|
376
|
+
/* Transitions */
|
377
|
+
.modal-enter-active, .modal-leave-active {
|
378
|
+
transition: opacity .5s;
|
379
|
+
}
|
380
|
+
.modal-enter, .modal-leave-to {
|
381
|
+
opacity: 0;
|
382
|
+
}
|
383
|
+
|
384
|
+
@media screen and (max-width: 1024px) {
|
385
|
+
.grid {
|
386
|
+
width: 100%;
|
387
|
+
}
|
388
|
+
.grid-item {
|
389
|
+
width: 50%;
|
390
|
+
height: 25vh;
|
391
|
+
}
|
392
|
+
|
393
|
+
.grid-item--width1 {
|
394
|
+
width: 50%;
|
395
|
+
}
|
396
|
+
.grid-item--height1 {
|
397
|
+
height: 25vh;
|
398
|
+
}
|
399
|
+
|
400
|
+
.grid-item--width2 {
|
401
|
+
width: 100%;
|
402
|
+
}
|
403
|
+
.grid-item--height2 {
|
404
|
+
height: 50vh;
|
405
|
+
}
|
406
|
+
|
407
|
+
.grid-item--width3 {
|
408
|
+
width: 100%;
|
409
|
+
}
|
410
|
+
.grid-item--height3 {
|
411
|
+
height: 50vh;
|
412
|
+
}
|
413
|
+
}
|
414
|
+
</style>
|
@@ -2,98 +2,112 @@
|
|
2
2
|
// DEPENENCY
|
3
3
|
// --------------------------------------------------
|
4
4
|
const path = require('path');
|
5
|
-
const { v4: uuidv4 } = require('uuid');
|
6
|
-
// Multer
|
7
|
-
const multer = require('multer');
|
8
|
-
// Configure multer storage
|
9
|
-
const photosPath = path.join(__dirname, '../../public/photos');
|
10
|
-
|
11
|
-
const storage = multer.diskStorage({
|
12
|
-
destination: function(req, file, cb) {
|
13
|
-
cb(null, photosPath)
|
14
|
-
},
|
15
|
-
filename: function(req, file, cb) {
|
16
|
-
// Generate a 6-digit random number
|
17
|
-
const uniqueSuffix = Math.floor(100000 + Math.random() * 900000);
|
18
|
-
cb(null, file.fieldname + '-' + uniqueSuffix + path.extname(file.originalname));
|
19
|
-
}
|
20
|
-
});
|
21
|
-
const upload = multer({ storage: storage });
|
22
|
-
// --------------------------------------------------
|
23
|
-
// Used models
|
24
|
-
// --------------------------------------------------
|
25
|
-
const db = require("../models");
|
26
|
-
const Photo = db.photo;
|
27
5
|
// --------------------------------------------------
|
28
6
|
// METHODS
|
29
7
|
// --------------------------------------------------
|
30
|
-
|
31
|
-
Photo.
|
32
|
-
|
33
|
-
|
8
|
+
const controllerFactory = (db) => {
|
9
|
+
const Photo = db.photo;
|
10
|
+
|
11
|
+
const read = async (req, res) => {
|
12
|
+
const { page, limit } = req.query;
|
13
|
+
|
14
|
+
console.log(req.query)
|
15
|
+
console.log(req.body)
|
16
|
+
|
17
|
+
let query = Photo.find().sort({$natural: -1});
|
18
|
+
|
19
|
+
if (page) {
|
20
|
+
const skipValue = (parseInt(page) - 1) * (limit ? parseInt(limit) : 10);
|
21
|
+
query = query.skip(skipValue);
|
22
|
+
}
|
23
|
+
|
24
|
+
if (limit) {
|
25
|
+
query = query.limit(parseInt(limit));
|
26
|
+
}
|
27
|
+
|
28
|
+
try {
|
29
|
+
const photos = await query;
|
30
|
+
|
31
|
+
if (!photos.length) {
|
34
32
|
return res.status(404).send({ message: "Photos not found." });
|
35
33
|
}
|
34
|
+
|
36
35
|
res.status(200).send(photos);
|
37
|
-
})
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
}
|
42
|
-
});
|
43
|
-
};
|
36
|
+
} catch (err) {
|
37
|
+
res.status(500).send({ message: err.message || "An error occurred." });
|
38
|
+
}
|
39
|
+
};
|
44
40
|
|
45
|
-
|
46
|
-
upload.single('image'),
|
47
|
-
async (req, res) => {
|
41
|
+
const create = async (req, res) => {
|
48
42
|
try {
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
43
|
+
// Извлечение данных из тела запроса
|
44
|
+
const { categories, size, images } = req.body;
|
45
|
+
|
46
|
+
// Проверка, что все необходимые данные предоставлены
|
47
|
+
if (!categories || !size || !images || images.length === 0) {
|
48
|
+
return res.status(400).send({ message: "All fields are required." });
|
53
49
|
}
|
54
50
|
|
55
|
-
|
51
|
+
// Проход по всем изображениям и их создание
|
52
|
+
const photos = [];
|
56
53
|
|
57
|
-
|
58
|
-
|
54
|
+
for (let imageLink of images) {
|
55
|
+
const newPhoto = {
|
56
|
+
categories,
|
57
|
+
size,
|
58
|
+
image: imageLink,
|
59
|
+
cover: 'thumbnail_' + imageLink,
|
60
|
+
};
|
61
|
+
|
62
|
+
const photo = await Photo.create(newPhoto);
|
63
|
+
if (!photo) {
|
64
|
+
return res.status(404).send({ message: `Photo with link ${imageLink} is not created.` });
|
65
|
+
}
|
66
|
+
photos.push(photo);
|
59
67
|
}
|
60
68
|
|
61
|
-
res.status(200).send(
|
69
|
+
res.status(200).send(photos);
|
62
70
|
} catch (error) {
|
63
|
-
console.log(error)
|
71
|
+
console.log(error);
|
64
72
|
res.status(500).send({ message: error });
|
65
73
|
}
|
66
74
|
}
|
67
|
-
];
|
68
|
-
|
69
75
|
|
76
|
+
const update = (req, res) => {
|
77
|
+
Photo.findOneAndUpdate({_id:req.body._id}, req.body, { new: true })
|
78
|
+
.exec()
|
79
|
+
.then(photo => {
|
80
|
+
if (!photo) {
|
81
|
+
return res.status(404).send({ message: "Something went wrong when updating photo." });
|
82
|
+
}
|
83
|
+
res.status(200).send(photo);
|
84
|
+
})
|
85
|
+
.catch(err => {
|
86
|
+
console.log(err)
|
87
|
+
return res.status(500).send({ message: err });
|
88
|
+
});
|
89
|
+
};
|
70
90
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
};
|
91
|
+
const deletePhoto = (req, res) => {
|
92
|
+
Photo.findOneAndDelete({_id: req.params._id})
|
93
|
+
.exec()
|
94
|
+
.then(photo => {
|
95
|
+
if (!photo) {
|
96
|
+
return res.status(404).send({ message: "Photo is not deleted." });
|
97
|
+
}
|
98
|
+
res.status(200).send(photo);
|
99
|
+
})
|
100
|
+
.catch(err => {
|
101
|
+
return res.status(500).send({ message: err });
|
102
|
+
});
|
103
|
+
};
|
85
104
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
}
|
93
|
-
res.status(200).send(photo);
|
94
|
-
})
|
95
|
-
.catch(err => {
|
96
|
-
return res.status(500).send({ message: err });
|
97
|
-
});
|
105
|
+
return {
|
106
|
+
read,
|
107
|
+
create,
|
108
|
+
update,
|
109
|
+
delete: deletePhoto
|
110
|
+
};
|
98
111
|
};
|
99
112
|
|
113
|
+
module.exports = controllerFactory;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
// // Importing Vue components from the components directory
|
2
|
+
// // import Profile from './components/pages/Profile.vue';
|
3
|
+
// // import ProfileEdit from './components/pages/ProfileEdit.vue';
|
4
|
+
|
5
|
+
// // Importing Vuex store modules from the store directory
|
6
|
+
// import * as filesStore from './store/files.store.js';
|
7
|
+
|
8
|
+
// // Importing Vue Router routes from the router directory
|
9
|
+
// import filesRoutes from './router/files.router.js';
|
10
|
+
|
11
|
+
// // Exporting components, store modules, and routes
|
12
|
+
// export {
|
13
|
+
// Profile,
|
14
|
+
// ProfileEdit,
|
15
|
+
// filesStore,
|
16
|
+
// filesRoutes
|
17
|
+
// };
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// Importing controllers from the controllers directory
|
2
|
+
const galleryController = require('./controllers/gallery.controller.js');
|
3
|
+
// Importing routes from the routes directory
|
4
|
+
const galleryRoutes = require('./routes/gallery.routes.js');
|
5
|
+
// Models
|
6
|
+
// const FileModel = require('./models/file.model.js');
|
7
|
+
|
8
|
+
// Exporting controllers, routes, and models
|
9
|
+
module.exports = {
|
10
|
+
galleryController,
|
11
|
+
galleryRoutes,
|
12
|
+
// FileModel
|
13
|
+
};
|
@@ -1,16 +1,22 @@
|
|
1
|
-
|
1
|
+
module.exports = (mongoose) => {
|
2
|
+
const Photochema = new mongoose.Schema({
|
3
|
+
categories: {
|
4
|
+
type: [String],
|
5
|
+
},
|
6
|
+
size: {
|
7
|
+
type: Object,
|
8
|
+
},
|
9
|
+
cover: {
|
10
|
+
type: String,
|
11
|
+
required: true
|
12
|
+
},
|
13
|
+
image: {
|
14
|
+
type: String,
|
15
|
+
required: true
|
16
|
+
},
|
17
|
+
})
|
2
18
|
|
3
|
-
const
|
4
|
-
categories: {
|
5
|
-
type: [String],
|
6
|
-
},
|
7
|
-
size: {
|
8
|
-
type: Object,
|
9
|
-
},
|
10
|
-
image: {
|
11
|
-
type: String,
|
12
|
-
required: true
|
13
|
-
},
|
14
|
-
});
|
19
|
+
const Photo = mongoose.model("Photo", Photochema);
|
15
20
|
|
16
|
-
|
21
|
+
return Photo;
|
22
|
+
};
|