Skip to content

Commit

Permalink
Merge pull request #19 from vicanso/main
Browse files Browse the repository at this point in the history
version 0.1.9
  • Loading branch information
vicanso authored Jun 13, 2023
2 parents d588ecb + 84e94ec commit 472041e
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 10 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable changes to this project will be documented in this file.

## [0.1.9] - 2023-06-13

### Features

- Add accept-encoding and support text content preview

### Refactor

- Adjust json format

## [0.1.8] - 2023-06-10

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ orm:
-u "sqlite:///~/Library/Application Support/com.bigtree.cyberapi/my_db.db" \
-o src/entities
version:
git cliff --unreleased --tag 0.1.8 --prepend CHANGELOG.md
git cliff --unreleased --tag 0.1.9 --prepend CHANGELOG.md
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cyberapi",
"private": true,
"version": "0.1.8",
"version": "0.1.9",
"scripts": {
"format": "prettier --write src/*.ts src/*.tsx src/**/*.ts src/**/*.tsx src/**/**/*.tsx",
"lint": "eslint . --ext .js,.tsx,.ts --fix && vue-tsc --noEmit",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cyberapi"
version = "0.1.8"
version = "0.1.9"
description = "API tool based on tauri, it is smaller and faster."
authors = ["tree.xie@outlook.com"]
license = "Apache License 2.0"
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/http_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ pub async fn request(
HeaderValue::from_str(h.value.as_str())?,
);
}
header.insert("Accept-Encoding", HeaderValue::from_str("gzip, br")?);
// 如果未设置content type
// 设置content type
if !set_content_type && !http_request.content_type.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "CyberAPI",
"version": "0.1.8"
"version": "0.1.9"
},
"tauri": {
"allowlist": {
Expand Down
7 changes: 5 additions & 2 deletions src/commands/http_response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ export function getStatusText(code: number) {
return statusTextMap.get(code.toString()) || "";
}


const mimeTextReg = /text|javascript/gi;

export function getResponseBody(resp: HTTPResponse): ResponseBodyResult {
const { headers, body } = resp;
let category = ResponseBodyCategory.Binary;
Expand All @@ -151,8 +154,8 @@ export function getResponseBody(resp: HTTPResponse): ResponseBodyResult {
json = JSON.parse(data);
isJSON = true;
// format
data = JSON.stringify(json, null, 2);
} else if (value.includes("text")) {
data = JSON.stringify(json, null, 4);
} else if (mimeTextReg.test(value)) {
category = ResponseBodyCategory.Text;
data = decode(data);
}
Expand Down
22 changes: 21 additions & 1 deletion src/components/APISettingParams/req_params.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { useSettingStore } from "../../stores/setting";
import { i18nCollection, i18nCommon } from "../../i18n";
import { CaretDownOutline, CodeSlashOutline } from "@vicons/ionicons5";
import { jsonFormat, showError, tryToParseArray } from "../../helpers/util";
import { showError, tryToParseArray } from "../../helpers/util";
import ExKeyValue, { HandleOption } from "../ExKeyValue";
import { KVParam } from "../../commands/interface";
import { padding } from "../../constants/style";
Expand Down Expand Up @@ -306,6 +306,11 @@ export default defineComponent({
showError(message, err);
}
};
const handleFormat = () => {
if (editorIns) {
editorIns.getAction("editor.action.formatDocument")?.run();
}
};

onMounted(() => {
initEditor();
Expand All @@ -322,6 +327,7 @@ export default defineComponent({
handleAuth,
handleChangeContentType,
handleUpdateActiveTab,
handleFormat,
activeTab,
codeEditor,
};
Expand Down Expand Up @@ -508,6 +514,20 @@ export default defineComponent({
ref="codeEditor"
class={codeEditorClass}
></div>
{activeTab === TabItem.Body && contentType === ContentType.JSON && (
<NButton
class="format"
quaternary
onClick={() => {
this.handleFormat();
}}
>
<NIcon>
<CodeSlashOutline />
</NIcon>
{i18nCollection("format")}
</NButton>
)}
{/* body form/multipart */}
{showBodyKeyValue && (
<ExKeyValue
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export function jsonFormat(data: string) {
if (!isJSON(item)) {
return item;
}
return JSON.stringify(JSON.parse(item), null, 2);
return JSON.stringify(JSON.parse(item), null, 4);
})
.join("\n");
}
Expand Down Expand Up @@ -228,7 +228,7 @@ export async function writeFileToDownload(file: string, data: ArrayBuffer) {
}

export async function writeSettingToDownload(arr: unknown, name: string) {
const data = JSON.stringify(arr, null, 2);
const data = JSON.stringify(arr, null, 4);
const buf = await stringToArrayBuffer(data);
await writeFileToDownload(`cyberapi-${name}.json`, buf);
}
Expand Down

0 comments on commit 472041e

Please sign in to comment.