197197 placement =" bottom"
198198 >
199199 <el-form-item label =" cert" prop =" tls.cert" >
200- <el-input v-model =" dataForm.tls.cert" clearable />
200+ <el-input
201+ v-model =" dataForm.tls.cert"
202+ style =" width : 50% "
203+ clearable
204+ />
205+ <el-upload
206+ style =" height : 32px "
207+ ref =" uploadCrtFile"
208+ action =" "
209+ :file-list =" crtFileList"
210+ :http-request =" uploadCertFile"
211+ accept =" .crt"
212+ :before-upload ="
213+ () => {
214+ crtFileList = [];
215+ }
216+ "
217+ :show-file-list =" false"
218+ :limit =" 1"
219+ >
220+ <template #trigger >
221+ <el-button >{{ t("config.uploadCrtFile") }}</el-button >
222+ </template >
223+ </el-upload >
201224 </el-form-item >
202225 </el-tooltip >
203226 <el-tooltip
206229 placement =" bottom"
207230 >
208231 <el-form-item label =" key" prop =" tls.key" >
209- <el-input v-model =" dataForm.tls.key" clearable />
232+ <el-input
233+ v-model =" dataForm.tls.key"
234+ style =" width : 50% "
235+ clearable
236+ />
237+ <el-upload
238+ style =" height : 32px "
239+ ref =" uploadKeyFile"
240+ action =" "
241+ :file-list =" keyFileList"
242+ :http-request =" uploadCertFile"
243+ accept =" .key"
244+ :before-upload ="
245+ () => {
246+ keyFileList = [];
247+ }
248+ "
249+ :show-file-list =" false"
250+ :limit =" 1"
251+ >
252+ <template #trigger >
253+ <el-button >{{ t("config.uploadKeyFile") }}</el-button >
254+ </template >
255+ </el-upload >
210256 </el-form-item >
211257 </el-tooltip >
212258 <el-tooltip
@@ -1049,6 +1095,7 @@ import {
10491095 listConfigApi ,
10501096 updateConfigsApi ,
10511097 updateHysteria2ConfigApi ,
1098+ uploadCertFileApi ,
10521099} from " @/api/config" ;
10531100import { useI18n } from " vue-i18n" ;
10541101import { assignWith , deepCopy } from " @/utils/copy" ;
@@ -1059,6 +1106,7 @@ import {
10591106} from " element-plus/lib/components" ;
10601107import { hysteria2ChangeVersionApi , listReleaseApi } from " @/api/hysteria2" ;
10611108import { monitorHysteria2Api } from " @/api/monitor" ;
1109+ import { UploadUserFile } from " element-plus" ;
10621110
10631111const { t } = useI18n ();
10641112
@@ -1132,6 +1180,8 @@ const state = reactive({
11321180 version: " " ,
11331181 running: false ,
11341182 },
1183+ crtFileList: [] as UploadUserFile [],
1184+ keyFileList: [] as UploadUserFile [],
11351185});
11361186
11371187const {
@@ -1155,6 +1205,8 @@ const {
11551205 hysteria2Version,
11561206 hysteria2Versions,
11571207 hysteria2Monitor,
1208+ crtFileList,
1209+ keyFileList,
11581210} = toRefs (state );
11591211
11601212const tabs = computed (() => {
@@ -1576,6 +1628,33 @@ const handleHysteria2ChangeVersion = async () => {
15761628 await setHysteria2Monitor ();
15771629};
15781630
1631+ const uploadCertFile = async (params : UploadRequestOptions ) => {
1632+ try {
1633+ if (! state .dataForm .tls ) {
1634+ return ;
1635+ }
1636+ if (
1637+ ! params .file .name .endsWith (" .crt" ) &&
1638+ ! params .file .name .endsWith (" .key" )
1639+ ) {
1640+ ElMessage .error (" file format not supported" );
1641+ }
1642+ if (params .file .size > 1024 * 1024 ) {
1643+ ElMessage .error (" the file is too big" );
1644+ }
1645+ let formData = new FormData ();
1646+ formData .append (" file" , params .file );
1647+ const { data } = await uploadCertFileApi (formData );
1648+ if (params .file .name .endsWith (" .crt" )) {
1649+ state .dataForm .tls .cert = data ;
1650+ } else if (params .file .name .endsWith (" .key" )) {
1651+ state .dataForm .tls .key = data ;
1652+ }
1653+ } catch (e ) {
1654+ /* empty */
1655+ }
1656+ };
1657+
15791658onMounted (() => {
15801659 setConfig ();
15811660 setHysteria2Versions ();
0 commit comments