Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
missuo committed Nov 15, 2023
1 parent 378e168 commit 740e43b
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: release

on:
push:
tags:
- 'v*'
workflow_dispatch:

jobs:
Build:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- run: bash release.sh ${{ github.ref }}

- name: Release
uses: softprops/action-gh-release@v1
with:
draft: false
files: |
dist/*.bobplugin
env:
GITHUB_TOKEN: ${{ secrets.GT_Token }}

- run: rm -rf dist

- uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: main
commit_message: new release!

29 changes: 29 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version=${1#refs/tags/v}
###
# @Author: Vincent Young
# @Date: 2023-11-15 11:43:18
# @LastEditors: Vincent Young
# @LastEditTime: 2023-11-15 11:43:21
# @FilePath: /bob-plugin-universal/release.sh
# @Telegram: https://t.me/missuo
# @GitHub: https://github.com/missuo
#
# Copyright © 2023 by Vincent, All Rights Reserved.
###
zip -r -j bob-plugin-universal-$version.bobplugin src/*

sha256_universal=$(sha256sum bob-plugin-universal-$version.bobplugin | cut -d ' ' -f 1)
echo $sha256_universal

download_link="https://github.com/missuo/bob-plugin-universal/releases/download/v$version/bob-plugin-universal-$version.bobplugin"

new_version="{\"version\": \"$version\", \"desc\": \"Fix some prompt errors.\", \"sha256\": \"$sha256_universal\", \"url\": \"$download_link\", \"minBobVersion\": \"0.5.0\"}"

json_file='appcast.json'
json_data=$(cat $json_file)

updated_json=$(echo $json_data | jq --argjson new_version "$new_version" '.versions += [$new_version]')

echo $updated_json > $json_file
mkdir dist
mv *.bobplugin dist
Binary file added src/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"identifier": "me.missuo.bobplugin.universal",
"category": "translate",
"version": "1.0.0",
"name": "Universal",
"summary": "",
"author": "missuo",
"appcast": "https://github.com/missuo/bob-plugin-universal/raw/main/appcast.json",
"homepage": "https://github.com/missuo/bob-plugin-universal",
"icon": "icon.png",
"minBobVersion": "0.5.0",
"options": [
{
"identifier": "url",
"type": "text",
"title": "API Endpoint",
"defaultValue": "http://1.1.1.1:23333/translate",
"desc": "Fill in the private API address you deployed."
}
]
}
46 changes: 46 additions & 0 deletions src/lang.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* @Author: Vincent Young
* @Date: 2023-03-05 18:22:21
* @LastEditors: Vincent Young
* @LastEditTime: 2023-03-10 16:01:44
* @FilePath: /bob-plugin-deeplx/src/lang.js
* @Telegram: https://t.me/missuo
*
* Copyright © 2023 by Vincent, All Rights Reserved.
*/

var supportedLanguages = [
["auto", "auto"],
["bg", "BG"], // Bulgarian
["cs", "CS"], // Czech
["da", "DA"], // Danish
["de", "DE"], // German
["el", "EL"], // Greek
["en", "EN"], // English
["es", "ES"], // Spanish
["et", "ET"], // Estonian
["fi", "FI"], // Finnish
["fr", "FR"], // French
["hu", "HU"], // Hungarian
["id", "ID"], // Indonesian
["it", "IT"], // Italian
["ja", "JA"], // Japanese
["lt", "LT"], // Lithuanian
["lv", "LV"], // Latvian
["nl", "NL"], // Dutch
["pl", "PL"], // Polish
["pt", "PT"], // Portuguese
["ro", "RO"], // Romanian
["ru", "RU"], // Russian
["sk", "SK"], // Slovak
["sl", "SL"], // Slovenian
["sv", "SV"], // Swedish
["tr", "TR"], // Turkish
["uk", "UK"], // Ukrainian
["zh-Hans", "ZH"], // Simplified Chinese
["zh-Hant", "ZH"], // Traditional Chinese
];

exports.supportedLanguages = supportedLanguages;
exports.langMap = new Map(supportedLanguages);
exports.langMapReverse = new Map(supportedLanguages.map(([standardLang, lang]) => [lang, standardLang]));
94 changes: 94 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* @Author: Vincent Young
* @Date: 2023-08-30 11:30:27
* @LastEditors: Vincent Young
* @LastEditTime: 2023-11-15 11:42:19
* @FilePath: /bob-plugin-universal/src/main.js
* @Telegram: https://t.me/missuo
* @GitHub: https://github.com/missuo
*
* Copyright © 2023 by Vincent, All Rights Reserved.
*/

var lang = require("./lang.js");

function supportLanguages() {
return lang.supportedLanguages.map(([standardLang]) => standardLang);
}

function translate(query, completion) {
let sourceLang = "";
if (query.from === "auto") {
sourceLang = lang.langMap.get(query.detectFrom);
} else {
sourceLang = lang.langMap.get(query.from);
}
let targetLang = "";
if (query.to === "auto") {
targetLang = lang.langMap.get(query.detectTo);
} else {
targetLang = lang.langMap.get(query.to);
}

const body = JSON.stringify({
text: query.text,
source_lang: sourceLang,
target_lang: targetLang,
});
console.log(body);

(async () => {
const urls = $option.url.split(",");
const randomUrl = urls[Math.floor(Math.random() * urls.length)];
const resp = await $http.request({
method: "POST",
url: randomUrl,
header: {
'Content-Type': 'application/json'
},
body: $data.fromUTF8(body)
});
const {
statusCode
} = resp.response;

if (statusCode === 200 && resp.data.data){
completion({
result: {
from: query.detectFrom,
to: query.detectTo,
toParagraphs: resp.data.data.split('\n')
},
});
}

if (statusCode === 406) {
completion({
error: {
type: "unsupportedLanguage",
message: "Unsupported target languages",
},
});
return;
} else if (statusCode === 429) {
completion({
error: {
type: "api",
message: "Too many requests",
},
});
return;
}
})().catch(err => {
completion({
error: {
type: err._type || "unknown",
message: err._message || "未知错误",
addition: err._addition,
},
});
});
}

exports.supportLanguages = supportLanguages;
exports.translate = translate;

0 comments on commit 740e43b

Please sign in to comment.