Skip to content

Commit

Permalink
Merge pull request #47 from CMU-313/lint-overhaul
Browse files Browse the repository at this point in the history
Fixing lint errors and adjusting CI test scope
  • Loading branch information
philliparaujo authored Nov 14, 2024
2 parents df391d1 + 3cbda92 commit 46e76ea
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 27 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/standardjs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ name: StandardJS Lint
on:
pull_request:
branches:
- f24
- standard-js-tool
- '*'
push:
branches:
- f24
- standard-js-tool
- '*'

jobs:
lint:
Expand All @@ -28,4 +26,4 @@ jobs:
working-directory: ./install

- name: Run StandardJS
run: npx standard
run: npx standard public/src/modules/chat.js
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Lint and test
on:
pull_request:
branches:
- f24
- '*'
workflow_call: # Usually called from deploy

defaults:
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
node app --setup="${SETUP}" --ci="${CI}"
- name: Run ESLint
run: npm run lint
run: npx eslint --cache --ignore-pattern 'public/src/modules/chat.js' ./nodebb .

- name: Node tests
run: npm test
Expand Down
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 @@ -69,6 +69,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;
}
}
34 changes: 28 additions & 6 deletions src/translate/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
var request = require('request');
'use strict';

const translatorApi = module.exports;

translatorApi.translate = async function (postData) {
const TRANSLATOR_API = "https://slackers-translator-d7bcacgqd5a2gsap.canadacentral-01.azurewebsites.net/";
const response = await fetch(TRANSLATOR_API+'/?content='+postData.content);
const data = await response.json();
return [data["is_english"], data["translated_content"]];
}
const TRANSLATOR_API = 'https://slackers-translator-d7bcacgqd5a2gsap.canadacentral-01.azurewebsites.net/';

try {
const response = await fetch(`${TRANSLATOR_API}/?content=${encodeURIComponent(postData.content)}`);
if (!response.ok) {
throw new Error(`Failed to fetch translation: ${response.status} ${response.statusText}`);
}

// Attempt to parse response as JSON
let data;
try {
data = await response.json();
} catch (err) {
throw new Error('Unexpected response format: Expected JSON but received non-JSON data');
}

// Check if the necessary fields are present in the data
if (!data || typeof data.is_english !== 'boolean' || typeof data.translated_content !== 'string') {
throw new Error('Incomplete data: Missing expected fields in response');
}

return [data.is_english, data.translated_content];
} catch (error) {
console.error('Translation API error:', error.message);
return [null, 'Error in translation service'];
}
};

0 comments on commit 46e76ea

Please sign in to comment.