Skip to content

Commit

Permalink
refactor: 调整部分类组件的目录结构
Browse files Browse the repository at this point in the history
  • Loading branch information
renxia committed Jan 18, 2024
1 parent b485542 commit 98942d9
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
export * from './lib';
export * from './async';
export * from './cookie';
export * from './date';
export * from './helper';
export * from './is';
export * from './Logger';
export * from './objects';
export * from './ReqFetch';
export * from './semver';
export * from './uuid';
File renamed without changes.
8 changes: 4 additions & 4 deletions src/common/Logger.ts → src/common/lib/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* @Author: lzw
* @Date: 2022-04-08 10:30:02
* @LastEditors: lzw
* @LastEditTime: 2022-11-15 16:16:45
* @LastEditors: renxia
* @LastEditTime: 2024-01-18 11:05:29
* @Description:
*/
/* eslint no-console: 0 */

import { type GeneralFn } from '../types';
import { safeStringify } from './objects';
import { type GeneralFn } from '../../types';
import { safeStringify } from '../objects';

/** 日志级别 */
export enum LogLevel {
Expand Down
17 changes: 13 additions & 4 deletions src/common/ReqFetch.ts → src/common/lib/ReqFetch.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
/*
* @Author: renxia
* @Date: 2024-01-15 11:26:52
* @LastEditors: renxia
* @LastEditTime: 2024-01-18 11:15:16
* @Description:
*/
import type { OutgoingHttpHeaders } from 'node:http';
import { urlFormat } from './url';
import { toLowcaseKeyObject } from './objects';
import type { AnyObject } from '../types';
import { cookieParse, cookieStringfiy } from './cookie';
import { urlFormat } from '../url';
import { toLowcaseKeyObject } from '../objects';
import type { AnyObject } from '../../types';
import { cookieParse, cookieStringfiy } from '../cookie';

interface ReqOptions extends Omit<RequestInit, 'headers'> {
headers?: OutgoingHttpHeaders;
Expand Down Expand Up @@ -93,3 +100,5 @@ export class ReqFetch extends ReqBase {
return this.request<T>('POST', url, parameters, { ...options, headers: { ...options?.headers, ...headers } });
}
}

// new ReqFetch().get('https://www.baidu.com').then(d => console.log(d.response.status, d.data.length));
3 changes: 3 additions & 0 deletions src/common/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './LRUCache';
export * from './Logger';
export * from './ReqFetch';
2 changes: 1 addition & 1 deletion src/node/get-logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { color } from 'console-log-colors';
import { NLogger } from './lib/NLogger';
import { type LogLevelType } from '../common/Logger';
import { type LogLevelType } from '../common/lib/Logger';

export function getLogger(tag = '[FEUTILS]', levelType?: LogLevelType): NLogger {
return NLogger.getLogger(tag, { levelType, color });
Expand Down
2 changes: 1 addition & 1 deletion src/node/lib/NLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { WriteStream } from 'node:fs';
import { clearScreenDown, cursorTo } from 'node:readline';
import { color } from 'console-log-colors';
import { fs } from '../fs-system';
import { Logger, type LoggerOptions } from '../../common/Logger';
import { Logger, type LoggerOptions } from '../../common/lib/Logger';

const fsStreamCache: { [logPath: string]: WriteStream } = {};

Expand Down
10 changes: 4 additions & 6 deletions src/node/lib/WXWork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
/*
* @Author: lzw
* @Date: 2021-12-24 13:01:39
* @LastEditors: lzw
* @LastEditTime: 2022-07-26 21:01:43
* @LastEditors: renxia
* @LastEditTime: 2024-01-18 10:59:55
* @Description: 企业微信机器人通知
*/

import { Request } from './request';

const api = new Request();
const webhook = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=';

export interface WxWorkReqParams {
msgtype: string;
text?: {
Expand Down Expand Up @@ -130,6 +127,7 @@ export function wxWorkNotify(params: string | WxWorkReqParams, webhookUrl: strin
return Promise.resolve({ errcode: -2, errmsg: '[wxWorkNotify][webhook]invalid format' });
}

const webhook = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=';
if (!webhookUrl.startsWith('http')) webhookUrl = webhook + webhookUrl;

if (typeof params === 'string') {
Expand All @@ -141,7 +139,7 @@ export function wxWorkNotify(params: string | WxWorkReqParams, webhookUrl: strin
};
}

return api.post<WxWorkResult>(webhookUrl, params, { 'content-type': 'application/json' }).then(d => {
return new Request().post<WxWorkResult>(webhookUrl, params, { 'content-type': 'application/json' }).then(d => {
if (debug) console.log(`[wxWorkNotify][${d.data.errcode}]`, JSON.stringify(d.data));
return d.data;
});
Expand Down
2 changes: 1 addition & 1 deletion src/node/lib/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import zlib from 'node:zlib';
import http, { type IncomingMessage, type IncomingHttpHeaders, type OutgoingHttpHeaders } from 'node:http';
import https, { type RequestOptions } from 'node:https';
import { urlFormat } from '../../common/url';
import { ReqBase } from '../../common/ReqFetch';
import { ReqBase } from '../../common/lib/ReqFetch';
import type { AnyObject } from '../../types';

export class Request extends ReqBase {
Expand Down

0 comments on commit 98942d9

Please sign in to comment.