Skip to content

Commit

Permalink
适配p2t 网站 api v0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Esword618 committed Jul 4, 2023
1 parent 5761577 commit b62db68
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 225 deletions.
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

6 changes: 1 addition & 5 deletions .idea/pix2text-app.iml

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

25 changes: 0 additions & 25 deletions .idea/watcherTasks.xml

This file was deleted.

21 changes: 0 additions & 21 deletions LICENSE.txt

This file was deleted.

12 changes: 3 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,13 @@ func (a *App) DomReady(ctx context.Context) {
// 在这里添加你的操作
}

// beforeClose is called when the application is about to quit,
// either by clicking the window close button or calling runtime.Quit.
// Returning true will cause the application to continue,
// false will continue shutdown as normal.
// beforeClose在单击窗口关闭按钮或调用runtime.Quit即将退出应用程序时被调用.
// BeforeClose 在单击窗口关闭按钮或调用runtime.Quit即将退出应用程序时被调用.
// 返回 true 将导致应用程序继续,false 将继续正常关闭。
func (a *App) BeforeClose(ctx context.Context) (prevent bool) {
return false
}

// shutdown is called at application termination
// Shutdown is called at application termination
// 在应用程序终止时被调用
func (a *App) Shutdown(ctx context.Context) {
// Perform your teardown here
Expand Down Expand Up @@ -106,7 +102,6 @@ func (a *App) parse() {
client := req.C()
res, err := client.R().
SetHeaders(map[string]string{
"cookie": "__atuvc=1^%^7C8; __atuvs=63f992ec1481c1e1000",
"origin": "https://p2t.behye.com",
"referer": "https://p2t.behye.com/",
"sec-ch-ua-mobile": "?0",
Expand All @@ -118,14 +113,13 @@ func (a *App) parse() {
}).
SetFileBytes("image", "image", a.file). // Set form param name and filename
SetFormData(map[string]string{ // Set form data while uploading
"session_id": "session-AiYJrY-bxFfzzCwOA9Kb4cyWfpdJnt6q",
"session_id": "",
}).
Post("https://p2t.behye.com/api/pix2text")
if err != nil {
log.Println(err)
}
result, _ := res.ToString()
//fmt.Println(result)
runtime.EventsEmit(a.ctx, "parse_result", result)
//fmt.Println("发送完成")
}
Expand Down
8 changes: 8 additions & 0 deletions build/windows/installer/wails_tools.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ RequestExecutionLevel "${REQUEST_EXECUTION_LEVEL}"
DeleteRegKey HKLM "${UNINST_KEY}"
!macroend

!macro wails.setShellContext
${If} ${REQUEST_EXECUTION_LEVEL} == "admin"
SetShellVarContext all
${else}
SetShellVarContext current
${EndIf}
!macroend

# Install webview2 by launching the bootstrapper
# See https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/distribution#online-only-deployment
!macro wails.webview2runtime
Expand Down
3 changes: 0 additions & 3 deletions frontend/.vscode/extensions.json

This file was deleted.

7 changes: 6 additions & 1 deletion frontend/src/views/about/about.vue
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ import { ElNotification } from "element-plus";
const { toClipboard } = useClipboard();
const title = ref("P2t-app V0.1.1");
const title = ref("P2t-app V0.1.2");
const drawer = ref(false);
// 公众号图片
Expand All @@ -221,6 +221,11 @@ const timeActivities = [
color: "#434de7",
timestamp: "2023.02.26",
},
{
content: "v0.1.2 发布(与官方api的返回结果适配)",
color: "#19afc9",
timestamp: "2023.07.04",
},
];
// 感谢
const thankActivities = [
Expand Down
26 changes: 9 additions & 17 deletions frontend/src/views/upload/upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,22 @@ watch(
onMounted(() => {
// 获取 go 发送过来的解析结果
EventsOn("parse_result", (message: string) => {
if (message != "") {
const v = infoHandler(message);
if (v) {
// formula.value = v.substring(2, v.length - 2);
IUserStore.formula = v;
formula.value = v;
formulaResults.value = Md.render(v);
notificationSuccess("success", "解析成功");
} else {
notificationError("error", "什么也没识别到!");
}
console.log(message);
const info = JSON.parse(message);
if (info["status_code"] == 200) {
// formula.value = v.substring(2, v.length - 2);
IUserStore.formula = info["results"];
formula.value = info["results"];
formulaResults.value = Md.render(info["results"]);
notificationSuccess("success", "解析成功");
// const v = infoHandler(message);
} else {
notificationError("error", "识别失败,请稍后重试");
}
loading.value = false;
});
});
const infoHandler = (message: string) => {
const data = JSON.parse(message);
// console.log(data);
const results = data.results;
return results.map((item: { text: any }) => item.text).join("\n");
};
// 图片重置
const resetUploadImage = () => {
Expand Down
8 changes: 8 additions & 0 deletions frontend/wailsjs/runtime/runtime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,11 @@ export function Hide(): void;
// [Show](https://wails.io/docs/reference/runtime/intro#show)
// Shows the application.
export function Show(): void;

// [ClipboardGetText](https://wails.io/docs/reference/runtime/clipboard#clipboardgettext)
// Returns the current text stored on clipboard
export function ClipboardGetText(): Promise<string>;

// [ClipboardSetText](https://wails.io/docs/reference/runtime/clipboard#clipboardsettext)
// Sets a text on the clipboard
export function ClipboardSetText(text: string): Promise<boolean>;
14 changes: 11 additions & 3 deletions frontend/wailsjs/runtime/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ export function LogFatal(message) {
}

export function EventsOnMultiple(eventName, callback, maxCallbacks) {
window.runtime.EventsOnMultiple(eventName, callback, maxCallbacks);
return window.runtime.EventsOnMultiple(eventName, callback, maxCallbacks);
}

export function EventsOn(eventName, callback) {
EventsOnMultiple(eventName, callback, -1);
return EventsOnMultiple(eventName, callback, -1);
}

export function EventsOff(eventName, ...additionalEventNames) {
return window.runtime.EventsOff(eventName, ...additionalEventNames);
}

export function EventsOnce(eventName, callback) {
EventsOnMultiple(eventName, callback, 1);
return EventsOnMultiple(eventName, callback, 1);
}

export function EventsEmit(eventName) {
Expand Down Expand Up @@ -192,3 +192,11 @@ export function Hide() {
export function Show() {
window.runtime.Show();
}

export function ClipboardGetText() {
return window.runtime.ClipboardGetText();
}

export function ClipboardSetText(text) {
return window.runtime.ClipboardSetText(text);
}
72 changes: 37 additions & 35 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
module github.com/Esword618/p2t-app

go 1.18
go 1.20

require (
github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81
github.com/imroc/req/v3 v3.32.3
github.com/wailsapp/wails/v2 v2.3.1
golang.design/x/clipboard v0.6.3
golang.org/x/image v0.0.0-20211028202545-6944b10bf410
github.com/go-latex/latex v0.0.0-20230307184459-12ec69307ad9
github.com/imroc/req/v3 v3.37.2
github.com/wailsapp/wails/v2 v2.5.1
golang.design/x/clipboard v0.7.0
golang.org/x/image v0.8.0
)

require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/bep/debounce v1.2.1 // indirect
github.com/fogleman/gg v1.3.0 // indirect
github.com/gaukas/godicttls v0.0.4 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/google/pprof v0.0.0-20230222194610-99052d3372e7 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
github.com/labstack/echo/v4 v4.9.0 // indirect
github.com/labstack/gommon v0.3.1 // indirect
github.com/leaanthony/go-ansi-parser v1.0.1 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/labstack/echo/v4 v4.10.2 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/leaanthony/go-ansi-parser v1.6.1 // indirect
github.com/leaanthony/gosod v1.0.3 // indirect
github.com/leaanthony/slicer v1.5.0 // indirect
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/onsi/ginkgo/v2 v2.8.3 // indirect
github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2 // indirect
github.com/leaanthony/slicer v1.6.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/onsi/ginkgo/v2 v2.11.0 // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-19 v0.2.1 // indirect
github.com/quic-go/qtls-go1-20 v0.1.1 // indirect
github.com/quic-go/quic-go v0.33.0 // indirect
github.com/samber/lo v1.27.1 // indirect
github.com/tkrajina/go-reflector v0.5.5 // indirect
github.com/quic-go/qtls-go1-19 v0.3.2 // indirect
github.com/quic-go/qtls-go1-20 v0.2.2 // indirect
github.com/quic-go/quic-go v0.35.1 // indirect
github.com/refraction-networking/utls v1.3.2 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/samber/lo v1.38.1 // indirect
github.com/tkrajina/go-reflector v0.5.6 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/wailsapp/mimetype v1.4.1 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/exp v0.0.0-20230223210539-50820d90acfd // indirect
golang.org/x/exp/shiny v0.0.0-20230223210539-50820d90acfd // indirect
golang.org/x/mobile v0.0.0-20210716004757-34ab1303b554 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/tools v0.6.0 // indirect
golang.org/x/crypto v0.10.0 // indirect
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
golang.org/x/exp/shiny v0.0.0-20230626212559-97b1e661b5df // indirect
golang.org/x/mobile v0.0.0-20230531173138-3c911d8e3eda // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/tools v0.10.0 // indirect
)

// replace github.com/wailsapp/wails/v2 v2.3.1 => E:\goproject\pkg\mod
Loading

0 comments on commit b62db68

Please sign in to comment.