fix
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { program, Command } from '@/program.ts';
|
import { program, Command } from '@/program.ts';
|
||||||
import { getConfig } from '@/module/get-config.ts';
|
import { getConfig, getEnvToken } from '@/module/get-config.ts';
|
||||||
import inquirer from 'inquirer';
|
import inquirer from 'inquirer';
|
||||||
import { loginInCommand } from '@/module/login/login-by-web.ts';
|
import { loginInCommand } from '@/module/login/login-by-web.ts';
|
||||||
import { queryLogin, storage } from '@/module/query.ts';
|
import { queryLogin, storage } from '@/module/query.ts';
|
||||||
@@ -75,13 +75,13 @@ const loginCommand = new Command('login')
|
|||||||
program.addCommand(loginCommand);
|
program.addCommand(loginCommand);
|
||||||
|
|
||||||
const showMe = async (show = true) => {
|
const showMe = async (show = true) => {
|
||||||
const token = process.env.KEVISUAL_TOKEN;
|
const token = getEnvToken();
|
||||||
const localToken = storage.getItem('token');
|
const localToken = storage.getItem('token');
|
||||||
if (!token && !localToken) {
|
if (!token && !localToken) {
|
||||||
console.log('请先登录');
|
console.log('请先登录');
|
||||||
return { code: 40400, message: '请先登录' };
|
return { code: 40400, message: '请先登录' };
|
||||||
}
|
}
|
||||||
let me = await queryLogin.getMe(token);
|
let me = await queryLogin.getMe(localToken || token);
|
||||||
if (me?.code === 401) {
|
if (me?.code === 401) {
|
||||||
me = await queryLogin.getMe();
|
me = await queryLogin.getMe();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { program as app, Command } from '@/program.ts';
|
import { program as app, Command } from '@/program.ts';
|
||||||
import { getConfig, writeConfig } from '@/module/index.ts';
|
import { getConfig, getEnvToken, writeConfig } from '@/module/index.ts';
|
||||||
import { queryLogin, storage } from '@/module/query.ts';
|
import { queryLogin, storage } from '@/module/query.ts';
|
||||||
import inquirer from 'inquirer';
|
import inquirer from 'inquirer';
|
||||||
import util from 'util';
|
import util from 'util';
|
||||||
@@ -23,7 +23,7 @@ const token = new Command('token')
|
|||||||
.action(async (opts) => {
|
.action(async (opts) => {
|
||||||
const token = storage.getItem('token');
|
const token = storage.getItem('token');
|
||||||
if (opts.env) {
|
if (opts.env) {
|
||||||
console.log('token in env', process.env.KEVISUAL_TOKEN);
|
console.log('token in env', getEnvToken());
|
||||||
} else {
|
} else {
|
||||||
console.log('token', token);
|
console.log('token', token);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,6 +103,9 @@ export class SyncBase {
|
|||||||
const syncList = syncKeys.map((key) => {
|
const syncList = syncKeys.map((key) => {
|
||||||
const value = sync[key];
|
const value = sync[key];
|
||||||
const filepath = path.join(this.#dir, key); // 文件的路径
|
const filepath = path.join(this.#dir, key); // 文件的路径
|
||||||
|
if (filepath.includes('node_modules') || filepath.includes('.git')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (typeof value === 'string') {
|
if (typeof value === 'string') {
|
||||||
const auth = checkAuth(value, baseURL);
|
const auth = checkAuth(value, baseURL);
|
||||||
const type = auth ? 'sync' : 'none';
|
const type = auth ? 'sync' : 'none';
|
||||||
@@ -123,11 +126,14 @@ export class SyncBase {
|
|||||||
type: value?.type ?? type,
|
type: value?.type ?? type,
|
||||||
auth: checkAuth(value.url, baseURL),
|
auth: checkAuth(value.url, baseURL),
|
||||||
};
|
};
|
||||||
});
|
}).filter((item) => item);
|
||||||
|
let resultSyncList: SyncList[] = []
|
||||||
if (opts?.getFile) {
|
if (opts?.getFile) {
|
||||||
return this.getSyncListFile(syncList);
|
resultSyncList = await this.getSyncListFile(syncList);
|
||||||
|
} else {
|
||||||
|
resultSyncList = syncList;
|
||||||
}
|
}
|
||||||
return syncList;
|
return resultSyncList;
|
||||||
}
|
}
|
||||||
async getCheckList() {
|
async getCheckList() {
|
||||||
const checkDir = this.config?.clone || {};
|
const checkDir = this.config?.clone || {};
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { Result } from '@kevisual/query';
|
|||||||
import { fileIsExist } from '@/uitls/file.ts';
|
import { fileIsExist } from '@/uitls/file.ts';
|
||||||
import { glob } from 'fast-glob';
|
import { glob } from 'fast-glob';
|
||||||
import inquirer from 'inquirer';
|
import inquirer from 'inquirer';
|
||||||
|
import { getEnvToken } from '../get-config.ts';
|
||||||
|
|
||||||
type DownloadTask = {
|
type DownloadTask = {
|
||||||
downloadPath: string;
|
downloadPath: string;
|
||||||
@@ -38,7 +39,7 @@ type Options = {
|
|||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
export const fetchLink = async (url: string = '', opts?: Options) => {
|
export const fetchLink = async (url: string = '', opts?: Options) => {
|
||||||
const token = process.env.KEVISUAL_TOKEN || storage.getItem('token');
|
const token = storage.getItem('token') || getEnvToken();
|
||||||
const fetchURL = new URL(url);
|
const fetchURL = new URL(url);
|
||||||
const check = opts?.check ?? false;
|
const check = opts?.check ?? false;
|
||||||
const isKevisual = !!url.includes('kevisual');
|
const isKevisual = !!url.includes('kevisual');
|
||||||
@@ -272,8 +273,14 @@ export type AiList = {
|
|||||||
pathname?: string;
|
pathname?: string;
|
||||||
url?: string;
|
url?: string;
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* AI路径的资源下载地址
|
||||||
|
* @param url
|
||||||
|
* @param opts
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
export const fetchAiList = async (url: string, opts?: { recursive: boolean }): Promise<Result<AiList[]>> => {
|
export const fetchAiList = async (url: string, opts?: { recursive: boolean }): Promise<Result<AiList[]>> => {
|
||||||
const token = process.env.KEVISUAL_TOKEN || storage.getItem('token');
|
const token = storage.getItem('token') || getEnvToken();
|
||||||
const _url = new URL(url);
|
const _url = new URL(url);
|
||||||
const dir = _url.searchParams.get('dir');
|
const dir = _url.searchParams.get('dir');
|
||||||
if (!dir) {
|
if (!dir) {
|
||||||
|
|||||||
@@ -35,3 +35,7 @@ export const writeConfig = (config: Record<string, any>) => {
|
|||||||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
||||||
return config;
|
return config;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getEnvToken = () => {
|
||||||
|
return process.env.KEVISUAL_TOKEN || '';
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Query } from '@kevisual/query/query';
|
import { Query } from '@kevisual/query/query';
|
||||||
import { getConfig } from './get-config.ts';
|
import { getConfig, getEnvToken } from './get-config.ts';
|
||||||
import { QueryLoginNode, storage } from '@kevisual/query-login/node';
|
import { QueryLoginNode, storage } from '@kevisual/query-login/node';
|
||||||
const config = getConfig();
|
const config = getConfig();
|
||||||
export const baseURL = config?.baseURL || 'https://kevisual.cn';
|
export const baseURL = config?.baseURL || 'https://kevisual.cn';
|
||||||
@@ -14,7 +14,7 @@ export const getHeader = async () => {
|
|||||||
const headers: Record<string, string> = {
|
const headers: Record<string, string> = {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
};
|
};
|
||||||
let token = process.env.KEVISUAL_TOKEN;
|
let token = getEnvToken();
|
||||||
if (!token) {
|
if (!token) {
|
||||||
token = await storage.getItem('token');
|
token = await storage.getItem('token');
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ export const getHeader = async () => {
|
|||||||
|
|
||||||
query.beforeRequest = async (config) => {
|
query.beforeRequest = async (config) => {
|
||||||
if (config.headers) {
|
if (config.headers) {
|
||||||
let token = process.env.KEVISUAL_TOKEN;
|
let token = getEnvToken();
|
||||||
if (!token) {
|
if (!token) {
|
||||||
token = await storage.getItem('token');
|
token = await storage.getItem('token');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user