Skip to content

Commit

Permalink
More transl srcs (#182)
Browse files Browse the repository at this point in the history
* fix issue with blank visraam #181
add manmohan singh to punjabi
fix some docker script problems

* Automatically serve any available punjabi translations

* remove lodash

* resolving issues from sttm-api repo

* fix for ceremonies

* remove lodash

* Delete package-lock.json
  • Loading branch information
ManjotS authored Jun 17, 2020
1 parent f976619 commit 8e635d3
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 10,740 deletions.
2 changes: 1 addition & 1 deletion api/config/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
mysql: {
host: '127.0.0.1',
host: process.env.DB_HOST || 'localhost',
port: process.env.DB_PORT || 3306,
user: process.env.DB_USER || 'root',
password: process.env.DB_PASSWORD || 'root',
Expand Down
39 changes: 23 additions & 16 deletions api/lib/getJSON.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const getObject = require('lodash/get');

// ceremonies and perhaps future features have ranges, meaning
// translations and translit objects are now arrays of the
// original verse structures passed as one verse
Expand Down Expand Up @@ -45,8 +43,22 @@ const reduceVisraams = (visraam, wordCount) => {
});
return accumulator;
};
/* eslint-enable no-param-reassign */

// this exists because the pu spec for v2 api looks different than data in db
const reducepuTranslations = (pu, puu) => {
const accumulator = {};
if (typeof pu === 'object') {
Object.keys(pu).forEach(i => {
accumulator[i] = {
gurmukhi: pu[i],
unicode: puu[i],
};
});
}
return accumulator;
};

/* eslint-enable no-param-reassign */
const prepVerse = (row, includeMeta = false, liveSearch = 0) => {
let translations = JSON.parse(row.Translations);
if (Array.isArray(translations)) {
Expand All @@ -60,23 +72,14 @@ const prepVerse = (row, includeMeta = false, liveSearch = 0) => {
unicode: row.GurmukhiUni,
},
larivaar: {
gurmukhi: (row.Gurmukhi || '').toString().replace(/\s+/g, ''),
unicode: (row.GurmukhiUni || '').toString().replace(/\s+/g, ''),
gurmukhi: (String(row.Gurmukhi) || '').replace(/\s+/g, ''),
unicode: (String(row.GurmukhiUni) || '').replace(/\s+/g, ''),
},
translation: {
en: {
...translations.en,
},
pu: {
ss: {
gurmukhi: getObject(translations, 'pu.ss', ''),
unicode: getObject(translations, 'puu.ss', ''),
},
ft: {
gurmukhi: getObject(translations, 'pu.ft', ''),
unicode: getObject(translations, 'puu.ft', ''),
},
},
pu: reducepuTranslations(translations.pu, translations.puu),
es: {
...translations.es,
},
Expand All @@ -99,7 +102,11 @@ const prepVerse = (row, includeMeta = false, liveSearch = 0) => {
verse.pageNo = row.PageNo;
verse.lineNo = row.LineNo;
verse.updated = row.Updated;
verse.visraam = JSON.parse(row.Visraam);
try {
verse.visraam = JSON.parse(row.Visraam);
} catch (e) {
verse.visraam = [];
}
if (Array.isArray(verse.visraam)) {
const wordCount = JSON.parse(row.WordCount || '[0]');
verse.visraam = reduceVisraams(verse.visraam, wordCount);
Expand Down
3 changes: 1 addition & 2 deletions api/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ const lib = {
},
};
if (stack === true) {
ret.data.stack = err.stack;
ret.data.stack = err.stack.split('\n');
console.error(err);
Error.captureStackTrace(err);
}
res.status(code).json(ret);
},
Expand Down
6 changes: 5 additions & 1 deletion bin/clean-up-docker-containers.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
#!/usr/bin/env bash
docker rmi khalisfoundation/banidb-dev

docker kill banidb-api
docker rm banidb-api

docker rmi khalisfoundation/banidb-dev --force
12 changes: 6 additions & 6 deletions bin/start-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
container_name=banidb-api
is_running=`docker inspect -f '{{.State.Running}}' $container_name`

if [ -z "${DB_PORT}" ]; then
if [ -z "${DB_PORT}" ]; then
dbPort=3306
else
else
dbPort=${DB_PORT}
fi

if [ -z "$is_running" ]
if [[ -z "$is_running" || "$is_running" -eq "false" ]]
then
echo "Starting docker container"
docker run -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=khajana_dev_khajana -d -p $dbPort:3306 --name $container_name khalisfoundation/banidb-dev:latest
attempt=0
while [ $attempt -le 59 ]; do
attempt=$(( $attempt + 1 ))
echo "Waiting for container to be up (attempt: $attempt)..."
result=$(docker exec banidb-api mysqladmin ping -u root -proot 2> /dev/null || echo 'fail' )
result=$(docker exec banidb-api mysqladmin ping -u root -proot 2> /dev/null || echo 'fail' )
if grep -q 'mysqld is alive' <<< $result ; then
echo "DB container is up"
echo "Waiting so connections stabalize"
echo "Waiting so connections stabilize"
break
fi
sleep 10
done
sleep 50
sleep 20
echo "~~~~Ready~~~~~~"
else
echo "Docker container is running"
Expand Down
Loading

0 comments on commit 8e635d3

Please sign in to comment.