Procházet zdrojové kódy

⚙️ 升级更新脚本

快乐的梦鱼 před 4 týdny
rodič
revize
29eeb72a14

+ 0 - 92
scripts/UpdateScript/app.mjs

@@ -43,11 +43,7 @@ export async function viewVersion(type) {
         data = await axiosInstance.get('/version/' + type);
     }
     catch (e) {
-<<<<<<< HEAD
       logError('Failed to load version info', e);
-=======
-      console.error('Failed to load version info', e);
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
       return;
     }
     const table = new Table({
@@ -80,15 +76,9 @@ export async function getVersion(action, type) {
           status: 1,
           config: "{}",
         });
-<<<<<<< HEAD
         consola.success('Add version success');
       } catch (e) {
         logError('Failed to add version', e);
-=======
-        console.log('Add version success');
-      } catch (e) {
-        console.error('Failed to add version', e);
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
       }
       break;
     }
@@ -100,15 +90,9 @@ export async function getVersion(action, type) {
         return;
       try {
         await axiosInstance.delete('/version/' + versionId);
-<<<<<<< HEAD
         consola.success('删除版本成功');
       } catch (e) {
         logError('删除版本失败', e);
-=======
-        console.log('删除版本成功');
-      } catch (e) {
-        console.error('删除版本失败', e);
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
       }
       break;
     }
@@ -136,15 +120,9 @@ export async function getVersion(action, type) {
         await axiosInstance.put('/version/' + versionId, {
           status: state
         });
-<<<<<<< HEAD
         consola.success('设置状态成功');
       } catch (e) {
         logError('设置状态失败', e);
-=======
-        console.log('设置状态成功');
-      } catch (e) {
-        console.error('设置状态失败', e);
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
       }
       break;
     }
@@ -155,15 +133,9 @@ export async function getVersion(action, type) {
         await axiosInstance.put('/version/' + versionId, {
           config: config,
         });
-<<<<<<< HEAD
         consola.success('设置配置成功');
       } catch (e) {
         logError('设置配置失败', e);
-=======
-        console.log('设置配置成功');
-      } catch (e) {
-        console.error('设置配置失败', e);
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
       }
       break;
     }
@@ -174,15 +146,9 @@ export async function getVersion(action, type) {
 
       try {
         await axiosInstance.post('/update/active/app', { versionId, updateId, isNext });
-<<<<<<< HEAD
         consola.success('成功');
       } catch (e) {
         logError('失败', e);
-=======
-        console.log('成功');
-      } catch (e) {
-        console.error('失败', e);
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
       }
       break;
     }
@@ -192,24 +158,14 @@ export async function getVersion(action, type) {
 
       try {
         await axiosInstance.post('/update/active/web', { versionId, updateId });
-<<<<<<< HEAD
         consola.success('成功');
       } catch (e) {
         logError('失败', e);
-=======
-        console.log('成功');
-      } catch (e) {
-        console.error('失败', e);
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
       }
       break;
     }
     default:
-<<<<<<< HEAD
       logError('未知参数', action);
-=======
-      console.error('未知参数', action);
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
       break;
   }
 }
@@ -222,11 +178,7 @@ export async function selectVersion(defaultVersionId = null) {
     appId: config.appId 
   }))).data;
   if (data.length === 0) {
-<<<<<<< HEAD
     logError('没有版本,请在管理后台创建 appId ' + config.appId + ' 的版本');
-=======
-    console.error('没有版本');
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
     return;
   }
   const versionId = (await select({
@@ -244,11 +196,7 @@ export async function selectUpdate() {
   const { versionId } = await selectVersion();
   const data = (await axiosInstance.get('/version/update?search=' + JSON.stringify({ versionId }))).data;
   if (data.length === 0) {
-<<<<<<< HEAD
     logError('没有更新');
-=======
-    console.error('没有更新');
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
     return;
   }
   const resultId = (await select({
@@ -279,11 +227,7 @@ export async function postUpdate(type, options) {
       break;
     }
     default:
-<<<<<<< HEAD
       logError('Unknow type', type);
-=======
-      console.error('Unknow type', type);
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
       break;
   }
 }
@@ -308,19 +252,11 @@ export async function deprecateOrDeleteUpdate(updateId) {
   })) === 0;
 
   if (deprecate && currentUpdateInfo.type !== 1) {
-<<<<<<< HEAD
     consola.warn('只有Web更新允许弃用');
     return;
   }
   if (currentUpdateInfo.status === 0) {
     consola.warn(`当前状态 ${stateConstant[currentUpdateInfo.status]} 无法弃用`);
-=======
-    console.log('只有Web更新允许弃用');
-    return;
-  }
-  if (currentUpdateInfo.status === 0) {
-    console.log(`当前状态 ${stateConstant[currentUpdateInfo.status]} 无法弃用`);
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
     return;
   }
 
@@ -334,15 +270,9 @@ export async function deprecateOrDeleteUpdate(updateId) {
 
   try {
     await axiosInstance.post(`/update/${deprecate ? 'deprecate' : 'delete'}`, { updateId });
-<<<<<<< HEAD
     consola.success(`${deprecate ? '弃用' : '删除'} 成功`);
   } catch (e) {
     logError(`操作失败`, e);
-=======
-    console.log(`${deprecate ? '弃用' : '删除'} 成功`);
-  } catch (e) {
-    console.error(`操作失败`, e);
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
   }
 }
 export async function viewUpdate(updateId) {
@@ -353,20 +283,12 @@ export async function viewUpdate(updateId) {
   try {
     currentUpdateInfo = (await axiosInstance.get('/update/' + updateId)).data;
   } catch (e) {
-<<<<<<< HEAD
     logError('加载更新信息失败', updateId);
-=======
-    console.error('加载更新信息失败', updateId);
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
   }
   try {
     currentVersionInfo = (await axiosInstance.get('/version/' + currentUpdateInfo.versionId)).data;
   } catch (e) {
-<<<<<<< HEAD
     logError('加载版本信息失败', currentUpdateInfo.versionId);
-=======
-    console.error('加载版本信息失败', currentUpdateInfo.versionId);
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
   }
 
   const table = new Table({
@@ -429,11 +351,7 @@ export async function getUpdate(action, type, all, options) {
 
     if (type !== 'all' && all !== 'all' && data.data.length > 10) {
       data.data = data.data.slice(0, 10);
-<<<<<<< HEAD
       consola.info('filter!', all);
-=======
-      console.log('filter!', all);
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
     }
 
     data.data.forEach((d) => {
@@ -462,11 +380,7 @@ export async function getUpdate(action, type, all, options) {
         break;
       }
       default: 
-<<<<<<< HEAD
         logError('Unknow action', action);
-=======
-        console.error('Unknow action', action);
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
         break;
     }
   }
@@ -474,14 +388,8 @@ export async function getUpdate(action, type, all, options) {
 export async function testVersion(version) {
   try {
     const data = await axiosInstance.get('/update-get-info?version=' + version);
-<<<<<<< HEAD
     consola.info('版本信息', data.data);
   } catch(e) {
     logError('获取失败', e);
-=======
-    console.log('版本信息', data.data);
-  } catch(e) {
-    console.log('获取失败', e);
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
   }
 }

+ 0 - 53
scripts/UpdateScript/auth.mjs

@@ -28,10 +28,7 @@ export const constant = {
 
 let currentData = {
   token: '',
-<<<<<<< HEAD
   refreshToken: '',
-=======
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
   identifier: '',
 };
 
@@ -44,13 +41,10 @@ function getErrorMessage(e) {
   return e instanceof Error ? e.message : (typeof e === 'object' ? e : '' + e);
 }
 
-<<<<<<< HEAD
 async function saveCurrentData() {
   await writeFile(constant.TokenSave, JSON.stringify(currentData));
 }
 
-=======
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
 // Axios 实例
 // ========================================
 
@@ -77,7 +71,6 @@ axiosInstance.interceptors.request.use((value) => {
   return value;
 });
 
-<<<<<<< HEAD
 let refreshPromise = null;
 
 async function tryRefreshToken() {
@@ -140,22 +133,13 @@ axiosInstance.interceptors.response.use(null, async (error) => {
     }
   }
   return Promise.reject(error);
-=======
-axiosInstance.interceptors.response.use((value) => {
-  if (value.data.success) return value.data;
-  else return Promise.reject(value.data);
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
 });
 
 // 认证初始化
 // ========================================
 
 /**
-<<<<<<< HEAD
  * 初始化认证模块,从本地加载 token,并检查登录状态
-=======
- * 初始化认证模块,从本地加载 token
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
  * @returns {Promise<void>}
  */
 export async function initAuth() {
@@ -169,7 +153,6 @@ export async function initAuth() {
     // 无 token 文件时使用默认值
   }
   initIdentifier();
-<<<<<<< HEAD
 
   if (currentData.token) {
     try {
@@ -197,8 +180,6 @@ export async function initAuth() {
 
   consola.warn('未登录,进入登录界面');
   await interactiveLogin();
-=======
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
 }
 
 /**
@@ -212,7 +193,6 @@ export function getCurrentData() {
 // ========================================
 
 /**
-<<<<<<< HEAD
  * 执行登录请求并保存 token
  * @param {string} user 用户名
  * @param {string} pass 密码
@@ -251,22 +231,14 @@ async function interactiveLogin() {
 }
 
 /**
-=======
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
  * 检查登录状态
  */
 export async function checkLogged() {
   try {
     await axiosInstance.get('/auth');
-<<<<<<< HEAD
     consola.success('已登录');
   } catch (e) {
     logError('获取状态失败:', getErrorMessage(e));
-=======
-    console.log('已登录');
-  } catch (e) {
-    console.error('获取状态失败:', getErrorMessage(e));
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
   }
 }
 
@@ -276,28 +248,12 @@ export async function checkLogged() {
  */
 export async function login(user) {
   try {
-<<<<<<< HEAD
     const username = user || await input({ message: '输入用户名' });
     const pass = await password({ message: '输入密码' });
     await doLogin(username, pass);
     consola.success('登录成功');
   } catch (e) {
     logError('登录失败', getErrorMessage(e));
-=======
-    const pass = await password({ message: '输入密码' });
-    const res = await axiosInstance.post('/auth?rember=true', {
-      method: 'key',
-      key: `${user}@${md5(pass)}`,
-    });
-    currentData.token = {
-      authName: res.data.authName,
-      authKey: res.data.authKey,
-    };
-    await writeFile(constant.TokenSave, JSON.stringify(currentData));
-    console.log('登录成功');
-  } catch (e) {
-    console.error('登录失败', getErrorMessage(e));
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
   }
 }
 
@@ -306,7 +262,6 @@ export async function login(user) {
  */
 export async function logout() {
   currentData.token = '';
-<<<<<<< HEAD
   currentData.refreshToken = '';
   await saveCurrentData();
   try {
@@ -314,13 +269,5 @@ export async function logout() {
     consola.success('退出登录成功');
   } catch (e) {
     logError('退出登录失败', getErrorMessage(e));
-=======
-  await writeFile(constant.TokenSave, JSON.stringify(currentData));
-  try {
-    await axiosInstance.delete('/auth');
-    console.log('退出登录成功');
-  } catch (e) {
-    console.error('退出登录失败', getErrorMessage(e));
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f
   }
 }

+ 0 - 6
scripts/UpdateScript/index.mjs

@@ -47,7 +47,6 @@ function start() {
 
 initAuth().then(start);
 
-<<<<<<< HEAD
 process.on('unhandledRejection', (reason) => {
   let reasonStr = '';
   if (typeof reason === 'string') {
@@ -62,8 +61,3 @@ process.on('unhandledRejection', (reason) => {
   logError('UnhandledRejection:', reasonStr)
 })
 
-=======
-process.on('unhandledRejection', (reason, p) => {
-  console.error('Promise: ', p, 'Reason: ', reason)
-})
->>>>>>> 7c11b917b224c1bfd3d86d6cc15ea83fede0098f