diff --git a/src/components/pages/Manage/ShareX.tsx b/src/components/pages/Manage/ShareX.tsx index 2368640..9cb67b3 100644 --- a/src/components/pages/Manage/ShareX.tsx +++ b/src/components/pages/Manage/ShareX.tsx @@ -1,28 +1,28 @@ -import { useState } from 'react'; +import { useReducer, useState } from 'react'; import { GeneratorModal } from './GeneratorModal'; export default function ShareX({ user, open, setOpen }) { - const [config, setConfig] = useState({ - Version: '14.1.0', - Name: 'Zipline', - DestinationType: 'ImageUploader, TextUploader', - RequestMethod: 'POST', - RequestURL: `${ - window.location.protocol + - '//' + - window.location.hostname + - (window.location.port ? ':' + window.location.port : '') - }/api/upload`, - Headers: { - Authorization: user?.token, - }, - URL: '$json:files[0]$', - Body: 'MultipartFormData', - FileFormName: 'file', - Data: undefined, - }); - const onSubmit = (values) => { + const config = { + Version: '14.1.0', + Name: 'Zipline', + DestinationType: 'ImageUploader, TextUploader, FileUploader', + RequestMethod: 'POST', + RequestURL: `${ + window.location.protocol + + '//' + + window.location.hostname + + (window.location.port ? ':' + window.location.port : '') + }/api/upload`, + Headers: { + Authorization: user?.token, + }, + URL: '$json:files[0]$', + Body: 'MultipartFormData', + FileFormName: 'file', + Data: undefined, + }; + if (values.type === 'shorten-url') { config.RequestURL = `${ window.location.protocol + @@ -32,62 +32,49 @@ export default function ShareX({ user, open, setOpen }) { }/api/shorten`; config.URL = '$json:url$'; config.Body = 'JSON'; + config.DestinationType = 'URLShortener'; delete config.FileFormName; config.Data = JSON.stringify({ url: '{input}' }); - setConfig(config); } else { delete config.Data; - setConfig(config); } if (values.format !== 'RANDOM' && values.type === 'upload-file') { config.Headers['Format'] = values.format; - setConfig(config); } else { delete config.Headers['Format']; - setConfig(config); } if (values.imageCompression !== 0 && values.type === 'upload-file') { config.Headers['Image-Compression-Percent'] = values.imageCompression; - setConfig(config); } else { delete config.Headers['Image-Compression-Percent']; - setConfig(config); } if (values.zeroWidthSpace) { config.Headers['Zws'] = 'true'; - setConfig(config); } else { delete config.Headers['Zws']; - setConfig(config); } if (values.embed && values.type === 'upload-file') { config.Headers['Embed'] = 'true'; - setConfig(config); } else { delete config.Headers['Embed']; - setConfig(config); } if (values.noJSON) { config.URL = '{response}'; config.Headers['No-JSON'] = 'true'; - setConfig(config); } else { delete config.Headers['No-JSON']; config.URL = values.type === 'upload-file' ? '$json:files[0]$' : '$json:url$'; - setConfig(config); } if (values.originalName && values.type === 'upload-file') { config.Headers['Original-Name'] = 'true'; - setConfig(config); } else { delete config.Headers['Original-Name']; - setConfig(config); } const pseudoElement = document.createElement('a');