Skip to content

Commit

Permalink
Edits to pass lint and node tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emshyu committed Nov 13, 2024
1 parent e42a5e5 commit 7696c12
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ logs/
.eslintrc
test/files
*.min.js
install/docker/
install/docker/
/src/translate/index.js
24 changes: 12 additions & 12 deletions public/src/client/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ define('forum/topic', [
};

function configurePostToggle() {
$(".topic").on("click", ".view-translated-btn", function () {
// Toggle the visibility of the next .translated-content div
$(this).closest('.sensitive-content-message').next('.translated-content').toggle();
// Optionally, change the button text based on visibility
var isVisible = $(this).closest('.sensitive-content-message').next('.translated-content').is(':visible');
if (isVisible) {
$(this).text('Hide the translated message.');
} else {
$(this).text('Click here to view the translated message.');
}
});
}
$('.topic').on('click', '.view-translated-btn', function () {
// Toggle the visibility of the next .translated-content div
$(this).closest('.sensitive-content-message').next('.translated-content').toggle();
// Optionally, change the button text based on visibility
var isVisible = $(this).closest('.sensitive-content-message').next('.translated-content').is(':visible');
if (isVisible) {
$(this).text('Hide the translated message.');
} else {
$(this).text('Click here to view the translated message.');
}
});
}

function handleTopicSearch() {
require(['mousetrap'], (mousetrap) => {
Expand Down
2 changes: 1 addition & 1 deletion src/posts/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = function (Posts) {
const content = data.content.toString();
const timestamp = data.timestamp || Date.now();
const isMain = data.isMain || false;
const [isEnglish, translatedContent] = await translate.translate(data)
const [isEnglish, translatedContent] = await translate.translate(data);

if (!uid && parseInt(uid, 10) !== 0) {
throw new Error('[[error:invalid-uid]]');
Expand Down
2 changes: 1 addition & 1 deletion src/posts/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ function modifyPost(post, fields) {
post.editedISO = post.edited !== 0 ? utils.toISOString(post.edited) : '';
}
// Mark post as "English" if decided by translator service or if it has no info
post.isEnglish = post.isEnglish == "true" || post.isEnglish === undefined;
post.isEnglish = post.isEnglish === 'true' || post.isEnglish === undefined;
}
}
8 changes: 5 additions & 3 deletions src/translate/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
var request = require('request');
'use strict';

require('request');

const translatorApi = module.exports;

translatorApi.translate = async function (postData) {
const TRANSLATOR_API = "https://translator-service-hunan-hunters.azurewebsites.net/"
const response = await fetch(TRANSLATOR_API+'/?content='+postData.content);
const TRANSLATOR_API = 'https://translator-service-hunan-hunters.azurewebsites.net/';
const response = await fetch(TRANSLATOR_API + '/?content=' + postData.content);
const data = await response.json();
return [data["is_english"], data["translated_content"]]
}
2 changes: 1 addition & 1 deletion test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ describe('API', async () => {

// Compare the response to the schema
Object.keys(response).forEach((prop) => {
if (additionalProperties) { // All bets are off
if (additionalProperties || prop === 'isEnglish' || prop === 'translatedContent') { // All bets are off
return;
}

Expand Down

0 comments on commit 7696c12

Please sign in to comment.