Commit 60bc5e50ce2ce0c77998358c1c65df330d024eea
1 parent
6df1a3ec
Exists in
coppe
Atualizações de Volume e correção da rotina do Corretor de sinais
Showing
12 changed files
with
1203 additions
and
236 deletions
Show diff stats
Dockerfile
@@ -80,11 +80,17 @@ RUN mkdir /home/vlibras/container | @@ -80,11 +80,17 @@ RUN mkdir /home/vlibras/container | ||
80 | 80 | ||
81 | WORKDIR /home/vlibras/container/ | 81 | WORKDIR /home/vlibras/container/ |
82 | 82 | ||
83 | -#RUN wget http://150.165.205.38:8000/vlibras-wikilibras-container.zip | ||
84 | - | ||
85 | -#RUN unzip vlibras-wikilibras-container.zip | ||
86 | - | ||
87 | -ADD . /home/vlibras/container/ | 83 | +ADD corretor_sinais/ /home/vlibras/container/corretor_sinais/ |
84 | +ADD validador_sinais/ /home/vlibras/container/validador_sinais | ||
85 | +ADD pybossa /home/vlibras/container/pybossa/ | ||
86 | +ADD wikilibrasV2 /home/vlibras/container/wikilibrasV2/ | ||
87 | +ADD wikilibras-front /home/vlibras/container/wikilibras-front/ | ||
88 | +ADD wikilibras-core /home/vlibras/container/wikilibras-core/ | ||
89 | +ADD wikilibras-api /home/vlibras/container/wikilibras-api/ | ||
90 | +ADD wikilibrasdbapi /home/vlibras/container/wikilibrasdbapi/ | ||
91 | +ADD wikilibras-pybossa.sql /home/vlibras/container/ | ||
92 | +ADD Makefile /home/vlibras/container/ | ||
93 | +ADD taskmgr /home/vlibras/container/taskmgr | ||
88 | 94 | ||
89 | RUN chown -R vlibras /home/vlibras/container/ | 95 | RUN chown -R vlibras /home/vlibras/container/ |
90 | 96 | ||
@@ -126,7 +132,7 @@ RUN sudo apt-get install mongodb -y | @@ -126,7 +132,7 @@ RUN sudo apt-get install mongodb -y | ||
126 | 132 | ||
127 | RUN make install | 133 | RUN make install |
128 | 134 | ||
129 | -RUN ( sudo service postgresql start & sleep 1m ) ; make create-db | 135 | +RUN ( sudo service postgresql start & sleep 1m ) ; make create-db ; ( sudo service postgresql stop & sleep 1m ) |
130 | 136 | ||
131 | WORKDIR /home/vlibras/container/taskmgr/ | 137 | WORKDIR /home/vlibras/container/taskmgr/ |
132 | 138 | ||
@@ -136,9 +142,9 @@ WORKDIR /home/vlibras/container/ | @@ -136,9 +142,9 @@ WORKDIR /home/vlibras/container/ | ||
136 | 142 | ||
137 | RUN make config KEY=2324bc23-7d6f-4840-8905-b1e6c1675eed | 143 | RUN make config KEY=2324bc23-7d6f-4840-8905-b1e6c1675eed |
138 | 144 | ||
139 | -WORKDIR /home/vlibras/container/pybossa/ | 145 | +WORKDIR /home/vlibras/container/ |
140 | 146 | ||
141 | -RUN ( sudo service postgresql start & sleep 3m ) ; sudo su postgres -c 'psql --set ON_ERROR_STOP=off -f /home/vlibras/container/wikilibras-pybossa.sql pybossa' | 147 | +RUN ( sudo service postgresql start & sleep 3m ) ; sudo su postgres -c 'psql --set ON_ERROR_STOP=off -f /home/vlibras/container/wikilibras-pybossa.sql pybossa' ; ( sudo service postgresql stop & sleep 1m ) |
142 | 148 | ||
143 | RUN sudo apt-get install nano git htop -y | 149 | RUN sudo apt-get install nano git htop -y |
144 | 150 |
Makefile
@@ -67,6 +67,14 @@ config: $(notdir ${VLIBRAS_WIKILIBRAS_ENV}) | @@ -67,6 +67,14 @@ config: $(notdir ${VLIBRAS_WIKILIBRAS_ENV}) | ||
67 | @ $(MAKE) -s apache | 67 | @ $(MAKE) -s apache |
68 | @ $(MAKE) -s showip | 68 | @ $(MAKE) -s showip |
69 | 69 | ||
70 | +start-up: | ||
71 | + @ while ! sudo service supervisor restart; do echo "fail, retrying ..."; done | ||
72 | + @ sudo supervisorctl restart rq-scheduler | ||
73 | + @ sudo supervisorctl restart rq-worker | ||
74 | + @ sudo supervisorctl restart pybossa | ||
75 | + @ sudo service apache2 restart | ||
76 | + @ sudo service apache2 reload | ||
77 | + | ||
70 | apache: | 78 | apache: |
71 | @ sudo service apache2 start | 79 | @ sudo service apache2 start |
72 | @ if [ -e /etc/apache2/sites-enabled/pybossa.conf ]; then sudo a2dissite pybossa.conf; fi | 80 | @ if [ -e /etc/apache2/sites-enabled/pybossa.conf ]; then sudo a2dissite pybossa.conf; fi |
@@ -0,0 +1,35 @@ | @@ -0,0 +1,35 @@ | ||
1 | +version: '2' | ||
2 | + | ||
3 | +services: | ||
4 | + web: | ||
5 | + build: | ||
6 | + context: . | ||
7 | + args: | ||
8 | + - IP=150.165.205.99 | ||
9 | + ports: | ||
10 | + - "80:80" | ||
11 | + - "18422" | ||
12 | + - "5432" | ||
13 | + - "6379" | ||
14 | + - "27017" | ||
15 | + - "200:200" | ||
16 | + - "201:201" | ||
17 | + - "8003:8003" | ||
18 | + - "8001:8001" | ||
19 | + - "8002:8002" | ||
20 | + stdin_open: true | ||
21 | + tty: true | ||
22 | + volumes: | ||
23 | + - /home/vlibras/container/wikilibrasdbapi/blender/ | ||
24 | + - /home/vlibras/container/wikilibrasdbapi/sinais/ | ||
25 | + - /home/vlibras/container/wikilibrasdbapi/avatar/ | ||
26 | + - /var/log/apache2/ | ||
27 | + - /var/lib/mongodb/ | ||
28 | + - /home/vlibras/container/wikilibrasV2/view/videos/ | ||
29 | + - /home/vlibras/container/corretor_sinais/view/videos/ | ||
30 | + - /home/vlibras/container/validador_sinais/view/videos/ | ||
31 | + - /home/vlibras/container/wikilibrasV2/view/uploads/ | ||
32 | + - /home/vlibras/container/corretor_sinais/view/uploads/ | ||
33 | + - /home/vlibras/container/validador_sinais/view/uploads/ | ||
34 | + #- /home/vlibras/container/taskmgr/events.log | ||
35 | + - /home/vlibras/container/wikilibras-core/users/ |
docker-compose.yml.example
@@ -17,3 +17,17 @@ services: | @@ -17,3 +17,17 @@ services: | ||
17 | - "8003" | 17 | - "8003" |
18 | stdin_open: true | 18 | stdin_open: true |
19 | tty: true | 19 | tty: true |
20 | + volumes: | ||
21 | + - /home/vlibras/container/wikilibrasdbapi/blender/ | ||
22 | + - /home/vlibras/container/wikilibrasdbapi/sinais/ | ||
23 | + - /home/vlibras/container/wikilibrasdbapi/avatar/ | ||
24 | + - /var/log/apache2/ | ||
25 | + - /var/lib/mongodb/ | ||
26 | + - /home/vlibras/container/wikilibrasV2/view/videos/ | ||
27 | + - /home/vlibras/container/corretor_sinais/view/videos/ | ||
28 | + - /home/vlibras/container/validador_sinais/view/videos/ | ||
29 | + - /home/vlibras/container/wikilibrasV2/view/uploads/ | ||
30 | + - /home/vlibras/container/corretor_sinais/view/uploads/ | ||
31 | + - /home/vlibras/container/validador_sinais/view/uploads/ | ||
32 | + #- /home/vlibras/container/taskmgr/events.log | ||
33 | + - /home/vlibras/container/wikilibras-core/users/ |
docker-compose.yml.template
@@ -17,3 +17,17 @@ services: | @@ -17,3 +17,17 @@ services: | ||
17 | - "8003" | 17 | - "8003" |
18 | stdin_open: true | 18 | stdin_open: true |
19 | tty: true | 19 | tty: true |
20 | + volumes: | ||
21 | + - /home/vlibras/container/wikilibrasdbapi/blender/ | ||
22 | + - /home/vlibras/container/wikilibrasdbapi/sinais/ | ||
23 | + - /home/vlibras/container/wikilibrasdbapi/avatar/ | ||
24 | + - /var/log/apache2/ | ||
25 | + - /var/lib/mongodb/ | ||
26 | + - /home/vlibras/container/wikilibrasV2/view/videos/ | ||
27 | + - /home/vlibras/container/corretor_sinais/view/videos/ | ||
28 | + - /home/vlibras/container/validador_sinais/view/videos/ | ||
29 | + - /home/vlibras/container/wikilibrasV2/view/uploads/ | ||
30 | + - /home/vlibras/container/corretor_sinais/view/uploads/ | ||
31 | + - /home/vlibras/container/validador_sinais/view/uploads/ | ||
32 | + #- /home/vlibras/container/taskmgr/events.log | ||
33 | + - /home/vlibras/container/wikilibras-core/users/ |
@@ -0,0 +1,141 @@ | @@ -0,0 +1,141 @@ | ||
1 | +PROJECT_NAME := pybossa | ||
2 | +PROJECT_DIR := $(CURDIR) | ||
3 | +SED_REPLACE_ALL = sed -i "s/$(1)/$(2)/g" "$(3)" | ||
4 | +SED_REPLACE_ALL_PATH = sed -i "s\#$(1)\#$(2)\#g" "$(3)" | ||
5 | + | ||
6 | +ifndef IP | ||
7 | + ifneq ($(shell ip route | grep "default" | awk '{print $$5; exit}'),) | ||
8 | + IP := $(shell ip route get 1 | awk '{print $$7; exit}') | ||
9 | + else | ||
10 | + IP := 127.0.0.1 | ||
11 | + endif | ||
12 | +endif | ||
13 | + | ||
14 | +LOCALHOST ?= ${IP} | ||
15 | + | ||
16 | +install: .install config build | ||
17 | + | ||
18 | +build: env create-db | ||
19 | + @ sudo chown redis:redis /etc/redis/redis.conf | ||
20 | + @ sudo chown redis:redis /etc/redis/sentinel.conf | ||
21 | + @ sudo service redis-server stop | ||
22 | + @ sudo update-rc.d -f redis-server remove | ||
23 | + @ while ! sudo service supervisor restart; do echo "fail, retrying ..."; done | ||
24 | + @ sudo supervisorctl restart rq-scheduler | ||
25 | + @ sudo supervisorctl restart rq-worker | ||
26 | + @ sudo supervisorctl restart pybossa | ||
27 | + | ||
28 | +clean: | ||
29 | + @ find . -regextype posix-awk -regex "(.*.log|.*.pyc)" -type f -print -delete | ||
30 | + | ||
31 | +config: | ||
32 | + @ cp ./alembic.ini.template ./alembic.ini | ||
33 | + @ cp ./settings_local.py.tmpl ./settings_local.py | ||
34 | + @ cp ./contrib/pybossa.wsgi.tmpl ./contrib/pybossa.wsgi | ||
35 | + @ cp ./contrib/apache/pybossa.conf.tmpl ./contrib/apache/pybossa.conf | ||
36 | + @ cp ./contrib/pybossa.ini.template ./contrib/pybossa.ini | ||
37 | + @ cp ./contrib/supervisor/rq-scheduler.conf.template ./contrib/supervisor/rq-scheduler.conf | ||
38 | + @ cp ./contrib/supervisor/rq-worker.conf.template ./contrib/supervisor/rq-worker.conf | ||
39 | + @ cp ./contrib/supervisor/pybossa.conf.template ./contrib/supervisor/pybossa.conf | ||
40 | + @ ln -sf ./pybossa/themes/default/translations/ ./pybossa/translations | ||
41 | + @ $(call SED_REPLACE_ALL_PATH,<path-to-project>,$(CURDIR),./contrib/pybossa.wsgi) | ||
42 | + @ $(call SED_REPLACE_ALL,ServerName localhost,ServerName ${LOCALHOST},./contrib/apache/pybossa.conf) | ||
43 | + @ $(call SED_REPLACE_ALL,user1,$$USER,./contrib/apache/pybossa.conf) | ||
44 | + @ $(call SED_REPLACE_ALL,group1,$$USER,./contrib/apache/pybossa.conf) | ||
45 | + @ $(call SED_REPLACE_ALL_PATH,<path-to-project>,$(CURDIR),./contrib/apache/pybossa.conf) | ||
46 | + @ $(call SED_REPLACE_ALL_PATH,/home/pybossa/pybossa,$(CURDIR),./contrib/pybossa.ini) | ||
47 | + @ $(call SED_REPLACE_ALL_PATH,/home/pybossa/pybossa,$(CURDIR),./contrib/supervisor/rq-scheduler.conf) | ||
48 | + @ $(call SED_REPLACE_ALL,user=pybossa,user=$$USER,./contrib/supervisor/rq-scheduler.conf) | ||
49 | + @ $(call SED_REPLACE_ALL_PATH,/home/pybossa/pybossa,$(CURDIR),./contrib/supervisor/rq-worker.conf) | ||
50 | + @ $(call SED_REPLACE_ALL,user=pybossa,user=$$USER,./contrib/supervisor/rq-worker.conf) | ||
51 | + @ $(call SED_REPLACE_ALL_PATH,/home/pybossa/pybossa,$(CURDIR),./contrib/supervisor/pybossa.conf) | ||
52 | + @ $(call SED_REPLACE_ALL_PATH,pybossa.ini,contrib/pybossa.ini,./contrib/supervisor/pybossa.conf) | ||
53 | + @ $(call SED_REPLACE_ALL,user=pybossa,user=$$USER,./contrib/supervisor/pybossa.conf) | ||
54 | + @ sudo install -m 755 -p ./contrib/apache/pybossa.conf /etc/apache2/sites-available/pybossa.conf | ||
55 | + @ sudo install -m 644 -p ./contrib/redis-supervisor/redis.conf /etc/redis/redis.conf | ||
56 | + @ sudo install -m 644 -p ./contrib/redis-supervisor/sentinel.conf /etc/redis/sentinel.conf | ||
57 | + @ sudo install -m 644 -p ./contrib/supervisor/pybossa.conf /etc/supervisor/conf.d/pybossa.conf | ||
58 | + @ sudo install -m 644 -p ./contrib/supervisor/redis-sentinel.conf /etc/supervisor/conf.d/redis-sentinel.conf | ||
59 | + @ sudo install -m 644 -p ./contrib/supervisor/redis-server.conf /etc/supervisor/conf.d/redis-server.conf | ||
60 | + @ sudo install -m 644 -p ./contrib/supervisor/rq-scheduler.conf /etc/supervisor/conf.d/rq-scheduler.conf | ||
61 | + @ sudo install -m 644 -p ./contrib/supervisor/rq-worker.conf /etc/supervisor/conf.d/rq-worker.conf | ||
62 | + @ cat /etc/apache2/sites-available/pybossa.conf | ||
63 | + @ ([ -e /etc/apache2/sites-enabled/wikilibras.conf ] && sudo a2dissite wikilibras.conf) || sudo a2ensite pybossa.conf | ||
64 | + @ sudo service apache2 restart | ||
65 | + @ sudo service apache2 reload | ||
66 | + | ||
67 | +env: | ||
68 | + @ ( \ | ||
69 | + virtualenv ./env/; \ | ||
70 | + . ./env/bin/activate; \ | ||
71 | + pip install -U pip; \ | ||
72 | + pip install -U uwsgi; \ | ||
73 | + pip install -U ndg-httpsclient; \ | ||
74 | + pip install -r requirements.txt; \ | ||
75 | + ) | ||
76 | + | ||
77 | + | ||
78 | +start-up: | ||
79 | + @ while ! sudo service supervisor restart; do echo "fail, retrying ..."; done | ||
80 | + @ sudo supervisorctl restart rq-scheduler | ||
81 | + @ sudo supervisorctl restart rq-worker | ||
82 | + @ sudo supervisorctl restart pybossa | ||
83 | + @ sudo service apache2 restart | ||
84 | + @ sudo service apache2 reload | ||
85 | + | ||
86 | +uninstall: clean | ||
87 | + @ rm -rf ./env/ | ||
88 | + @ rm -f ./settings_local.py | ||
89 | + @ rm -f ./contrib/${PROJECT_NAME}.wsgi | ||
90 | + @ rm -f ./contrib/apache/${PROJECT_NAME}.conf | ||
91 | + @ sudo rm -f /etc/apache2/sites-available/${PROJECT_NAME}.conf | ||
92 | + @ sudo rm -f /etc/apache2/sites-enabled/${PROJECT_NAME}.conf | ||
93 | + | ||
94 | +run: | ||
95 | + @ ( \ | ||
96 | + . ./env/bin/activate; \ | ||
97 | + python main.py; \ | ||
98 | + ) | ||
99 | + | ||
100 | +.install: | ||
101 | + @ sudo apt-get update && \ | ||
102 | + sudo apt-get install -y git-core \ | ||
103 | + postgresql postgresql-server-dev-all libpq-dev python-psycopg2 \ | ||
104 | + python-virtualenv \ | ||
105 | + python-dev build-essential libjpeg-dev libssl-dev swig libffi-dev \ | ||
106 | + redis-server \ | ||
107 | + supervisor \ | ||
108 | + apache2 apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapache2-mod-wsgi | ||
109 | + @ echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/servername.conf | ||
110 | + @ sudo a2enconf servername | ||
111 | + @ sudo a2enmod headers | ||
112 | + -@ sudo a2dissite 000-default.conf | ||
113 | + | ||
114 | +PYBOSSA_DB_USERNAME := pybossa | ||
115 | +PYBOSSA_DB_PASSWORD := tester | ||
116 | +PYBOSSA_DB_CREATE := psql -c \"CREATE USER pybossa WITH PASSWORD '${PYBOSSA_DB_PASSWORD}'\"; | ||
117 | +PYBOSSA_DB_CREATE += psql -c \"CREATE DATABASE pybossa OWNER ${PYBOSSA_DB_USERNAME}\"; | ||
118 | +PYBOSSA_DB_DROP := psql -c \"DROP DATABASE ${PYBOSSA_DB_USERNAME}\"; | ||
119 | +PYBOSSA_DB_DROP += psql -c \"DROP USER ${PYBOSSA_DB_USERNAME}\"; | ||
120 | +PYBOSSA_DB_DUMPFILE := pybossa-dump.sql | ||
121 | +PYBOSSA_DB_VERBOSE := -v | ||
122 | +PYBOSSA_DB_ADMINFILE := wikilibras-pybossa.sql | ||
123 | + | ||
124 | +.postgresql: | ||
125 | + -@ sudo service postgresql restart | ||
126 | + | ||
127 | +create-db: .postgresql env | ||
128 | + @ sudo su postgres -c "${PYBOSSA_DB_CREATE}" | ||
129 | + @ ( \ | ||
130 | + . ./env/bin/activate; \ | ||
131 | + python cli.py db_create; \ | ||
132 | + ) | ||
133 | + | ||
134 | +create-admin: | ||
135 | + @ sudo su postgres -c "psql --set ON_ERROR_STOP=off -f ${PYBOSSA_DB_ADMINFILE} ${PYBOSSA_DB_USERNAME}" | ||
136 | + | ||
137 | +drop-db: .postgresql | ||
138 | + @ sudo su postgres -c "${PYBOSSA_DB_DROP}" | ||
139 | + | ||
140 | +${PYBOSSA_DB_DUMPFILE}: | ||
141 | + @ sudo su postgres -c "PGPASSWORD='${PYBOSSA_DB_PASSWORD}' pg_dump ${PYBOSSA_DB_VERBOSE} -b --inserts ${PYBOSSA_DB_USERNAME};" > ${PYBOSSA_DB_DUMPFILE} |
pybossa/Makefile.old
@@ -1,133 +0,0 @@ | @@ -1,133 +0,0 @@ | ||
1 | -PROJECT_NAME := pybossa | ||
2 | -PROJECT_DIR := $(CURDIR) | ||
3 | -SED_REPLACE_ALL = sed -i "s/$(1)/$(2)/g" "$(3)" | ||
4 | -SED_REPLACE_ALL_PATH = sed -i "s\#$(1)\#$(2)\#g" "$(3)" | ||
5 | - | ||
6 | -ifndef IP | ||
7 | - ifneq ($(shell ip route | grep "default" | awk '{print $$5; exit}'),) | ||
8 | - IP := $(shell ip route get 1 | awk '{print $$7; exit}') | ||
9 | - else | ||
10 | - IP := 127.0.0.1 | ||
11 | - endif | ||
12 | -endif | ||
13 | - | ||
14 | -LOCALHOST ?= ${IP} | ||
15 | - | ||
16 | -install: .install config build | ||
17 | - | ||
18 | -build: env create-db | ||
19 | - @ sudo chown redis:redis /etc/redis/redis.conf | ||
20 | - @ sudo chown redis:redis /etc/redis/sentinel.conf | ||
21 | - @ sudo service redis-server stop | ||
22 | - @ sudo update-rc.d -f redis-server remove | ||
23 | - @ while ! sudo service supervisor restart; do echo "fail, retrying ..."; done | ||
24 | - @ sudo supervisorctl restart rq-scheduler | ||
25 | - @ sudo supervisorctl restart rq-worker | ||
26 | - @ sudo supervisorctl restart pybossa | ||
27 | - | ||
28 | -clean: | ||
29 | - @ find . -regextype posix-awk -regex "(.*.log|.*.pyc)" -type f -print -delete | ||
30 | - | ||
31 | -config: | ||
32 | - @ cp ./alembic.ini.template ./alembic.ini | ||
33 | - @ cp ./settings_local.py.tmpl ./settings_local.py | ||
34 | - @ cp ./contrib/pybossa.wsgi.tmpl ./contrib/pybossa.wsgi | ||
35 | - @ cp ./contrib/apache/pybossa.conf.tmpl ./contrib/apache/pybossa.conf | ||
36 | - @ cp ./contrib/pybossa.ini.template ./contrib/pybossa.ini | ||
37 | - @ cp ./contrib/supervisor/rq-scheduler.conf.template ./contrib/supervisor/rq-scheduler.conf | ||
38 | - @ cp ./contrib/supervisor/rq-worker.conf.template ./contrib/supervisor/rq-worker.conf | ||
39 | - @ cp ./contrib/supervisor/pybossa.conf.template ./contrib/supervisor/pybossa.conf | ||
40 | - @ ln -sf ./pybossa/themes/default/translations/ ./pybossa/translations | ||
41 | - @ $(call SED_REPLACE_ALL_PATH,<path-to-project>,$(CURDIR),./contrib/pybossa.wsgi) | ||
42 | - @ $(call SED_REPLACE_ALL,ServerName localhost,ServerName ${LOCALHOST},./contrib/apache/pybossa.conf) | ||
43 | - @ $(call SED_REPLACE_ALL,user1,$$USER,./contrib/apache/pybossa.conf) | ||
44 | - @ $(call SED_REPLACE_ALL,group1,$$USER,./contrib/apache/pybossa.conf) | ||
45 | - @ $(call SED_REPLACE_ALL_PATH,<path-to-project>,$(CURDIR),./contrib/apache/pybossa.conf) | ||
46 | - @ $(call SED_REPLACE_ALL_PATH,/home/pybossa/pybossa,$(CURDIR),./contrib/pybossa.ini) | ||
47 | - @ $(call SED_REPLACE_ALL_PATH,/home/pybossa/pybossa,$(CURDIR),./contrib/supervisor/rq-scheduler.conf) | ||
48 | - @ $(call SED_REPLACE_ALL,user=pybossa,user=$$USER,./contrib/supervisor/rq-scheduler.conf) | ||
49 | - @ $(call SED_REPLACE_ALL_PATH,/home/pybossa/pybossa,$(CURDIR),./contrib/supervisor/rq-worker.conf) | ||
50 | - @ $(call SED_REPLACE_ALL,user=pybossa,user=$$USER,./contrib/supervisor/rq-worker.conf) | ||
51 | - @ $(call SED_REPLACE_ALL_PATH,/home/pybossa/pybossa,$(CURDIR),./contrib/supervisor/pybossa.conf) | ||
52 | - @ $(call SED_REPLACE_ALL_PATH,pybossa.ini,contrib/pybossa.ini,./contrib/supervisor/pybossa.conf) | ||
53 | - @ $(call SED_REPLACE_ALL,user=pybossa,user=$$USER,./contrib/supervisor/pybossa.conf) | ||
54 | - @ sudo install -m 755 -p ./contrib/apache/pybossa.conf /etc/apache2/sites-available/pybossa.conf | ||
55 | - @ sudo install -m 644 -p ./contrib/redis-supervisor/redis.conf /etc/redis/redis.conf | ||
56 | - @ sudo install -m 644 -p ./contrib/redis-supervisor/sentinel.conf /etc/redis/sentinel.conf | ||
57 | - @ sudo install -m 644 -p ./contrib/supervisor/pybossa.conf /etc/supervisor/conf.d/pybossa.conf | ||
58 | - @ sudo install -m 644 -p ./contrib/supervisor/redis-sentinel.conf /etc/supervisor/conf.d/redis-sentinel.conf | ||
59 | - @ sudo install -m 644 -p ./contrib/supervisor/redis-server.conf /etc/supervisor/conf.d/redis-server.conf | ||
60 | - @ sudo install -m 644 -p ./contrib/supervisor/rq-scheduler.conf /etc/supervisor/conf.d/rq-scheduler.conf | ||
61 | - @ sudo install -m 644 -p ./contrib/supervisor/rq-worker.conf /etc/supervisor/conf.d/rq-worker.conf | ||
62 | - @ cat /etc/apache2/sites-available/pybossa.conf | ||
63 | - @ ([ -e /etc/apache2/sites-enabled/wikilibras.conf ] && sudo a2dissite wikilibras.conf) || sudo a2ensite pybossa.conf | ||
64 | - @ sudo service apache2 restart | ||
65 | - @ sudo service apache2 reload | ||
66 | - | ||
67 | -env: | ||
68 | - @ ( \ | ||
69 | - virtualenv ./env/; \ | ||
70 | - . ./env/bin/activate; \ | ||
71 | - pip install -U pip; \ | ||
72 | - pip install -U uwsgi; \ | ||
73 | - pip install -U ndg-httpsclient; \ | ||
74 | - pip install -r requirements.txt; \ | ||
75 | - ) | ||
76 | - | ||
77 | - | ||
78 | -uninstall: clean | ||
79 | - @ rm -rf ./env/ | ||
80 | - @ rm -f ./settings_local.py | ||
81 | - @ rm -f ./contrib/${PROJECT_NAME}.wsgi | ||
82 | - @ rm -f ./contrib/apache/${PROJECT_NAME}.conf | ||
83 | - @ sudo rm -f /etc/apache2/sites-available/${PROJECT_NAME}.conf | ||
84 | - @ sudo rm -f /etc/apache2/sites-enabled/${PROJECT_NAME}.conf | ||
85 | - | ||
86 | -run: | ||
87 | - @ ( \ | ||
88 | - . ./env/bin/activate; \ | ||
89 | - python main.py; \ | ||
90 | - ) | ||
91 | - | ||
92 | -.install: | ||
93 | - @ sudo apt-get update && \ | ||
94 | - sudo apt-get install -y git-core \ | ||
95 | - postgresql postgresql-server-dev-all libpq-dev python-psycopg2 \ | ||
96 | - python-virtualenv \ | ||
97 | - python-dev build-essential libjpeg-dev libssl-dev swig libffi-dev \ | ||
98 | - redis-server \ | ||
99 | - supervisor \ | ||
100 | - apache2 apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapache2-mod-wsgi | ||
101 | - @ echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/servername.conf | ||
102 | - @ sudo a2enconf servername | ||
103 | - @ sudo a2enmod headers | ||
104 | - -@ sudo a2dissite 000-default.conf | ||
105 | - | ||
106 | -PYBOSSA_DB_USERNAME := pybossa | ||
107 | -PYBOSSA_DB_PASSWORD := tester | ||
108 | -PYBOSSA_DB_CREATE := psql -c \"CREATE USER pybossa WITH PASSWORD '${PYBOSSA_DB_PASSWORD}'\"; | ||
109 | -PYBOSSA_DB_CREATE += psql -c \"CREATE DATABASE pybossa OWNER ${PYBOSSA_DB_USERNAME}\"; | ||
110 | -PYBOSSA_DB_DROP := psql -c \"DROP DATABASE ${PYBOSSA_DB_USERNAME}\"; | ||
111 | -PYBOSSA_DB_DROP += psql -c \"DROP USER ${PYBOSSA_DB_USERNAME}\"; | ||
112 | -PYBOSSA_DB_DUMPFILE := pybossa-dump.sql | ||
113 | -PYBOSSA_DB_VERBOSE := -v | ||
114 | -PYBOSSA_DB_ADMINFILE := wikilibras-pybossa.sql | ||
115 | - | ||
116 | -.postgresql: | ||
117 | - -@ sudo service postgresql restart | ||
118 | - | ||
119 | -create-db: .postgresql env | ||
120 | - @ sudo su postgres -c "${PYBOSSA_DB_CREATE}" | ||
121 | - @ ( \ | ||
122 | - . ./env/bin/activate; \ | ||
123 | - python cli.py db_create; \ | ||
124 | - ) | ||
125 | - | ||
126 | -create-admin: | ||
127 | - @ sudo su postgres -c "psql --set ON_ERROR_STOP=off -f ${PYBOSSA_DB_ADMINFILE} ${PYBOSSA_DB_USERNAME}" | ||
128 | - | ||
129 | -drop-db: .postgresql | ||
130 | - @ sudo su postgres -c "${PYBOSSA_DB_DROP}" | ||
131 | - | ||
132 | -${PYBOSSA_DB_DUMPFILE}: | ||
133 | - @ sudo su postgres -c "PGPASSWORD='${PYBOSSA_DB_PASSWORD}' pg_dump ${PYBOSSA_DB_VERBOSE} -b --inserts ${PYBOSSA_DB_USERNAME};" > ${PYBOSSA_DB_DUMPFILE} |
pybossa/wikilibras-pybossa.sql.old
@@ -1,47 +0,0 @@ | @@ -1,47 +0,0 @@ | ||
1 | --- install: | ||
2 | --- sudo su postgres -c 'psql --set ON_ERROR_STOP=off -f wikilibras-pybossa.sql pybossa' | ||
3 | - | ||
4 | --- SELECT * FROM "user"; | ||
5 | --- postgres://pybossa:tester@localhost:5432/pybossa | ||
6 | - | ||
7 | -INSERT INTO "user" ( | ||
8 | - id, | ||
9 | - created, | ||
10 | - email_addr, | ||
11 | - name, | ||
12 | - fullname, | ||
13 | - locale, | ||
14 | - api_key, | ||
15 | - passwd_hash, | ||
16 | - admin, | ||
17 | - pro, | ||
18 | - privacy_mode, | ||
19 | - google_user_id, | ||
20 | - ckan_api, | ||
21 | - newsletter_prompted, | ||
22 | - valid_email, | ||
23 | - confirmation_email_sent, | ||
24 | - subscribed, | ||
25 | - info, | ||
26 | - profile_id | ||
27 | -) VALUES ( | ||
28 | - 1, --id | ||
29 | - '2017-02-20T15:12:14.560847', --created | ||
30 | - 'wikilibras@lavid.ufpb.br', --email_addr | ||
31 | - 'wikilibras', --name | ||
32 | - 'wikilibras', --fullname | ||
33 | - 'pt_BR', --locale | ||
34 | - '2324bc23-7d6f-4840-8905-b1e6c1675eed', --api_key | ||
35 | - 'pbkdf2:sha1:1000$wIP6vkOx$99be5c325961aa39030bb10e3b58a85ac3bfaa90', --passwd_hash, | ||
36 | - 't', --admin | ||
37 | - 'f', --pro | ||
38 | - 'f', --privacy_mode | ||
39 | - '', --google_user_id | ||
40 | - '', --ckan_api | ||
41 | - 'f', --newsletter_prompted | ||
42 | - 't', --valid_email | ||
43 | - 'f', --confirmation_email_sent | ||
44 | - 't', --subscribed | ||
45 | - '{}', --info | ||
46 | - 1 --profile_i | ||
47 | -) |
wikilibras-pybossa.sql
@@ -3,3 +3,10 @@ | @@ -3,3 +3,10 @@ | ||
3 | 3 | ||
4 | INSERT INTO "user" VALUES (1, '2017-01-01T00:00:00.000000', 'wikilibras@lavid.ufpb.br', 'wikilibras', 'wikilibras', 'pt_BR', '2324bc23-7d6f-4840-8905-b1e6c1675eed', 'pbkdf2:sha1:1000$wIP6vkOx$99be5c325961aa39030bb10e3b58a85ac3bfaa90', true, false, false, NULL, NULL, NULL, NULL, NULL, NULL, false, true, false, true, '{}', 1); | 4 | INSERT INTO "user" VALUES (1, '2017-01-01T00:00:00.000000', 'wikilibras@lavid.ufpb.br', 'wikilibras', 'wikilibras', 'pt_BR', '2324bc23-7d6f-4840-8905-b1e6c1675eed', 'pbkdf2:sha1:1000$wIP6vkOx$99be5c325961aa39030bb10e3b58a85ac3bfaa90', true, false, false, NULL, NULL, NULL, NULL, NULL, NULL, false, true, false, true, '{}', 1); |
5 | SELECT pg_catalog.setval('user_id_seq', 1, true); | 5 | SELECT pg_catalog.setval('user_id_seq', 1, true); |
6 | + | ||
7 | +INSERT INTO "user" VALUES (2, '2017-01-01T00:00:00.000000', 'tester1@lavid.ufpb.br', 'tester1', 'tester1', 'pt_BR', 'e4fef6e0-d954-4ce8-be39-ab08a96aa61a', 'pbkdf2:sha256:50000$ZXnRVTb5$2bfd28d77b26d3c1f183192ec793885bbd523ad92b8a6708edce6d5226a850fe', true, false, false, NULL, NULL, NULL, NULL, NULL, NULL, false, true, false, true, '{}', 1); | ||
8 | +INSERT INTO "user" VALUES (3, '2017-01-01T00:00:00.000000', 'tester2@lavid.ufpb.br', 'tester2', 'tester2', 'pt_BR', '1d0fbea5-88d7-40f2-a835-676bc3824f8c', 'pbkdf2:sha256:50000$DizF7nb3$d4b4946fcac8a88cb2337d610e743432441719559f236b0d5816feb9ffbbefdf', true, false, false, NULL, NULL, NULL, NULL, NULL, NULL, false, true, false, true, '{}', 1); | ||
9 | +INSERT INTO "user" VALUES (4, '2017-01-01T00:00:00.000000', 'tester3@lavid.ufpb.br', 'tester3', 'tester3', 'pt_BR', '8c5707aa-e813-4a5e-b3f1-7d3e413da494', 'pbkdf2:sha256:50000$pYfjlhqL$a3bbd613e39c0ef6387548b4ef1c8b273bf02031b34b10d2f26f21f0839da890', true, false, false, NULL, NULL, NULL, NULL, NULL, NULL, false, true, false, true, '{}', 1); | ||
10 | +INSERT INTO "user" VALUES (5, '2017-01-01T00:00:00.000000', 'tester4@lavid.ufpb.br', 'tester4', 'tester4', 'pt_BR', 'f47796e1-e0da-49ff-b030-ad7459cf464b', 'pbkdf2:sha256:50000$Zht8o4X9$b4e630fb43254589c407406836bf60b5e669f7368dfa45a24ebbc0ed5fee3872', true, false, false, NULL, NULL, NULL, NULL, NULL, NULL, false, true, false, true, '{}', 1); | ||
11 | +INSERT INTO "user" VALUES (6, '2017-01-01T00:00:00.000000', 'tester5@lavid.ufpb.br', 'tester5', 'tester5', 'pt_BR', '7dce7aac-29cd-467f-a1b6-cc96044b5909', 'pbkdf2:sha256:50000$v6cDxeNk$2f7b494d9d4b2e175cdfc9e617758a3a6c30e511385bc24e4d1b499064f9a908', true, false, false, NULL, NULL, NULL, NULL, NULL, NULL, false, true, false, true, '{}', 1); | ||
12 | +SELECT pg_catalog.setval('user_id_seq', 6, true); |
wikilibras-pybossa.sql.old
@@ -1,47 +0,0 @@ | @@ -1,47 +0,0 @@ | ||
1 | --- install: | ||
2 | --- sudo su postgres -c 'psql --set ON_ERROR_STOP=off -f wikilibras-pybossa.sql pybossa' | ||
3 | - | ||
4 | --- SELECT * FROM "user"; | ||
5 | --- postgres://pybossa:tester@localhost:5432/pybossa | ||
6 | - | ||
7 | -INSERT INTO "user" ( | ||
8 | - id, | ||
9 | - created, | ||
10 | - email_addr, | ||
11 | - name, | ||
12 | - fullname, | ||
13 | - locale, | ||
14 | - api_key, | ||
15 | - passwd_hash, | ||
16 | - admin, | ||
17 | - pro, | ||
18 | - privacy_mode, | ||
19 | - google_user_id, | ||
20 | - ckan_api, | ||
21 | - newsletter_prompted, | ||
22 | - valid_email, | ||
23 | - confirmation_email_sent, | ||
24 | - subscribed, | ||
25 | - info, | ||
26 | - profile_id | ||
27 | -) VALUES ( | ||
28 | - 1, --id | ||
29 | - '2017-02-20T15:12:14.560847', --created | ||
30 | - 'wikilibras@lavid.ufpb.br', --email_addr | ||
31 | - 'wikilibras', --name | ||
32 | - 'wikilibras', --fullname | ||
33 | - 'pt_BR', --locale | ||
34 | - '2324bc23-7d6f-4840-8905-b1e6c1675eed', --api_key | ||
35 | - 'pbkdf2:sha1:1000$wIP6vkOx$99be5c325961aa39030bb10e3b58a85ac3bfaa90', --passwd_hash, | ||
36 | - 't', --admin | ||
37 | - 'f', --pro | ||
38 | - 'f', --privacy_mode | ||
39 | - '', --google_user_id | ||
40 | - '', --ckan_api | ||
41 | - 'f', --newsletter_prompted | ||
42 | - 't', --valid_email | ||
43 | - 'f', --confirmation_email_sent | ||
44 | - 't', --subscribed | ||
45 | - '{}', --info | ||
46 | - 1 --profile_i | ||
47 | -) |
wikilibrasdbapi/routes/index.js
@@ -164,7 +164,7 @@ router.put("/updateselo", function(req, res, next) | @@ -164,7 +164,7 @@ router.put("/updateselo", function(req, res, next) | ||
164 | } | 164 | } |
165 | else | 165 | else |
166 | { | 166 | { |
167 | - query += 'UPDATE "sinal" SET "idSelo" = ' + parseInt(selo) + ' WHERE '; | 167 | + query += 'UPDATE "sinal" SET "version" = 0, "idSelo" = ' + parseInt(selo) + ' WHERE '; |
168 | } | 168 | } |
169 | if (_.isEmpty(idTask) && _.isEmpty(idSinal)) | 169 | if (_.isEmpty(idTask) && _.isEmpty(idSinal)) |
170 | { | 170 | { |
@@ -0,0 +1,969 @@ | @@ -0,0 +1,969 @@ | ||
1 | +var express = require("express"); | ||
2 | +var promise = require("bluebird"); // or any other Promise/A+ compatible library; | ||
3 | +var _ = require("lodash"); | ||
4 | +var pgp = require("pg-promise")({promiseLib: promise}); // overriding the default (ES6 Promise); | ||
5 | +var db = pgp("postgres://wikilibras:wikilibras123@localhost:5432/wikilibras"); | ||
6 | +var parameters = require("../helpers/parameters"); | ||
7 | +var async = require("async"); | ||
8 | +var files = require("../helpers/files.js"); | ||
9 | +var fs = require('fs'); | ||
10 | +var path = require("path"); | ||
11 | +var util = require("util"); | ||
12 | +var mkdirp = require("mkdirp"); | ||
13 | +var multer = require("multer"); | ||
14 | +var upload = multer({dest: "uploads/"}); | ||
15 | +var users = path.join(__dirname, "../public/users"); | ||
16 | +var sys = require("util"); | ||
17 | +var exec = require("child_process").exec; | ||
18 | +var child = null; | ||
19 | +var router = express.Router(); | ||
20 | + | ||
21 | +// GET home page | ||
22 | +router.get("/", function(req, res, next) | ||
23 | +{ | ||
24 | + res.render("index" | ||
25 | + , { | ||
26 | + title: "Wikilibras-DB API", | ||
27 | + version: "1.0.0" | ||
28 | + }); | ||
29 | +}); | ||
30 | + | ||
31 | +router.get("/countvideo", function(req, res, next) | ||
32 | +{ | ||
33 | + var response = {}; | ||
34 | + db.query('SELECT COUNT(*) FROM sinal;') | ||
35 | + .then(function(result) | ||
36 | + { | ||
37 | + // response.status = true; | ||
38 | + // response.message = ""; | ||
39 | + // response.data = result; | ||
40 | + // TODO uncomment lines above, remove the line below and | ||
41 | + response = [parseInt(result[0].count)]; | ||
42 | + res.status(203); | ||
43 | + }) | ||
44 | + .catch(function(error) | ||
45 | + { | ||
46 | + response.status = false; | ||
47 | + response.message = ""; | ||
48 | + response.data = error; | ||
49 | + res.status(500); | ||
50 | + }) | ||
51 | + .finally(function() | ||
52 | + { | ||
53 | + res.send(response); | ||
54 | + pgp.end(); | ||
55 | + }); | ||
56 | +}); | ||
57 | + | ||
58 | +router.get("/listselos", function(req, res, next) | ||
59 | +{ | ||
60 | + var response = {}; | ||
61 | + db.query('SELECT "nomeSelo", "idSelo" FROM "tipoSelo";') | ||
62 | + .then(function(result) | ||
63 | + { | ||
64 | + // response.status = true; | ||
65 | + // response.data = result; | ||
66 | + response = result; | ||
67 | + res.status(203); | ||
68 | + }) | ||
69 | + .catch(function(error) | ||
70 | + { | ||
71 | + response.status = false; | ||
72 | + response.error = error; | ||
73 | + res.status(500); | ||
74 | + }) | ||
75 | + .finally(function() | ||
76 | + { | ||
77 | + res.send(response); | ||
78 | + pgp.end(); | ||
79 | + }); | ||
80 | +}); | ||
81 | + | ||
82 | +router.get("/countuservideos", function(req, res, next) | ||
83 | +{ | ||
84 | + var response = {}; | ||
85 | + var limit = 10; | ||
86 | + if (!_.isEmpty(req.query.limit)) | ||
87 | + { | ||
88 | + var _limit = parseInt(req.query.limit); | ||
89 | + if ((0 <= _limit) && (_limit <= 1000)) | ||
90 | + { | ||
91 | + limit = _limit; | ||
92 | + } | ||
93 | + } | ||
94 | + var query = 'SELECT DISTINCT' + | ||
95 | + ' usuario as username,' + | ||
96 | + ' "idUsuario" as email,' + | ||
97 | + ' CAST(COUNT(*) as INTEGER) as videos' + | ||
98 | + ' FROM sinal' + | ||
99 | + ' GROUP BY usuario, "idUsuario"' + | ||
100 | + ' ORDER BY videos DESC, usuario' + | ||
101 | + ' LIMIT ' + limit + ';'; | ||
102 | + db.query(query) | ||
103 | + .then(function(result) | ||
104 | + { | ||
105 | + // response.status = true; | ||
106 | + // response.data = result; | ||
107 | + response = result; | ||
108 | + res.status(203); | ||
109 | + }) | ||
110 | + .catch(function(error) | ||
111 | + { | ||
112 | + response.status = false; | ||
113 | + response.error = error; | ||
114 | + console.log(error); | ||
115 | + res.status(500); | ||
116 | + }) | ||
117 | + .finally(function() | ||
118 | + { | ||
119 | + res.send(response); | ||
120 | + pgp.end(); | ||
121 | + }); | ||
122 | +}); | ||
123 | + | ||
124 | +router.get("/listall", function(req, res, next) | ||
125 | +{ | ||
126 | + var response = {}; | ||
127 | + // db.query('SELECT s."nome", s."data", s.cidade, s.estado, s.file, s.avatar, s.blender, ts."nomeSelo", s."version" FROM "sinal" s, "tipoSelo" ts WHERE s."idSelo" = ts."idSelo"') | ||
128 | + db.query('SELECT s."data", s."usuario", s."idSinal", s.idtask, s."idSelo", ts."nomeSelo", s."version", s."nome", s."classe", s."frase", s."estado", s."cidade", s."file", s."avatar", s."blender" FROM "sinal" s INNER JOIN "tipoSelo" ts ON (s."idSelo" = ts."idSelo")') | ||
129 | + .then(function(result) | ||
130 | + { | ||
131 | + response = result; | ||
132 | + res.status(203); | ||
133 | + }) | ||
134 | + .catch(function(error) | ||
135 | + { | ||
136 | + response = error; | ||
137 | + res.status(500); | ||
138 | + }) | ||
139 | + .finally(function() | ||
140 | + { | ||
141 | + res.send(response); | ||
142 | + pgp.end(); | ||
143 | + }); | ||
144 | +}); | ||
145 | + | ||
146 | +/** | ||
147 | + * Atualiza o campo selo com base no idSinal ou idTask | ||
148 | + */ | ||
149 | +router.put("/updateselo", function(req, res, next) | ||
150 | +{ | ||
151 | + var response = {}; | ||
152 | + var idTask = req.body["idtask"]; | ||
153 | + var idSinal = req.body["idsinal"]; | ||
154 | + var selo = req.body["selo"]; | ||
155 | + | ||
156 | + console.log(JSON.stringify(req.body, null, 4)); | ||
157 | + var query = ""; | ||
158 | + if (_.isEmpty(selo)) | ||
159 | + { | ||
160 | + res.status(500); | ||
161 | + response.status = false; | ||
162 | + response.error = "O campo 'selo' é obrigatório"; | ||
163 | + return res.send(response); | ||
164 | + } | ||
165 | + else | ||
166 | + { | ||
167 | + query += 'UPDATE "sinal" SET "idSelo" = ' + parseInt(selo) + ' WHERE '; | ||
168 | + } | ||
169 | + if (_.isEmpty(idTask) && _.isEmpty(idSinal)) | ||
170 | + { | ||
171 | + res.status(500); | ||
172 | + response.status = false; | ||
173 | + response.error = "O campo 'idtask' ou 'idsinal' está ausente"; | ||
174 | + return res.send(response); | ||
175 | + } | ||
176 | + if (!_.isEmpty(idTask)) | ||
177 | + { | ||
178 | + query += 'idtask = ' + parseInt(idTask); | ||
179 | + } | ||
180 | + if (!_.isEmpty(idTask) && !_.isEmpty(idSinal)) | ||
181 | + { | ||
182 | + query += " AND "; | ||
183 | + } | ||
184 | + if (!_.isEmpty(idSinal)) | ||
185 | + { | ||
186 | + query += '"idSinal" = ' + parseInt(idSinal); | ||
187 | + } | ||
188 | + query += ' RETURNING "nome", "idSinal", idtask, "idSelo";'; | ||
189 | + db.query(query) | ||
190 | + .then(function(result) | ||
191 | + { | ||
192 | + if (Object.keys(result).length > 0) | ||
193 | + { | ||
194 | + response.status = true; | ||
195 | + } | ||
196 | + else | ||
197 | + { | ||
198 | + response.status = false; | ||
199 | + } | ||
200 | + response.data = result; | ||
201 | + res.status(200); | ||
202 | + }) | ||
203 | + .catch(function(error) | ||
204 | + { | ||
205 | + response.status = false; | ||
206 | + response.error = error; | ||
207 | + res.status(500); | ||
208 | + }) | ||
209 | + .finally(function() | ||
210 | + { | ||
211 | + res.send(response); | ||
212 | + pgp.end(); | ||
213 | + }); | ||
214 | +}); | ||
215 | + | ||
216 | +/** | ||
217 | + * Atualiza o campo 'idtask' com base no idSinal | ||
218 | + */ | ||
219 | +router.get("/updatetask", function(req, res, next) | ||
220 | +{ | ||
221 | + var response = {}; | ||
222 | + var idTask = req.query["idtask"]; | ||
223 | + var idSinal = req.query["idsinal"]; | ||
224 | + if (_.isEmpty(idTask)) | ||
225 | + { | ||
226 | + res.status(500); | ||
227 | + response.status = false; | ||
228 | + response.error = "O campo 'idtask' é obrigatório"; | ||
229 | + res.send(response); | ||
230 | + return; | ||
231 | + } | ||
232 | + else | ||
233 | + { | ||
234 | + idTask = parseInt(idTask); | ||
235 | + } | ||
236 | + if (_.isEmpty(idSinal)) | ||
237 | + { | ||
238 | + res.status(500); | ||
239 | + response.status = false; | ||
240 | + response.error = "O campo 'idsinal' é obrigatório"; | ||
241 | + res.send(response); | ||
242 | + return; | ||
243 | + } | ||
244 | + else | ||
245 | + { | ||
246 | + idSinal = parseInt(idSinal); | ||
247 | + } | ||
248 | + db.query('UPDATE "sinal" SET version = version + 1, idtask = ($1) WHERE "idSinal" = ($2) RETURNING "idSinal", idtask;', [idTask, idSinal]) | ||
249 | + .then(function(result) | ||
250 | + { | ||
251 | + if (Object.keys(result).length > 0) | ||
252 | + { | ||
253 | + response.status = true; | ||
254 | + response.data = result; | ||
255 | + } | ||
256 | + else | ||
257 | + { | ||
258 | + response.status = false; | ||
259 | + response.data = "ERROR: 'idSinal' = " + idSinal + " Não encontrado"; | ||
260 | + } | ||
261 | + res.status(200); | ||
262 | + }) | ||
263 | + .catch(function(error) | ||
264 | + { | ||
265 | + response.status = false; | ||
266 | + response.error = error; | ||
267 | + res.status(500); | ||
268 | + }) | ||
269 | + .finally(function() | ||
270 | + { | ||
271 | + res.send(response); | ||
272 | + pgp.end(); | ||
273 | + }); | ||
274 | +}); | ||
275 | + | ||
276 | +/** | ||
277 | + * Retorna lista de sinais inseridos pelo formulário e | ||
278 | + * os que que tiveram o selo alterado | ||
279 | + */ | ||
280 | +router.get("/newtasks", function(req, res, next) | ||
281 | +{ | ||
282 | + var response = {}; | ||
283 | + var selo = req.query["selo"]; | ||
284 | + var query = 'SELECT s."idSinal", s."nome", s."idSelo", ts."nomeSelo", s."usuario", s."estado", s."classe", s."file", s."avatar", s."blender" FROM "sinal" s INNER JOIN "tipoSelo" ts ON (s."idSelo" = ts."idSelo") WHERE s."version" = 0 '; | ||
285 | + if (!_.isEmpty(selo)) | ||
286 | + { | ||
287 | + query += ' AND s."idSelo" = ' + parseInt(selo); | ||
288 | + } | ||
289 | + query += ';'; | ||
290 | + db.query(query) | ||
291 | + .then(function(result) | ||
292 | + { | ||
293 | + response.status = true; | ||
294 | + response.count = result.length; | ||
295 | + response.data = result; | ||
296 | + res.status(200); | ||
297 | + }) | ||
298 | + .catch(function(error) | ||
299 | + { | ||
300 | + response.status = false; | ||
301 | + response.error = error; | ||
302 | + res.status(500); | ||
303 | + }) | ||
304 | + .finally(function() | ||
305 | + { | ||
306 | + res.send(response); | ||
307 | + pgp.end(); | ||
308 | + }); | ||
309 | +}); | ||
310 | + | ||
311 | +/* | ||
312 | +// only for test | ||
313 | +router.get("/populate", function(req, res, next) | ||
314 | +{ | ||
315 | + var response = {}; | ||
316 | + exec("sudo su postgres -c 'psql --set ON_ERROR_STOP=off -f ../wikilibras-db-api-dump.sql wikilibras'", | ||
317 | + function(error, stdout, stderr) | ||
318 | + { | ||
319 | + if (error) | ||
320 | + { | ||
321 | + response.status = false; | ||
322 | + response.message = "Error while populate"; | ||
323 | + console.log(stdout); | ||
324 | + res.status = 500; | ||
325 | + } | ||
326 | + else if (stderr.length > 0) | ||
327 | + { | ||
328 | + response.status = false; | ||
329 | + response.message = "The Database already been populated"; | ||
330 | + console.log(stderr); | ||
331 | + res.status = 304; | ||
332 | + } | ||
333 | + else | ||
334 | + { | ||
335 | + response.status = true; | ||
336 | + response.message = "The Database has been populated"; | ||
337 | + res.status = 201; | ||
338 | + } | ||
339 | + res.send(response); | ||
340 | + }); | ||
341 | +}); | ||
342 | +*/ | ||
343 | + | ||
344 | +router.get("/reset", function(req, res, next) | ||
345 | +{ | ||
346 | + var response = {}; | ||
347 | + db.query('TRUNCATE TABLE sinal, selo; ALTER SEQUENCE sequence RESTART WITH 1;') | ||
348 | + .then(function(result) | ||
349 | + { | ||
350 | + response.status = true; | ||
351 | + response.message = "The database has been truncated"; | ||
352 | + res.status(203); | ||
353 | + }) | ||
354 | + .catch(function(error) | ||
355 | + { | ||
356 | + response.status = false; | ||
357 | + response.message = "The database cannot be truncated"; | ||
358 | + response.error = error; | ||
359 | + res.status(500); | ||
360 | + }) | ||
361 | + .finally(function() | ||
362 | + { | ||
363 | + res.send(response); | ||
364 | + pgp.end(); | ||
365 | + // console.log(JSON.stringify(response, null, 4)); | ||
366 | + }); | ||
367 | +}); | ||
368 | + | ||
369 | +router.get("/resettasks", function(req, res, next) | ||
370 | +{ | ||
371 | + const pg = require("pg"); | ||
372 | + const connectionString = "postgres://pybossa:tester@localhost:5432/pybossa"; | ||
373 | + const results = []; | ||
374 | + const data = { text: req.body.text, complete: false }; | ||
375 | + pg.connect(connectionString, function(err, client, done) | ||
376 | + { | ||
377 | + if (err) | ||
378 | + { | ||
379 | + done(); | ||
380 | + console.log(err); | ||
381 | + return res.status(500).json({ success: false, data: err }); | ||
382 | + } | ||
383 | + const query = client.query('TRUNCATE "task" CASCADE; ALTER SEQUENCE task_id_seq RESTART WITH 1'); | ||
384 | + query.on('row', function(row) | ||
385 | + { | ||
386 | + results.push(row); | ||
387 | + }); | ||
388 | + query.on('end', function() | ||
389 | + { | ||
390 | + done(); | ||
391 | + return res.json({ success: true, data: results }); | ||
392 | + }); | ||
393 | + }); | ||
394 | +}); | ||
395 | + | ||
396 | +router.get("/version", function(req, res, next) | ||
397 | +{ | ||
398 | + var response = []; | ||
399 | + db.query('SELECT MAX(version) FROM sinal;') | ||
400 | + .then(function(result) | ||
401 | + { | ||
402 | + response = { "version": result[0].max }; | ||
403 | + }) | ||
404 | + .catch(function(error) | ||
405 | + { | ||
406 | + response = error; | ||
407 | + }) | ||
408 | + .finally(function() | ||
409 | + { | ||
410 | + pgp.end(); | ||
411 | + res.status(200).send(response); | ||
412 | + }); | ||
413 | +}); | ||
414 | + | ||
415 | +router.get("/sinais", function(req, res, next) | ||
416 | +{ | ||
417 | + var results = []; | ||
418 | + if ((!_.isEmpty(req.query("selo"))) && (!_.isEmpty(req.query("version")))) | ||
419 | + { | ||
420 | + db.query('SELECT s."nome", s."data", s.cidade, s."version", s.estado, s.file, s.avatar, s.blender, ts."nomeSelo" FROM "sinal" s, "tipoSelo" ts WHERE s."idSelo" = ts."idSelo" AND ts."nomeSelo" = $1 AND s."version" = $2', [req.query("selo"), req.query("version")]) | ||
421 | + .then(function(result) | ||
422 | + { | ||
423 | + res.status(203).send(result); | ||
424 | + }) | ||
425 | + .catch(function(error) | ||
426 | + { | ||
427 | + // error; | ||
428 | + }) | ||
429 | + .finally(function() | ||
430 | + { | ||
431 | + pgp.end(); | ||
432 | + }); | ||
433 | + } | ||
434 | + else | ||
435 | + { | ||
436 | + if (!_.isEmpty(req.query("version"))) | ||
437 | + { | ||
438 | + db.query("select nome, data, file, avatar, blender version FROM sinal WHERE version = $1", req.query("version")) | ||
439 | + .then(function(result) | ||
440 | + { | ||
441 | + res.status(203).send(result); | ||
442 | + }) | ||
443 | + .catch(function(error) | ||
444 | + { | ||
445 | + // error; | ||
446 | + }) | ||
447 | + .finally(function() | ||
448 | + { | ||
449 | + pgp.end(); | ||
450 | + }); | ||
451 | + } | ||
452 | + if (!_.isEmpty(req.query("selo"))) | ||
453 | + { | ||
454 | + db.query('SELECT s."nome", s."data", s.cidade, s.estado, s.file, s.avatar, s.blender, ts."nomeSelo", s.version FROM "sinal" s, "tipoSelo" ts WHERE s."idSelo" = ts."idSelo" AND ts."nomeSelo" = $1', req.query("selo")) | ||
455 | + | ||
456 | + .then(function(result) | ||
457 | + { | ||
458 | + res.status(203).send(result); | ||
459 | + }) | ||
460 | + .catch(function(error) | ||
461 | + { | ||
462 | + // error; | ||
463 | + }) | ||
464 | + .finally(function() | ||
465 | + { | ||
466 | + pgp.end(); | ||
467 | + }); | ||
468 | + } | ||
469 | + } | ||
470 | +}); | ||
471 | + | ||
472 | +router.post('/gsinal', function(req, res, next) | ||
473 | +{ | ||
474 | + console.log("\n\n\n============================================="); | ||
475 | + console.log("[" + new Date().toISOString() + "] Requisição do IP: " + req.ip); | ||
476 | + console.log("== Parametros: " + util.inspect(req.body)); | ||
477 | + console.log("== Body: " + JSON.stringify(req.headers)); | ||
478 | + db.query('UPDATE sinal SET "idSelo" = ($1), version = version + 1 WHERE nome = ($2)', [req.body.selo, req.body.nome]) | ||
479 | + .then(function(data) | ||
480 | + { | ||
481 | + res.status(203).send('Sinal ' + req.body.nome + ' atualizado com sucesso [without archive]'); | ||
482 | + }) | ||
483 | + .catch(function(error) | ||
484 | + { | ||
485 | + console.log("Erro " + error); | ||
486 | + }); | ||
487 | +}); | ||
488 | + | ||
489 | +/* | ||
490 | +router.post('/addsinal', upload.array('video', 2), function(req, res, next) | ||
491 | +{ | ||
492 | + console.log("\n\n\n============================================="); | ||
493 | + console.log("[" + new Date().toISOString() + "]"); | ||
494 | + console.log("From: " + req.ip); | ||
495 | + // console.log("Files: " + req.files[0]); | ||
496 | + // console.log("headers: " + JSON.stringify(req.headers)); | ||
497 | + console.log("body: " + JSON.stringify(req.body)); | ||
498 | + | ||
499 | + if (req.method === "OPTIONS") | ||
500 | + { | ||
501 | + res.header('Access-Control-Allow-Origin', req.headers.origin); | ||
502 | + } | ||
503 | + else | ||
504 | + { | ||
505 | + res.header('Access-Control-Allow-Origin', '*'); | ||
506 | + } | ||
507 | + | ||
508 | + if (_.isEmpty(req.body.nome)) | ||
509 | + { | ||
510 | + res.send(500, 'O valor do parâmetro nome está vazio'); | ||
511 | + return; | ||
512 | + } | ||
513 | + async.series([ | ||
514 | + function(callback) | ||
515 | + { | ||
516 | + console.log("\t >> ORDEM 1"); | ||
517 | + if (_.isEmpty(req.body.wikilibras)) | ||
518 | + { | ||
519 | + console.log("Movendo arquivo para conversão..."); | ||
520 | + files.downloadAndMoveVideo(req, 'sinais', callback); | ||
521 | + } | ||
522 | + else | ||
523 | + { | ||
524 | + files.downloadAndMoveVideo(req, 'wikilibras', callback); | ||
525 | + } | ||
526 | + }, | ||
527 | + function(callback) | ||
528 | + { | ||
529 | + console.log("\t >> ORDEM 2"); | ||
530 | + if (_.isEmpty(req.body.wikilibras)) | ||
531 | + { | ||
532 | + console.log("Convertendo para .webm..."); | ||
533 | + child = exec('avconv -v error -i uploads/' + req.files[0].originalname + ' -acodec libvorbis -vcodec libvpx -an sinais/' + req.files[0].originalname.slice(0, -4) + '.webm -y', function(error, stdout, stderr) | ||
534 | + { | ||
535 | + console.log('stdout: ' + stdout); | ||
536 | + console.log('stderr: ' + stderr); | ||
537 | + if (error !== null) | ||
538 | + { | ||
539 | + console.log('exec error: ' + error); | ||
540 | + } | ||
541 | + }); | ||
542 | + | ||
543 | + child.on('exit', function() | ||
544 | + { | ||
545 | + setTimeout(function() | ||
546 | + { | ||
547 | + console.log("Conversão para webm concluída."); | ||
548 | + callback(null, 1); | ||
549 | + }, 500); | ||
550 | + }); | ||
551 | + } | ||
552 | + else | ||
553 | + { | ||
554 | + callback(); | ||
555 | + } | ||
556 | + }, | ||
557 | + function(callback) | ||
558 | + { | ||
559 | + console.log("== Alterando o db"); | ||
560 | + db.query('SELECT "idSelo" FROM "sinal" WHERE nome = $1', req.body.nome) | ||
561 | + .then(function(result) | ||
562 | + { | ||
563 | + var d = new Date(); | ||
564 | + if (Object.keys(result).length > 0) | ||
565 | + { | ||
566 | + if (!_.isEmpty(req.body.overwrite)) | ||
567 | + { | ||
568 | + if (!_.isEmpty(req.body.wikilibras)) | ||
569 | + { | ||
570 | + db.query('UPDATE sinal SET avatar = ($1), blender = ($2) WHERE nome = ($3)', [req.files[0].originalname, req.files[1].originalname, req.body.nome]) | ||
571 | + .then(function(data) | ||
572 | + { | ||
573 | + res.send(200, 'Sinal ' + req.body.nome + ' atualizado com sucesso [with avatar/blender].'); | ||
574 | + }) | ||
575 | + .catch(function(error) | ||
576 | + { | ||
577 | + console.log("Erro " + error); | ||
578 | + }); | ||
579 | + } | ||
580 | + if (!_.isEmpty(req.files)) | ||
581 | + { | ||
582 | + db.query('UPDATE sinal SET "idSelo" = ($1), version = version + 1, file = ($2) WHERE nome = ($3)', [req.body.selo, req.files[0].originalname, req.body.nome]) | ||
583 | + .then(function(data) | ||
584 | + { | ||
585 | + res.status(200).send('Sinal ' + req.body.nome + ' atualizado com sucesso [with archive].'); | ||
586 | + }) | ||
587 | + .catch(function(error) | ||
588 | + { | ||
589 | + console.log("Erro " + error); | ||
590 | + }); | ||
591 | + } | ||
592 | + else | ||
593 | + { | ||
594 | + db.query('UPDATE sinal SET "idSelo" = ($1) WHERE nome = ($2)', [req.body.selo, req.body.nome]) | ||
595 | + .then(function(data) | ||
596 | + { | ||
597 | + res.status(200).send('Sinal ' + req.body.nome + ' atualizado com sucesso [without archive].'); | ||
598 | + }) | ||
599 | + .catch(function(error) | ||
600 | + { | ||
601 | + console.log("Erro " + error); | ||
602 | + }); | ||
603 | + } | ||
604 | + } | ||
605 | + else | ||
606 | + { | ||
607 | + res.status(500).send('Sinal já cadastrado no sistema'); | ||
608 | + } | ||
609 | + } | ||
610 | + else | ||
611 | + { | ||
612 | + if (_.isEmpty(req.body.selo)) | ||
613 | + { | ||
614 | + req.body.selo = 7; | ||
615 | + } | ||
616 | + db.one('insert into sinal (usuario, nome, "idSelo", data, version, estado, cidade, file) values ($1, $2, $3, $4, $5, $6, $7, $8) returning "idSinal"', [req.body.login, req.body.nome, req.body.selo, d.getFullYear() + "/" + d.getMonth() + "/" + d.getDate(), 1, req.body.estado, req.body.cidade, req.files[0].originalname.slice(0, -4) + '.webm']) | ||
617 | + .then(function(data) | ||
618 | + { | ||
619 | + res.status(200).send('Sinal ' + req.body.nome + ' adicionado com sucesso.'); | ||
620 | + }) | ||
621 | + .catch(function(error) | ||
622 | + { | ||
623 | + console.log("Erro " + error); | ||
624 | + }); | ||
625 | + } | ||
626 | + }) | ||
627 | + .catch(function(error) | ||
628 | + { | ||
629 | + console.log(error); | ||
630 | + }) | ||
631 | + .finally(function() | ||
632 | + { | ||
633 | + pgp.end(); | ||
634 | + }); | ||
635 | + } | ||
636 | + , ], function(err) | ||
637 | + { | ||
638 | + if (err) | ||
639 | + { | ||
640 | + res.send(500, "Error"); | ||
641 | + return; | ||
642 | + } | ||
643 | + }); | ||
644 | +}); | ||
645 | +*/ | ||
646 | + | ||
647 | +router.post('/updatesinal', upload.array('video', 2), function(req, res, next) | ||
648 | +{ | ||
649 | + // console.log("[" + new Date().toISOString() + "]"); | ||
650 | + // console.log("From: " + req.ip); | ||
651 | + // console.log("Files: " + JSON.stringify(req.files[0], null, 4)); | ||
652 | + // console.log("headers: " + JSON.stringify(req.headers, null, 4)); | ||
653 | + // console.log("body: " + JSON.stringify(req.body, null, 4)); | ||
654 | + if (req.method === "OPTIONS") | ||
655 | + { | ||
656 | + res.header('Access-Control-Allow-Origin', req.headers.origin); | ||
657 | + } | ||
658 | + else | ||
659 | + { | ||
660 | + res.header('Access-Control-Allow-Origin', '*'); | ||
661 | + } | ||
662 | + if (req.files.length < 2) | ||
663 | + { | ||
664 | + return res.status(500).send("ERROR: O campo 'video' deve conter dois arquivos (video, blend)"); | ||
665 | + } | ||
666 | + var response = {}; | ||
667 | + var directory = users; | ||
668 | + var nome = req.body["nome"]; | ||
669 | + var selo = req.body["selo"]; | ||
670 | + var idTask = req.body["idtask"]; | ||
671 | + var blend = req.files[1]; | ||
672 | + var video = req.files[0]; | ||
673 | + var maxblendsize = 25; // MB | ||
674 | + var maxvideosize = 25; // MB | ||
675 | + if (_.isEmpty(nome) || _.isEmpty(idTask)) | ||
676 | + { | ||
677 | + response.status = false; | ||
678 | + response.error = "Os campos 'nome' e 'idtask' são obrigatórios"; | ||
679 | + return res.status(500).send(response); | ||
680 | + } | ||
681 | + else | ||
682 | + { | ||
683 | + nome = nome.trim().toUpperCase(); | ||
684 | + } | ||
685 | + if (video.size > (maxvideosize * 1048576)) | ||
686 | + { | ||
687 | + response.status = false; | ||
688 | + response.error = "O tamanho do video deve ter no máximo " + maxvideosize + " MB"; | ||
689 | + return res.status(500).send(response); | ||
690 | + } | ||
691 | + if (blend.size > (maxblendsize * 1048576)) | ||
692 | + { | ||
693 | + response.status = false; | ||
694 | + response.error = "O tamanho do blend deve ter no máximo " + maxblendsize + " MB"; | ||
695 | + return res.status(500).send(response); | ||
696 | + } | ||
697 | + if (_.isEmpty(selo) || 1 < selo || selo > 7) | ||
698 | + { | ||
699 | + selo = 1; | ||
700 | + } | ||
701 | + db.query('SELECT "idSinal", usuario, estado, classe FROM "sinal" WHERE nome = ($1) AND idtask = ($2)', [nome, idTask]) | ||
702 | + .then(function(result) | ||
703 | + { | ||
704 | + if (Object.keys(result).length > 0) | ||
705 | + { | ||
706 | + var idSinal = result[0]["idSinal"]; | ||
707 | + var login = result[0]["usuario"]; | ||
708 | + var estado = result[0]["estado"]; | ||
709 | + var classe = result[0]["classe"]; | ||
710 | + var videoname = nome + ".webm"; | ||
711 | + var blendname = nome + ".blend"; | ||
712 | + if (login !== null) | ||
713 | + { | ||
714 | + directory = path.join(directory, login); | ||
715 | + } | ||
716 | + if (estado !== null) | ||
717 | + { | ||
718 | + directory = path.join(directory, estado); | ||
719 | + } | ||
720 | + if (classe !== null) | ||
721 | + { | ||
722 | + directory = path.join(directory, classe); | ||
723 | + } | ||
724 | + if (!fs.existsSync(directory)) | ||
725 | + { | ||
726 | + console.log("Criando diretorio: " + directory); | ||
727 | + mkdirp(directory, function (err) | ||
728 | + { | ||
729 | + if (err) | ||
730 | + { | ||
731 | + console.error(err); | ||
732 | + res.status(500).send(err); | ||
733 | + return; | ||
734 | + } | ||
735 | + else | ||
736 | + { | ||
737 | + console.log("Diretório criado com sucesso!"); | ||
738 | + } | ||
739 | + }); | ||
740 | + } | ||
741 | + db.query('UPDATE sinal SET "idSelo" = ($1), version = ($2), avatar = ($3), blender = ($4) WHERE "idSinal" = ($5)', [selo, 0, videoname, blendname, idSinal]) | ||
742 | + .then(function(data) | ||
743 | + { | ||
744 | + videopath = path.join(directory, videoname); | ||
745 | + blendpath = path.join(directory, blendname); | ||
746 | + fs.rename(video.path, videopath); | ||
747 | + fs.rename(blend.path, blendpath); | ||
748 | + var message = "Sinal atualizado: '" + nome + "'"; | ||
749 | + console.log(message); | ||
750 | + res.status(200).send(message); | ||
751 | + }) | ||
752 | + .catch(function(error) | ||
753 | + { | ||
754 | + var message = "Erro ao atualizar sinal '" + nome + "'\n" + error; | ||
755 | + console.log(message); | ||
756 | + res.status(500).send(message); | ||
757 | + }); | ||
758 | + } | ||
759 | + else | ||
760 | + { | ||
761 | + var message = "Não foi encontrado nenhum 'idtask' = '" + idTask + "' com sinal = " + nome; | ||
762 | + res.status(500).send(message); | ||
763 | + } | ||
764 | + }) | ||
765 | + .catch(function(error) | ||
766 | + { | ||
767 | + console.log(error); | ||
768 | + }) | ||
769 | + .finally(function() | ||
770 | + { | ||
771 | + pgp.end(); | ||
772 | + }); | ||
773 | +}); | ||
774 | + | ||
775 | +router.post('/addsinal', upload.array('video', 2), function(req, res, next) | ||
776 | +{ | ||
777 | + // console.log("[" + new Date().toISOString() + "]"); | ||
778 | + // console.log("From: " + req.ip); | ||
779 | + // console.log("Files: " + JSON.stringify(req.files[0], null, 4)); | ||
780 | + // console.log("headers: " + JSON.stringify(req.headers, null, 4)); | ||
781 | + // console.log("body: " + JSON.stringify(req.body, null, 4)); | ||
782 | + if (req.method === "OPTIONS") | ||
783 | + { | ||
784 | + res.header('Access-Control-Allow-Origin', req.headers.origin); | ||
785 | + } | ||
786 | + else | ||
787 | + { | ||
788 | + res.header('Access-Control-Allow-Origin', '*'); | ||
789 | + } | ||
790 | + if (req.files.length < 1) | ||
791 | + { | ||
792 | + return res.status(500).send("ERROR: O campo 'video' não contém nenhum arquivo do sinal"); | ||
793 | + } | ||
794 | + var directory = users; | ||
795 | + var login = req.body["login"]; | ||
796 | + var estado = req.body["estado"]; | ||
797 | + var classe = req.body["classe-gramatical"]; | ||
798 | + var nome = req.body["nome"]; | ||
799 | + var cidade = req.body["cidade"]; | ||
800 | + var frase = req.body["frases"]; | ||
801 | + var selo = req.body["selo"]; | ||
802 | + var filesize = req.files[0].size; | ||
803 | + var input = req.files[0].path; | ||
804 | + var videoref = ""; | ||
805 | + var output = ""; | ||
806 | + var maxfilesize = 25; // MB | ||
807 | + if (filesize > (maxfilesize * 1048576)) | ||
808 | + { | ||
809 | + return res.status(500).send("O tamanho do arquivo deve ter no máximo " + maxfilesize + " MB"); | ||
810 | + } | ||
811 | + if (_.isEmpty(nome)) | ||
812 | + { | ||
813 | + return res.status(500).send("ERROR: O campo 'nome' não foi encontrado"); | ||
814 | + } | ||
815 | + else | ||
816 | + { | ||
817 | + nome = nome.trim().toUpperCase(); | ||
818 | + videoref = nome + "_REF.webm"; | ||
819 | + } | ||
820 | + if (_.isEmpty(selo)) | ||
821 | + { | ||
822 | + selo = 7; | ||
823 | + } | ||
824 | + if (_.isEmpty(login)) | ||
825 | + { | ||
826 | + console.log("WARNING: O campo 'login' não foi encontrado"); | ||
827 | + } | ||
828 | + else | ||
829 | + { | ||
830 | + directory = path.join(directory, login); | ||
831 | + } | ||
832 | + if (_.isEmpty(estado)) | ||
833 | + { | ||
834 | + console.log("WARNING: O campo 'estado' não foi encontrado"); | ||
835 | + } | ||
836 | + else | ||
837 | + { | ||
838 | + directory = path.join(directory, estado); | ||
839 | + } | ||
840 | + if (_.isEmpty(classe)) | ||
841 | + { | ||
842 | + console.log("WARNING: O campo 'classe' não foi encontrado"); | ||
843 | + } | ||
844 | + else | ||
845 | + { | ||
846 | + directory = path.join(directory, classe); | ||
847 | + } | ||
848 | + output = path.join(directory, videoref); | ||
849 | + async.series([ | ||
850 | + function (callback) | ||
851 | + { | ||
852 | + if (fs.existsSync(directory)) | ||
853 | + { | ||
854 | + callback(null, 1); | ||
855 | + } | ||
856 | + else | ||
857 | + { | ||
858 | + console.log("Criando diretorio: " + directory); | ||
859 | + mkdirp(directory, function (err) | ||
860 | + { | ||
861 | + if (err) | ||
862 | + { | ||
863 | + console.error(err); | ||
864 | + return res.status(500).send(err); | ||
865 | + } | ||
866 | + else | ||
867 | + { | ||
868 | + console.log("Diretório criado com sucesso!"); | ||
869 | + callback(null, 1); | ||
870 | + } | ||
871 | + }); | ||
872 | + } | ||
873 | + }, | ||
874 | + // Converter para formato webm | ||
875 | + function(callback) | ||
876 | + { | ||
877 | + console.log("Convertendo sinal '" + nome + "' para webm..."); | ||
878 | + child = exec("avconv -y -v error -i \"" + input + "\" -acodec libvorbis -vcodec libvpx -an \"" + output + "\"", | ||
879 | + function(error, stdout, stderr) | ||
880 | + { | ||
881 | + if (error || (stderr.length > 0)) | ||
882 | + { | ||
883 | + var log = "O arquivo de vídeo é inválido, ou ocorreu um erro durante a conversão\nDetalhes: " + stdout + stderr; | ||
884 | + log = log.trim(); | ||
885 | + res.status(500); | ||
886 | + callback(true, log); | ||
887 | + } | ||
888 | + else | ||
889 | + { | ||
890 | + res.status(200); | ||
891 | + return 0; | ||
892 | + } | ||
893 | + }); | ||
894 | + child.on("exit", function(code) | ||
895 | + { | ||
896 | + setTimeout(function() | ||
897 | + { | ||
898 | + if (code === 0) | ||
899 | + { | ||
900 | + console.log("Conversão concluída"); | ||
901 | + callback(null, 1); | ||
902 | + } | ||
903 | + else | ||
904 | + { | ||
905 | + callback(true, new Error("Erro durante conversão")); | ||
906 | + } | ||
907 | + }, 500); | ||
908 | + }); | ||
909 | + }, | ||
910 | + function(callback) | ||
911 | + { | ||
912 | + console.log("Verificando se este sinal já existe"); | ||
913 | + db.query('SELECT "idSinal" FROM "sinal" WHERE usuario = ($1) AND estado = ($2) AND classe = ($3) AND nome = ($4)', [login, estado, classe, nome]) | ||
914 | + .then(function(result) | ||
915 | + { | ||
916 | + var d = new Date(); | ||
917 | + var date = d.getFullYear() + "/" + d.getMonth() + "/" + d.getDate(); | ||
918 | + if (Object.keys(result).length > 0) | ||
919 | + { | ||
920 | + var idSinal = result[0].idSinal; | ||
921 | + console.log("Existe, atualizando o sinal[" + idSinal + "]: '" + nome + "'"); | ||
922 | + db.query('UPDATE sinal SET "idSelo" = ($1), version = ($2), data = ($3), cidade = ($4), frase = ($5), file = ($6) WHERE "idSinal" = ($7)', [7, 0, date, cidade, frase, videoref, idSinal]) | ||
923 | + .then(function(data) | ||
924 | + { | ||
925 | + res.status(200).send("Sinal atualizado"); | ||
926 | + }) | ||
927 | + .catch(function(error) | ||
928 | + { | ||
929 | + var message = "Erro ao atualizar sinal '" + nome + "'\n" + error; | ||
930 | + console.log(message); | ||
931 | + res.status(500).send(message); | ||
932 | + }); | ||
933 | + } | ||
934 | + else | ||
935 | + { | ||
936 | + console.log("Não existe, inserindo sinal: '" + nome + "'"); | ||
937 | + db.one('INSERT INTO sinal (usuario, nome, classe, "idSelo", data, version, estado, cidade, frase, file) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING "idSinal"', [login, nome, classe, selo, date, 0, estado, cidade, frase, videoref]) | ||
938 | + .then(function(data) | ||
939 | + { | ||
940 | + var message = "Sinal[" + data.idSinal + "]: '" + nome + "', inserido com sucesso!"; | ||
941 | + console.log(message); | ||
942 | + res.status(200).send(message); | ||
943 | + }) | ||
944 | + .catch(function(error) | ||
945 | + { | ||
946 | + res.status(500).send(error); | ||
947 | + }); | ||
948 | + } | ||
949 | + }) | ||
950 | + .catch(function(error) | ||
951 | + { | ||
952 | + console.log(error); | ||
953 | + }) | ||
954 | + .finally(function() | ||
955 | + { | ||
956 | + pgp.end(); | ||
957 | + }); | ||
958 | + } | ||
959 | + ], | ||
960 | + function(err, results) | ||
961 | + { | ||
962 | + if (err) | ||
963 | + { | ||
964 | + console.log(results[0]); | ||
965 | + } | ||
966 | + }); | ||
967 | +}); | ||
968 | + | ||
969 | +module.exports = router; |