Skip to content

Commit

Permalink
add gzip #228
Browse files Browse the repository at this point in the history
  • Loading branch information
baiy committed May 3, 2023
1 parent f6622f6 commit 2735dbb
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 11 deletions.
6 changes: 5 additions & 1 deletion packages/ctool-config/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,17 @@ export let _tools = {
feature: ['hmac'],
parent_directory: ""
},
gzip: {
feature: ['encoder', 'decoder'],
parent_directory: ""
},
} as const;

// 分类 配置
export const _categoryTool: Record<CategoryType, ToolType[]> = {
encryption: ["hash", "hmac", "aes", "des", "tripleDes", "rc4", "rabbit", "sm2", "sm4", "rsa", "sign", "base64", "bcrypt"],
check: ["sign", "regex", "diffs", "crontab", "bcrypt", "dataValidation"],
encoder_decoder: ["base64", "url", "unicode", "jwt", "hexString", "html"],
encoder_decoder: ["base64", "url", "unicode", "jwt", "hexString", "html", "gzip"],
conversion: ["json", "pinyin", "radix", "serialize", "unit", "time", "ascii", "variableConversion", "hexString", "arm", "httpSnippet", "color"],
generate: ["qrCode", "barcode", "randomString", "uuid", "binary", "ipcalc", "sqlFillParameter", "httpSnippet"],
other: ["ip", "code", "websocket", "unit", "text"]
Expand Down
13 changes: 8 additions & 5 deletions packages/ctool-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"private": true,
"scripts": {
"check": "vue-tsc --noEmit",
"dev": "pnpm run check && vite --force",
"dev": "pnpm run check && vite",
"build": "pnpm run check && vite build",
"preview": "vite preview"
},
"dependencies": {
"@codemirror/commands": "^6.1.3",
"@codemirror/language": "^6.5.0",
"@codemirror/language-data": "^6.1.0",
"@codemirror/merge": "^0.1.3",
"@codemirror/merge": "^6.0.2",
"@codemirror/search": "^6.2.3",
"@codemirror/state": "^6.2.0",
"@codemirror/view": "^6.7.3",
Expand Down Expand Up @@ -67,6 +67,7 @@
"magic-bytes.js": "^1.0.13",
"mathjs": "^11.5.1",
"netmask": "^2.0.2",
"pako": "^2.1.0",
"php-array-reader": "^1.3.4",
"pinia": "^2.0.29",
"pinia-plugin-persistedstate": "^2.4.0",
Expand Down Expand Up @@ -111,19 +112,21 @@
"@types/lodash": "^4.14.191",
"@types/netmask": "^1.0.30",
"@types/node": "^18.11.18",
"@types/pako": "^2.0.0",
"@types/prettier": "^2.7.2",
"@types/qs": "^6.9.7",
"@types/sm-crypto": "^0.3.0",
"@types/strict-uri-encode": "^2.0.0",
"@types/uuid": "^8.3.4",
"@types/valid-data-url": "^2.0.0",
"@types/ws": "^8.5.4",
"@vitejs/plugin-vue": "^4.0.0",
"@vitejs/plugin-vue": "^4.2.0",
"@vue-macros/reactivity-transform": "^0.3.4",
"@vue/runtime-core": "^3.2.45",
"typescript": "^4.9.5",
"vite": "^4.1.4",
"vite": "^4.3.3",
"vite-plugin-html-config": "^1.0.11",
"vite-plugin-node-polyfills": "^0.7.0",
"vue-tsc": "^1.2.0"
"vue-tsc": "^1.4.4"
}
}
5 changes: 5 additions & 0 deletions packages/ctool-core/src/helper/text/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ class Text {
return this._isError
}

setExtension(extension: string) {
this.fileName = `ctool-${dayjs().format('YYYY-MM-DD-HH-mm-ss')}${extension}`
return this
}

setFileName(name: string) {
this.fileName = name
return this
Expand Down
5 changes: 4 additions & 1 deletion packages/ctool-core/src/i18n/locales/en/tool.i18n.json5
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,8 @@
"dataValidation_crc": 'CRC',
"dataValidation_lrc": 'LRC',
"color": "Color",
"hmac": "HMAC"
"hmac": "HMAC",
"gzip": "GZIP",
"gzip_encoder": "Encoder",
"gzip_decoder": "Decoder",
}
5 changes: 4 additions & 1 deletion packages/ctool-core/src/i18n/locales/zh_CN/tool.i18n.json5
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,8 @@
"dataValidation_lrc": 'LRC',
"color": "颜色",
"hmac": "HMAC",
"hmac_hmac_keywords": "md5,sha1,sha256,sha512,sm3"
"hmac_hmac_keywords": "md5,sha1,sha256,sha512,sm3",
"gzip": "GZIP",
"gzip_encoder": "编码/压缩",
"gzip_decoder": "解码/解压",
}
49 changes: 49 additions & 0 deletions packages/ctool-core/src/tools/gzip/Decoder.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<HeightResize v-slot="{small,large}" :reduce="5">
<Align direction="vertical">
<TextInput
v-model="action.current.input"
:height="small"
upload="file"
:allow="['base64', 'hex', 'upload', 'url']"
encoding
/>
<TextOutput
v-model="action.current.output"
:allow="['text']"
:content="output"
:height="large"
@success="action.save()"
encoding
/>
</Align>
</HeightResize>
</template>

<script lang="ts" setup>
import {useAction, initialize} from "@/store/action"
import {createTextInput, createTextOutput} from "@/components/text"
import Text from "@/helper/text";
import pako from "pako";
const action = useAction(await initialize({
input: createTextInput('base64'),
output: createTextOutput('text'),
}))
const output = $computed(() => {
if (
action.current.input.text.isEmpty()
) {
return Text.empty()
}
if (action.current.input.text.isError()) {
return action.current.input.text
}
try {
return Text.fromUint8Array(pako.inflate(action.current.input.text.toUint8Array()))
} catch (e) {
return Text.fromError($error(e))
}
})
</script>
65 changes: 65 additions & 0 deletions packages/ctool-core/src/tools/gzip/Encoder.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<template>
<HeightResize v-slot="{small,large}" :reduce="5">
<Align direction="vertical">
<Display>
<TextInput
v-model="action.current.input"
:height="small"
upload="file"
encoding
/>
<template #extra>
<Bool v-model="action.current.deflate" label="Deflate"/>
</template>
</Display>
<TextOutput
v-model="action.current.output"
:allow="['base64','hex','down']"
:content="output"
:height="large"
@success="action.save()"
/>
</Align>
</HeightResize>
</template>

<script lang="ts" setup>
import {useAction, initialize} from "@/store/action"
import {createTextInput, createTextOutput} from "@/components/text"
import Text from "@/helper/text";
import pako from "pako";
const action = useAction(await initialize({
input: createTextInput('text'),
deflate: false,
output: createTextOutput('base64'),
}))
const output = $computed(() => {
if (
action.current.input.text.isEmpty()
) {
return Text.empty()
}
if (action.current.input.text.isError()) {
return action.current.input.text
}
try {
if (!action.current.input.text.isText()) {
throw new Error("input content must text / text file")
}
let result:Text
if (action.current.deflate) {
result = Text.fromUint8Array(pako.deflate(action.current.input.text.toUint8Array()))
}
else {
result = Text.fromUint8Array(pako.gzip(action.current.input.text.toUint8Array()))
}
result.setExtension('.gz')
return result;
} catch (e) {
return Text.fromError($error(e))
}
})
</script>
2 changes: 1 addition & 1 deletion packages/ctool-core/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference types="vite/client" />
/// <reference types="vue/macros-global" />
/// <reference types="@vue-macros/reactivity-transform/macros-global" />
declare module '*.vue' {
import type {DefineComponent} from 'vue'
const component: DefineComponent<{}, {}, any>
Expand Down
3 changes: 2 additions & 1 deletion packages/ctool-core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
],
"skipLibCheck": true,
"types": [
"node"
"node",
"@vue-macros/reactivity-transform/macros-global"
],
"paths": {
"@/*": [
Expand Down
4 changes: 3 additions & 1 deletion packages/ctool-core/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import vue from '@vitejs/plugin-vue'
import {nodePolyfills} from 'vite-plugin-node-polyfills'
import {readFileSync} from "fs";
import HtmlConfig from "vite-plugin-html-config"
import ReactivityTransform from '@vue-macros/reactivity-transform/vite'

export default defineConfig({
base: "./",
Expand All @@ -21,7 +22,8 @@ export default defineConfig({
}
]
}),
vue({reactivityTransform: true}),
vue(),
ReactivityTransform()
],
resolve: {
alias: {
Expand Down

0 comments on commit 2735dbb

Please sign in to comment.