mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
B OpenNebula/one#6423: Fix upload image (#2904)
Signed-off-by: Jorge Lobo <jlobo@opennebula.io>
This commit is contained in:
parent
5d21f33a7b
commit
0d562a2eab
@ -464,6 +464,7 @@ module.exports = {
|
||||
Path: 'Path/URL',
|
||||
ImagePath: 'Path in OpenNebula server or URL',
|
||||
Upload: 'Upload',
|
||||
ErrorUpload: 'Error Upload',
|
||||
EmptyDisk: 'Empty disk image',
|
||||
ImageSize: 'Image size, in Megabytes',
|
||||
ImageSizeUnit: 'Image size',
|
||||
|
@ -16,21 +16,22 @@
|
||||
import { ReactElement } from 'react'
|
||||
import { useHistory } from 'react-router'
|
||||
|
||||
import { jsonToXml } from 'client/models/Helper'
|
||||
import { useGeneralApi } from 'client/features/General'
|
||||
import { useGetDatastoresQuery } from 'client/features/OneApi/datastore'
|
||||
import {
|
||||
useAllocateImageMutation,
|
||||
useUploadImageMutation,
|
||||
} from 'client/features/OneApi/image'
|
||||
import { useGetDatastoresQuery } from 'client/features/OneApi/datastore'
|
||||
import { jsonToXml } from 'client/models/Helper'
|
||||
|
||||
import { PATH } from 'client/apps/sunstone/routesOne'
|
||||
import {
|
||||
DefaultFormStepper,
|
||||
SkeletonStepsForm,
|
||||
} from 'client/components/FormStepper'
|
||||
import { CreateForm } from 'client/components/Forms/Image'
|
||||
import { PATH } from 'client/apps/sunstone/routesOne'
|
||||
|
||||
import { T } from 'client/constants'
|
||||
import { useSystemData } from 'client/features/Auth'
|
||||
|
||||
const _ = require('lodash')
|
||||
@ -44,11 +45,12 @@ function CreateImage() {
|
||||
const history = useHistory()
|
||||
const [allocate] = useAllocateImageMutation()
|
||||
const [upload] = useUploadImageMutation()
|
||||
const { enqueueSuccess, uploadSnackbar } = useGeneralApi()
|
||||
const { enqueueSuccess, enqueueError, uploadSnackbar } = useGeneralApi()
|
||||
const { adminGroup, oneConfig } = useSystemData()
|
||||
useGetDatastoresQuery(undefined, { refetchOnMountOrArgChange: false })
|
||||
|
||||
const onSubmit = async ({ template, datastore, file }) => {
|
||||
let fileUploaded
|
||||
if (file) {
|
||||
const uploadProcess = (progressEvent) => {
|
||||
const percentCompleted = Math.round(
|
||||
@ -58,21 +60,26 @@ function CreateImage() {
|
||||
percentCompleted === 100 && uploadSnackbar(0)
|
||||
}
|
||||
try {
|
||||
const fileUploaded = await upload({
|
||||
fileUploaded = await upload({
|
||||
file,
|
||||
uploadProcess,
|
||||
}).unwrap()
|
||||
|
||||
template.PATH = fileUploaded[0]
|
||||
} catch {}
|
||||
}
|
||||
|
||||
try {
|
||||
const newTemplateId = await allocate({
|
||||
template: jsonToXml(template),
|
||||
datastore,
|
||||
}).unwrap()
|
||||
history.push(PATH.STORAGE.IMAGES.LIST)
|
||||
enqueueSuccess(`Image created - #${newTemplateId}`)
|
||||
if (file && !Array.isArray(fileUploaded)) {
|
||||
enqueueError(T.ErrorUpload)
|
||||
} else {
|
||||
const newTemplateId = await allocate({
|
||||
template: jsonToXml(template),
|
||||
datastore,
|
||||
}).unwrap()
|
||||
history.push(PATH.STORAGE.IMAGES.LIST)
|
||||
enqueueSuccess(`Image created - #${newTemplateId}`)
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
|
@ -39,13 +39,17 @@ const upload = (
|
||||
) => {
|
||||
const { files } = params
|
||||
const { user, password } = userData
|
||||
|
||||
if (!(files && user && password)) {
|
||||
res.locals.httpCode = httpBadRequest
|
||||
next()
|
||||
}
|
||||
|
||||
const data = files.map((file) => file.path)
|
||||
res.locals.httpCode = httpResponse(ok, data.length ? data : '')
|
||||
return
|
||||
}
|
||||
try {
|
||||
const data = files.map((file) => file.path)
|
||||
res.locals.httpCode = httpResponse(ok, data?.length ? data : '')
|
||||
} catch {}
|
||||
next()
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,11 @@
|
||||
const { env } = require('process')
|
||||
const multer = require('multer')
|
||||
const { messageTerminal } = require('server/utils/general')
|
||||
const { getRequestParameters, getRequestFiles } = require('server/utils/server')
|
||||
const {
|
||||
genPathResources,
|
||||
getRequestParameters,
|
||||
getRequestFiles,
|
||||
} = require('server/utils/server')
|
||||
const {
|
||||
defaultWebpackMode,
|
||||
defaultConfigErrorMessage,
|
||||
@ -26,6 +30,8 @@ const {
|
||||
const { writeInLogger } = require('server/utils/logger')
|
||||
const { getSunstoneConfig } = require('server/utils/yml')
|
||||
|
||||
genPathResources()
|
||||
|
||||
const appConfig = getSunstoneConfig()
|
||||
const optsMulter = { dest: appConfig.tmpdir || defaultTmpPath }
|
||||
if (appConfig && appConfig.max_upload_file_size) {
|
||||
|
Loading…
Reference in New Issue
Block a user