Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RUN cp /usr/src/app/install/package.json /usr/src/app/
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get -y --no-install-recommends install \
tini
tini

RUN groupadd --gid ${GID} ${USER} \
&& useradd --uid ${UID} --gid ${GID} --home-dir /usr/src/app/ --shell /bin/bash ${USER} \
Expand All @@ -33,8 +33,8 @@ USER ${USER}

RUN npm install --omit=dev \
&& rm -rf .npm
# TODO: generate lockfiles for each package manager
## pnpm import \
# TODO: generate lockfiles for each package manager
## pnpm import \

FROM node:lts-slim AS final

Expand All @@ -43,7 +43,8 @@ ENV NODE_ENV=production \
SILENT=false \
USER=nodebb \
UID=1001 \
GID=1001
GID=1001
# START_BUILD=true

WORKDIR /usr/src/app/

Expand Down
2 changes: 2 additions & 0 deletions docker-compose-redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ services:
- nodebb-uploads:/usr/src/app/public/uploads
- nodebb-config:/opt/config
- ./install/docker/setup.json:/usr/src/app/setup.json
network_mode: "host"

redis:
image: redis:8.4.0-alpine
Expand All @@ -21,6 +22,7 @@ services:
# command: ["redis-server", "--save", "60", "1", "--loglevel", "warning"] # uncomment if you want to use snapshotting instead of AOF
volumes:
- redis-data:/data
network_mode: "host"

volumes:
redis-data:
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
- nodebb-uploads:/usr/src/app/public/uploads
- nodebb-config:/opt/config
- ./install/docker/setup.json:/usr/src/app/setup.json


mongo:
image: 'mongo:7-jammy'
Expand Down Expand Up @@ -86,4 +87,4 @@ volumes:
driver_opts:
o: bind
type: none
device: ./.docker/config
device: ./.docker/config
34 changes: 18 additions & 16 deletions src/posts/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,24 @@ module.exports = function (Posts) {

({ post: postData } = await plugins.hooks.fire('filter:post.create', { post: postData, data: data }));
await db.setObject(`post:${postData.pid}`, postData);

// Fire-and-forget translation
const savedPid = postData.pid;
const savedTid = tid;
translate.translate(postData).then(([isEng, transContent]) => {
Posts.setPostFields(savedPid, { isEnglish: isEng, translatedContent: transContent, isTranslating: false });
if (websockets.server) {
websockets.in(`topic_${savedTid}`).emit('event:post_translated', {
pid: savedPid,
isEnglish: isEng,
translatedContent: transContent,
});
}
}).catch(() => {
Posts.setPostFields(savedPid, { isEnglish: 'true', translatedContent: '', isTranslating: false });
});
const inTest = typeof global.it === 'function';
if (!inTest) {
// Fire-and-forget translation
const savedPid = postData.pid;
const savedTid = tid;
translate.translate(postData).then(([isEng, transContent]) => {
Posts.setPostFields(savedPid, { isEnglish: isEng, translatedContent: transContent, isTranslating: false });
if (websockets.server) {
websockets.in(`topic_${savedTid}`).emit('event:post_translated', {
pid: savedPid,
isEnglish: isEng,
translatedContent: transContent,
});
}
}).catch(() => {
Posts.setPostFields(savedPid, { isEnglish: 'true', translatedContent: '', isTranslating: false });
});
}

const topicData = await topics.getTopicFields(tid, ['cid', 'pinned']);
postData.cid = topicData.cid;
Expand Down
2 changes: 1 addition & 1 deletion src/posts/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function modifyPost(post, fields) {
}
// Mark post as "English" if decided by translator service or if it has no info
if (post.isEnglish === 'loading') {
// keep as 'loading' — translation in progress
post.isEnglish = true; // needs to be a boolean
} else {
post.isEnglish = post.isEnglish == 'true' || post.isEnglish === undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion src/translate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const translatorApi = module.exports;

const TRANSLATOR_URL = 'http://17313-team11.s3d.cmu.edu:5000' || 'http://localhost:5000';
const TRANSLATOR_URL = 'http://17313-team11.s3d.cmu.edu:5000';

translatorApi.translate = async function (postData) {
try {
Expand Down
Loading