mango-cms 0.2.12 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/default/package.json +3 -0
- package/default/src/helpers/mango.js +66 -0
- package/default/vite.config.js +40 -23
- package/package.json +1 -1
package/default/package.json
CHANGED
|
@@ -333,6 +333,72 @@ Mango.endpoints = Object.keys(endpoints).reduce((a, c) => {
|
|
|
333
333
|
|
|
334
334
|
}, {})
|
|
335
335
|
|
|
336
|
+
Mango.upload = async (file) => {
|
|
337
|
+
|
|
338
|
+
return new Promise((resolve, reject) => {
|
|
339
|
+
const formData = new FormData()
|
|
340
|
+
|
|
341
|
+
let uploading = true
|
|
342
|
+
let filename = file.name
|
|
343
|
+
let progress = 0
|
|
344
|
+
let url
|
|
345
|
+
let error
|
|
346
|
+
|
|
347
|
+
// // Compress the image
|
|
348
|
+
// if (file.type.includes('image')) {
|
|
349
|
+
// let results = await compress.compress([file], {
|
|
350
|
+
// quality: .75, // the quality of the image, max is 1,
|
|
351
|
+
// maxWidth: 1920, // the max width of the output image, defaults to 1920px
|
|
352
|
+
// maxHeight: 1920, // the max height of the output image, defaults to 1920px
|
|
353
|
+
// resize: true, // defaults to true, set false if you do not want to resize the image width and height
|
|
354
|
+
// rotate: false, // See the rotation section below
|
|
355
|
+
// })
|
|
356
|
+
// const img1 = results[0]
|
|
357
|
+
// const base64str = img1.data
|
|
358
|
+
// const imgExt = img1.ext
|
|
359
|
+
// const filename = file.name
|
|
360
|
+
// file = Compress.convertBase64ToFile(base64str, imgExt)
|
|
361
|
+
// file = new File([file], filename, { type: file.type });
|
|
362
|
+
// console.log('file', file)
|
|
363
|
+
// }
|
|
364
|
+
|
|
365
|
+
formData.append('file', file)
|
|
366
|
+
|
|
367
|
+
const xhr = new XMLHttpRequest()
|
|
368
|
+
|
|
369
|
+
xhr.open('POST', `${api}/upload`, true)
|
|
370
|
+
|
|
371
|
+
xhr.upload.onprogress = (event) => {
|
|
372
|
+
if (event.lengthComputable) {
|
|
373
|
+
progress = (event.loaded / event.total) * 100
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
xhr.onload = () => {
|
|
378
|
+
if (xhr.status === 200) {
|
|
379
|
+
const json = JSON.parse(xhr.response)
|
|
380
|
+
const path = json.paths[0]
|
|
381
|
+
const url = api + path
|
|
382
|
+
uploading = false
|
|
383
|
+
progress = 0
|
|
384
|
+
resolve(url)
|
|
385
|
+
} else {
|
|
386
|
+
error = 'Error while uploading file'
|
|
387
|
+
uploading = false
|
|
388
|
+
reject(error)
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
xhr.onerror = () => {
|
|
393
|
+
error = 'Error while uploading file'
|
|
394
|
+
uploading = false
|
|
395
|
+
reject(error)
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
xhr.send(formData)
|
|
399
|
+
})
|
|
400
|
+
}
|
|
401
|
+
|
|
336
402
|
Mango.collections = collections
|
|
337
403
|
Mango.ws = ws
|
|
338
404
|
|
package/default/vite.config.js
CHANGED
|
@@ -9,32 +9,49 @@ let configPath = path.resolve(projectRoot, 'mango')
|
|
|
9
9
|
|
|
10
10
|
// If config doesn't exist in current directory, check parent
|
|
11
11
|
if (!fs.existsSync(configPath)) {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
projectRoot = path.resolve(projectRoot, '..')
|
|
13
|
+
configPath = path.resolve(projectRoot, 'mango')
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
// If config still doesn't exist, throw error
|
|
16
|
+
if (!fs.existsSync(configPath)) {
|
|
17
|
+
throw new Error('Mango folder not found. Please ensure your mango folder exists either in the current directory or parent directory.')
|
|
18
|
+
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
const collectionsPath = path.resolve(configPath, 'config/.collections.json')
|
|
22
|
+
|
|
21
23
|
// https://vitejs.dev/config/
|
|
22
24
|
export default defineConfig({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
plugins: [
|
|
26
|
+
vue(),
|
|
27
|
+
{
|
|
28
|
+
name: 'watch-collections',
|
|
29
|
+
configureServer(server) {
|
|
30
|
+
server.watcher.add(collectionsPath)
|
|
31
|
+
server.watcher.on('change', (file) => {
|
|
32
|
+
if (file === collectionsPath) {
|
|
33
|
+
server.ws.send({
|
|
34
|
+
type: 'full-reload',
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
server: {
|
|
42
|
+
host: '0.0.0.0',
|
|
43
|
+
},
|
|
44
|
+
resolve: {
|
|
45
|
+
alias: {
|
|
46
|
+
'@config': configPath,
|
|
47
|
+
'@mango': configPath,
|
|
48
|
+
'@settings': path.resolve(configPath, 'config/settings.json'),
|
|
49
|
+
'@collections': path.resolve(configPath, 'config/.collections.json'),
|
|
50
|
+
'@plugins': path.resolve(configPath, 'plugins'),
|
|
51
|
+
vue: path.resolve(__dirname, 'node_modules/vue'),
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
optimizeDeps: {
|
|
55
|
+
exclude: ['vue', '@collections'], // Prevent Vite from optimizing Vue separately
|
|
56
|
+
},
|
|
40
57
|
})
|