Skip to content

Commit

Permalink
Use the default dict if available
Browse files Browse the repository at this point in the history
  • Loading branch information
SteVio89 committed Jul 16, 2024
1 parent 87fc3ce commit de47005
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ private void handleWordsRequest(HttpExchange httpExchange, Map<String, String> p
List<String> groups = null;
if (params.containsKey("dicts")) {
groups = Arrays.asList(params.get("dicts").split(","));
} else if (limits.getAccount() != null &&
limits.getAccount().getDefaultDictionary() != null &&
!limits.getAccount().getDefaultDictionary().isEmpty()) {
groups = Collections.singletonList(limits.getAccount().getDefaultDictionary());
}
long start = System.nanoTime();
List<String> words = db.getWords(limits, groups, offset, limit);
Expand All @@ -214,16 +218,23 @@ private void handleWordAddRequest(HttpExchange httpExchange, Map<String, String>
ensurePostMethod(httpExchange, "/words/add");
UserLimits limits = getUserLimits(parameters, config);
DatabaseAccess db = DatabaseAccess.getInstance();
String dict = parameters.get("dict");
if(dict == null &&
limits.getAccount() != null &&
limits.getAccount().getDefaultDictionary() != null &&
!limits.getAccount().getDefaultDictionary().isEmpty()) {
dict = limits.getAccount().getDefaultDictionary();
}
/*
* experimental batch mode for adding words,
* use mode=batch, words="word1 word2 word3" (whitespace delimited list) instead of word parameter
*/
if ("batch".equals(parameters.get("mode"))) {
List<String> words = Arrays.asList(parameters.get("words").split("\\s+"));
db.addWordBatch(words, limits.getPremiumUid(), parameters.get("dict"));
db.addWordBatch(words, limits.getPremiumUid(), dict);
writeResponse("added", true, httpExchange);
} else {
boolean added = db.addWord(parameters.get("word"), limits.getPremiumUid(), parameters.get("dict"));
boolean added = db.addWord(parameters.get("word"), limits.getPremiumUid(), dict);
writeResponse("added", added, httpExchange);
}
}
Expand Down

0 comments on commit de47005

Please sign in to comment.