Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/yaklang/yakit
Browse files Browse the repository at this point in the history
  • Loading branch information
v1ll4n committed May 19, 2023
2 parents 4f4f696 + b23f935 commit 41ae60e
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 33 deletions.
6 changes: 3 additions & 3 deletions app/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
initExtraLocalCache,
getExtraLocalCacheValue,
initLocalCache,
setExtraLocalCache,
setCloeseExtraLocalCache,
} = require("./localCache")
const { engineLog } = require("./filePath")
const fs = require("fs")
Expand Down Expand Up @@ -85,8 +85,8 @@ const createWindow = () => {
checkboxChecked: false,
noLink: true
})
.then((res) => {
setExtraLocalCache(UICloseFlag, !res.checkboxChecked)
.then(async(res) => {
await setCloeseExtraLocalCache(UICloseFlag, !res.checkboxChecked)
if (res.response === 0) {
e.preventDefault()
win.minimize()
Expand Down
24 changes: 24 additions & 0 deletions app/main/localCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,29 @@ function setExtraLocalCache(key, value) {
extraKVCache.set(key, value)
localCacheState.extraCacheChanged = true
}
/**
* 退出时的缓存
*/
function setCloeseExtraLocalCache(key, value){
extraKVCache.set(key, value)
return new Promise((resolve, reject) => {
try {
localCacheState.writingFile = true
const cache = extraKVCache
let value = []
cache.forEach((v, k) => {
value.push({key: k, value: v})
})
value.sort((a, b) => `${a.key}`.localeCompare(`${b.key}`))
syncLocalCacheFile(type, JSON.stringify(value))
} catch (e) {
console.info(e)
} finally {
localCacheState.writingFile = false
resolve()
}
})
}
/**
* 写操作定时器
* @param {"cache"|"extraCache"} type
Expand Down Expand Up @@ -159,6 +182,7 @@ const syncCacheToFile = (type) => {
module.exports = {
getExtraLocalCacheValue,
setExtraLocalCache,
setCloeseExtraLocalCache,
getLocalCacheValue,
setLocalCache,
initLocalCache,
Expand Down
8 changes: 4 additions & 4 deletions app/renderer/src/main/src/components/WebsiteTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export interface WebsiteTreeViewerProp {
}

export interface WebsiteForest {
size: number
trees: WebsiteNode[]
uuid: string
Size: number
Trees: WebsiteNode[]
Uuid: string
}

export interface WebsiteNode {
Expand Down Expand Up @@ -46,7 +46,7 @@ export const ConvertWebsiteForestToTreeData = (forest: WebsiteForest) => {
return antDTreeData
};

const nodes = (forest.trees || []).map(viewTree)
const nodes = (forest.Trees || []).map(viewTree)
nodes.sort((a, b) => a.title.localeCompare(b.title))
const shrinkNode = (node: AntDTreeData) => {
node.children.map(shrinkNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
YakitITextModel,
YakitEditorKeyCode,
KeyboardToFuncProps,
YakitIModelDecoration
YakitIModelDecoration,
OperationRecord,
OperationRecordRes,
OtherMenuListProps
} from "./YakitEditorType"
import {showByRightContext} from "../YakitMenu/showByRightContext"
import {ConvertYakStaticAnalyzeErrorToMarker, YakStaticAnalyzeErrorResult} from "@/utils/editorMarkers"
Expand All @@ -24,6 +27,7 @@ import {EditorMenu, EditorMenuItemDividerProps, EditorMenuItemProps, EditorMenuI
import {YakitSystem} from "@/yakitGVDefine"
import cloneDeep from "lodash/cloneDeep"
import {convertKeyboard, keySortHandle} from "./editorUtils"
import {getRemoteValue, setRemoteValue} from "@/utils/kv"

import classNames from "classnames"
import styles from "./YakitEditor.module.scss"
Expand All @@ -38,8 +42,8 @@ const keyToFontSize: Record<string, number> = {
"font-size-large": 20
}

/** 编辑器右键默认菜单 */
const DefaultMenu: EditorMenuItemType[] = [
/** 编辑器右键默认菜单 - 顶部 */
const DefaultMenuTop: EditorMenuItemType[] = [
{
key: "font-size",
label: "字体大小",
Expand All @@ -49,6 +53,10 @@ const DefaultMenu: EditorMenuItemType[] = [
{key: "font-size-large", label: "大"}
]
},
]

/** 编辑器右键默认菜单 - 底部 */
const DefaultMenuBottom: EditorMenuItemType[] = [
{key: "cut", label: "剪切"},
{key: "copy", label: "复制"},
{key: "paste", label: "粘贴"}
Expand All @@ -73,9 +81,10 @@ export const YakitEditor: React.FC<YakitEditorProps> = React.memo((props) => {
noLineNumber = false,
lineNumbersMinChars = 5,
fontSize = 12,
showLineBreaks = false
showLineBreaks = false,
editorOperationRecord
} = props

const systemRef = useRef<YakitSystem>("Darwin")
const wrapperRef = useRef<HTMLDivElement>(null)
const isInitRef = useRef<boolean>(false)
Expand All @@ -85,7 +94,7 @@ export const YakitEditor: React.FC<YakitEditorProps> = React.memo((props) => {
const preHeightRef = useRef<number>(0)

/** @name 记录右键菜单组信息 */
const rightContextMenu = useRef<EditorMenuItemType[]>([...DefaultMenu])
const rightContextMenu = useRef<EditorMenuItemType[]>([...DefaultMenuTop,...DefaultMenuBottom])
/** @name 记录右键菜单组内的快捷键对应菜单项的key值 */
const keyBindingRef = useRef<KeyboardToFuncProps>({})
/** @name 记录右键菜单关系[菜单组key值-菜单组内菜单项key值数组] */
Expand All @@ -94,14 +103,30 @@ export const YakitEditor: React.FC<YakitEditorProps> = React.memo((props) => {
const [showBreak, setShowBreak, getShowBreak] = useGetState<boolean>(showLineBreaks)
const [fontsize, setFontsize] = useState<number>(fontSize)

// 读取上次选择的字体大小/换行符
useEffect(()=>{
if(editorOperationRecord){
getRemoteValue(editorOperationRecord).then((data) => {
if (!data) return
let obj:OperationRecordRes = JSON.parse(data)
if(obj?.fontSize){
setFontsize(obj?.fontSize)
}
if(typeof obj?.showBreak === "boolean"){
setShowBreak(obj?.showBreak)
}
})
}
},[])

/**
* 整理右键菜单的对应关系
* 菜单组的key值对应的组内菜单项的key值数组
*/
useEffect(() => {
const keyToRun: Record<string, string[]> = {}
const allMenu = {...baseMenuLists, ...extraMenuLists, ...contextMenu}

for (let key in allMenu) {
const keys: string[] = []
for (let item of allMenu[key].menu) {
Expand Down Expand Up @@ -151,6 +176,25 @@ export const YakitEditor: React.FC<YakitEditorProps> = React.memo((props) => {
}),
{wait: 300}
)
/** 操作记录存储 */
const onOperationRecord = (type:"fontSize"|"showBreak",value:number|boolean) => {
if(editorOperationRecord){
getRemoteValue(editorOperationRecord).then((data) => {
if (!data) {
let obj:OperationRecord = {
[type]:value
}
setRemoteValue(editorOperationRecord,JSON.stringify(obj))
}
else{
let obj:OperationRecord = JSON.parse(data)
obj[type] = value
setRemoteValue(editorOperationRecord,JSON.stringify(obj))
}
})
}
}

/** 右键菜单功能点击回调事件 */
const onRightContextMenu = useMemoizedFn((key: string) => {
/** 获取 ITextModel 实例 */
Expand All @@ -162,10 +206,12 @@ export const YakitEditor: React.FC<YakitEditorProps> = React.memo((props) => {
case "font-size-large":
if (editor?.updateOptions) {
setFontsize(keyToFontSize[key] || 12)
onOperationRecord("fontSize",keyToFontSize[key] || 12)
}
return
case "http-show-break":
setShowBreak(!getShowBreak())
onOperationRecord("showBreak",getShowBreak())
return
case "yak-formatter":
if (!model) return
Expand Down Expand Up @@ -261,6 +307,18 @@ export const YakitEditor: React.FC<YakitEditorProps> = React.memo((props) => {
return menus
})

const sortMenuFun = useMemoizedFn((dataSource,sortData) => {
const result = sortData.reduce((acc, item) => {
if(item.order>=0){
acc.splice(item.order, 0, ...item.menu)
}
else{
acc.push(...item.menu)
}
return acc;
}, [...dataSource]);
return result
})
/** yak后缀文件中,右键菜单增加'Yak 代码格式化'功能 */
useEffect(() => {
/**
Expand All @@ -271,7 +329,7 @@ export const YakitEditor: React.FC<YakitEditorProps> = React.memo((props) => {
ipcRenderer.invoke("fetch-system-name").then((systemType: YakitSystem) => {
systemRef.current = systemType

rightContextMenu.current = [...DefaultMenu]
rightContextMenu.current = [...DefaultMenuTop]
keyBindingRef.current = {}

if (type === "http") {
Expand All @@ -294,11 +352,27 @@ export const YakitEditor: React.FC<YakitEditorProps> = React.memo((props) => {
])
}

// 缓存需要排序的自定义菜单
let sortContextMenu:OtherMenuListProps[] = []
for (let menus in contextMenu) {
/** 当cloneDeep里面存在reactnode时,执行会产生性能问题 */
rightContextMenu.current = rightContextMenu.current.concat(cloneDeep(contextMenu[menus].menu))
/* 需要排序项 */
if(typeof contextMenu[menus].order === "number"){
sortContextMenu = sortContextMenu.concat(cloneDeep(contextMenu[menus]))
}
else{
/** 当cloneDeep里面存在reactnode时,执行会产生性能问题 */
rightContextMenu.current = rightContextMenu.current.concat(cloneDeep(contextMenu[menus].menu))
}
}

// 底部默认菜单
rightContextMenu.current = rightContextMenu.current.concat([...DefaultMenuBottom])

// 当存在order项则需要排序
if(sortContextMenu.length>0){
rightContextMenu.current = sortMenuFun(rightContextMenu.current,sortContextMenu)
}

rightContextMenu.current = contextMenuKeybindingHandle("", rightContextMenu.current)

if (!forceRenderMenu) isInitRef.current = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export interface YakitEditorProps {

/** @name 是否展示换行字符(只有在[type="http"]下有效,同时可在右键菜单中关闭显示功能) */
showLineBreaks?: boolean

/** @name 配置项-操作记录(拥有此项可记录字体大小及换行符) */
editorOperationRecord?: string
}

/**
Expand All @@ -65,6 +68,8 @@ export interface OtherMenuListProps {
[key: string]: {
menu: EditorMenuItemType[]
onRun: (editor: YakitIMonacoEditor, key: string) => any
/** Order菜单权重排序 0为第一个 1为第二个... 负数统一放最后 */
order?:number
}
}

Expand Down Expand Up @@ -118,3 +123,13 @@ export enum YakitEditorKeyCode {
export interface KeyboardToFuncProps {
[key: string]: string[]
}

/** 操作记录存储 */
export interface OperationRecord {
[key: string]: number|boolean
}

export interface OperationRecordRes {
fontSize?: number
showBreak?: boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,11 @@ export const HTTPPacketYakitEditor: React.FC<HTTPPacketYakitEditor> = React.memo
}, [defaultHttps, system, originValue, contextMenu, readOnly])

return (
<YakitEditor
<YakitEditor
menuType={["code", "decode", ...rightMenuType]}
readOnly={readOnly}
contextMenu={{...rightContextMenu}}
{...restProps}
{...extraEditorProps}
></YakitEditor>
)
/>)
})
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const ReportList: React.FC<ReportListProp> = (props) => {
pagination={{
size: "small",
pageSize: pagination?.Limit || 10,
current:response.Pagination.Page,
current:typeof response.Pagination.Page === "number"? response.Pagination.Page:parseInt(response.Pagination.Page) ,
simple: true,
total,
showTotal: (i) => <Tag>{i}条历史记录</Tag>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

.check-icon {
color: var(--yakit-primary-5);

position: absolute;
right: -12px;
top: 4px;
svg {
width: 16px;
height: 16px;
Expand Down
36 changes: 27 additions & 9 deletions app/renderer/src/main/src/pages/fuzzer/HTTPFuzzerHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,37 @@ export const HTTPFuzzerHistorySelector: React.FC<HTTPFuzzerHistorySelectorProp>
bordered={false}
>
<div className={styles["history-item"]}>
<Space size={4} style={{display: "flex", flexDirection: "row"}}>
<div
style={{
display: "flex",
flexDirection: "row",
width: "100%",
gap: 4,
position: "relative"
}}
>
<div>{`ID:${i.Id}`}</div>
<YakitTag color='info'>
{!!i.Host ? i.Host : formatTimestamp(i.CreatedAt)}
</YakitTag>
<div style={{overflow: "hidden"}}>
<YakitTag
color='info'
style={{
whiteSpace: "normal",
overflow: "hidden",
textOverflow: "ellipsis",
display: "block",
lineHeight: "14px"
}}
>
{!!i.Host ? i.Host : formatTimestamp(i.CreatedAt)}
</YakitTag>
</div>

<YakitTag>{i.HTTPFlowTotal}</YakitTag>
{i.HTTPFlowSuccessCount != i.HTTPFlowTotal && (
<div style={{flex: 1, alignItems: "right", textAlign: "right"}}>
<YakitTag>成功:{i.HTTPFlowSuccessCount}</YakitTag>
</div>
<YakitTag>成功:{i.HTTPFlowSuccessCount}</YakitTag>
)}
</Space>
{currentSelectId == i.Id && <CheckIcon className={styles["check-icon"]} />}
{currentSelectId == i.Id && <CheckIcon className={styles["check-icon"]} />}
</div>
</div>
</Card>
</YakitPopover>
Expand Down
Loading

0 comments on commit 41ae60e

Please sign in to comment.