mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-12-18 08:27:03 +02:00
Fix suggestions, move all sqlite databases to db
This commit is contained in:
parent
5a2e0fe656
commit
282737519c
@ -186,7 +186,7 @@ docker-compose -f docker-compose.cuda.yml up -d --build
|
|||||||
| --frontend-language-target | Set frontend default language - target | `es` | LT_FRONTEND_LANGUAGE_TARGET |
|
| --frontend-language-target | Set frontend default language - target | `es` | LT_FRONTEND_LANGUAGE_TARGET |
|
||||||
| --frontend-timeout | Set frontend translation timeout | `500` | LT_FRONTEND_TIMEOUT |
|
| --frontend-timeout | Set frontend translation timeout | `500` | LT_FRONTEND_TIMEOUT |
|
||||||
| --api-keys | Enable API keys database for per-user rate limits lookup | `Don't use API keys` | LT_API_KEYS |
|
| --api-keys | Enable API keys database for per-user rate limits lookup | `Don't use API keys` | LT_API_KEYS |
|
||||||
| --api-keys-db-path | Use a specific path inside the container for the local database. Can be absolute or relative | `api_keys.db` | LT_API_KEYS_DB_PATH |
|
| --api-keys-db-path | Use a specific path inside the container for the local database. Can be absolute or relative | `db/api_keys.db` | LT_API_KEYS_DB_PATH |
|
||||||
| --api-keys-remote | Use this remote endpoint to query for valid API keys instead of using the local database | `Use local API key database` | LT_API_KEYS_REMOTE |
|
| --api-keys-remote | Use this remote endpoint to query for valid API keys instead of using the local database | `Use local API key database` | LT_API_KEYS_REMOTE |
|
||||||
| --get-api-key-link | Show a link in the UI where to direct users to get an API key | `Don't show a link` | LT_GET_API_KEY_LINK |
|
| --get-api-key-link | Show a link in the UI where to direct users to get an API key | `Don't show a link` | LT_GET_API_KEY_LINK |
|
||||||
| --require-api-key-origin | Require use of an API key for programmatic access to the API, unless the request origin matches this domain | `No restrictions on domain origin` | LT_REQUIRE_API_KEY_ORIGIN |
|
| --require-api-key-origin | Require use of an API key for programmatic access to the API, unless the request origin matches this domain | `No restrictions on domain origin` | LT_REQUIRE_API_KEY_ORIGIN |
|
||||||
|
@ -10,6 +10,14 @@ DEFAULT_DB_PATH = DEFARGS['API_KEYS_DB_PATH']
|
|||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
def __init__(self, db_path=DEFAULT_DB_PATH, max_cache_len=1000, max_cache_age=30):
|
def __init__(self, db_path=DEFAULT_DB_PATH, max_cache_len=1000, max_cache_age=30):
|
||||||
|
# Legacy check - this can be removed at some point in the near future
|
||||||
|
if os.path.isfile("api_keys.db") and not os.path.isfile("db/api_keys.db"):
|
||||||
|
print("Migrating %s to %s" % ("api_keys.db", "db/api_keys.db"))
|
||||||
|
try:
|
||||||
|
os.rename("api_keys.db", "db/api_keys.db")
|
||||||
|
except Exception as e:
|
||||||
|
print(str(e))
|
||||||
|
|
||||||
db_dir = os.path.dirname(db_path)
|
db_dir = os.path.dirname(db_path)
|
||||||
if not db_dir == "" and not os.path.exists(db_dir):
|
if not db_dir == "" and not os.path.exists(db_dir):
|
||||||
os.makedirs(db_dir)
|
os.makedirs(db_dir)
|
||||||
|
@ -113,7 +113,7 @@ _default_options_objects = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'API_KEYS_DB_PATH',
|
'name': 'API_KEYS_DB_PATH',
|
||||||
'default_value': 'api_keys.db',
|
'default_value': 'db/api_keys.db',
|
||||||
'value_type': 'str'
|
'value_type': 'str'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -88,6 +88,8 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||||||
langsRequest.send();
|
langsRequest.send();
|
||||||
},
|
},
|
||||||
updated: function(){
|
updated: function(){
|
||||||
|
if (this.isSuggesting) return;
|
||||||
|
|
||||||
M.FormSelect.init(this.$refs.sourceLangDropdown);
|
M.FormSelect.init(this.$refs.sourceLangDropdown);
|
||||||
M.FormSelect.init(this.$refs.targetLangDropdown);
|
M.FormSelect.init(this.$refs.targetLangDropdown);
|
||||||
|
|
||||||
@ -283,11 +285,14 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||||||
this.savedTanslatedText = this.translatedText
|
this.savedTanslatedText = this.translatedText
|
||||||
|
|
||||||
this.isSuggesting = true;
|
this.isSuggesting = true;
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.$refs.translatedTextarea.focus();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
closeSuggestTranslation: function(e) {
|
closeSuggestTranslation: function(e) {
|
||||||
if(this.isSuggesting) {
|
if(this.isSuggesting) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.translatedText = this.savedTanslatedText
|
// this.translatedText = this.savedTanslatedText
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isSuggesting = false;
|
this.isSuggesting = false;
|
||||||
@ -312,7 +317,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||||||
try{
|
try{
|
||||||
var res = JSON.parse(this.response);
|
var res = JSON.parse(this.response);
|
||||||
if (res.success){
|
if (res.success){
|
||||||
M.toast({html: 'Thanks for your correction.'})
|
M.toast({html: 'Thanks for your correction. Note the suggestion will not take effect right away.'})
|
||||||
self.closeSuggestTranslation(e)
|
self.closeSuggestTranslation(e)
|
||||||
}else{
|
}else{
|
||||||
throw new Error(res.error || "Unknown error");
|
throw new Error(res.error || "Unknown error");
|
||||||
|
@ -1,12 +1,21 @@
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
|
import os
|
||||||
|
|
||||||
from expiringdict import ExpiringDict
|
from expiringdict import ExpiringDict
|
||||||
|
|
||||||
DEFAULT_DB_PATH = "suggestions.db"
|
DEFAULT_DB_PATH = "db/suggestions.db"
|
||||||
|
|
||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
def __init__(self, db_path=DEFAULT_DB_PATH, max_cache_len=1000, max_cache_age=30):
|
def __init__(self, db_path=DEFAULT_DB_PATH, max_cache_len=1000, max_cache_age=30):
|
||||||
|
# Legacy check - this can be removed at some point in the near future
|
||||||
|
if os.path.isfile("suggestions.db") and not os.path.isfile("db/suggestions.db"):
|
||||||
|
print("Migrating %s to %s" % ("suggestions.db", "db/suggestions.db"))
|
||||||
|
try:
|
||||||
|
os.rename("suggestions.db", "db/suggestions.db")
|
||||||
|
except Exception as e:
|
||||||
|
print(str(e))
|
||||||
|
|
||||||
self.db_path = db_path
|
self.db_path = db_path
|
||||||
self.cache = ExpiringDict(max_len=max_cache_len, max_age_seconds=max_cache_age)
|
self.cache = ExpiringDict(max_len=max_cache_len, max_age_seconds=max_cache_age)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user