Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized code #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 5 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ let flipped;
const frame = await fs.readFile(path.join(framesPath, file));
return frame.toString();
}));
flipped = original.map(f => {
return f
.toString()
.split('')
.reverse()
.join('')
})
flipped = original.map(frame => frame.split('').reverse().join(''));
})().catch((err) => {
console.log('Error loading frames');
console.log(err);
Expand All @@ -36,9 +30,9 @@ const colorsOptions = [
'blue',
'magenta',
'cyan',
'white'
];
'white'];
const numColors = colorsOptions.length;

const selectColor = previousColor => {
let color;

Expand All @@ -52,7 +46,6 @@ const selectColor = previousColor => {
const streamer = (stream, opts) => {
let index = 0;
let lastColor;
let frame = null;
const frames = opts.flip ? flipped : original;

return setInterval(() => {
Expand All @@ -64,7 +57,7 @@ const streamer = (stream, opts) => {
stream.push(colors[colorsOptions[newColor]](frames[index]));

index = (index + 1) % frames.length;
}, 70);
}, 50); // Reduced interval time for smoother animation
};

const validateQuery = ({ flip }) => ({
Expand All @@ -74,7 +67,7 @@ const validateQuery = ({ flip }) => ({
const server = http.createServer((req, res) => {
if (req.url === '/healthcheck') {
res.writeHead(200, { 'Content-Type': 'application/json' });
return res.end(JSON.stringify({status: 'ok'}));
return res.end(JSON.stringify({ status: 'ok' }));
}

if (
Expand Down