forked from CMU-313/NodeBB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates README and example files (CMU-313#1)
* Update provided example files - Added original JavaScript files for both examples - Adding comments at the beginning to provide context for what the files are - Small style updates * Moving @types packages to devDependencies * Update README.md * Update README installation instructions
- Loading branch information
Showing
8 changed files
with
179 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// This is one of the two example files included with the NodeBB repository | ||
// It is the original (untranslated) JavaScript file of composer.ts | ||
// This file is meant to serve as an example to assist you with your | ||
// HW1 translation. It is *not* meant to be run. | ||
// You do not have to keep your original JavaScript file for this assignment | ||
|
||
'use strict'; | ||
|
||
const nconf = require('nconf'); | ||
|
||
const user = require('../user'); | ||
const plugins = require('../plugins'); | ||
const topics = require('../topics'); | ||
const posts = require('../posts'); | ||
const helpers = require('./helpers'); | ||
|
||
exports.get = async function (req, res, callback) { | ||
res.locals.metaTags = { | ||
...res.locals.metaTags, | ||
name: 'robots', | ||
content: 'noindex', | ||
}; | ||
|
||
const data = await plugins.hooks.fire('filter:composer.build', { | ||
req: req, | ||
res: res, | ||
next: callback, | ||
templateData: {}, | ||
}); | ||
|
||
if (res.headersSent) { | ||
return; | ||
} | ||
if (!data || !data.templateData) { | ||
return callback(new Error('[[error:invalid-data]]')); | ||
} | ||
|
||
if (data.templateData.disabled) { | ||
res.render('', { | ||
title: '[[modules:composer.compose]]', | ||
}); | ||
} else { | ||
data.templateData.title = '[[modules:composer.compose]]'; | ||
res.render('compose', data.templateData); | ||
} | ||
}; | ||
|
||
exports.post = async function (req, res) { | ||
const { body } = req; | ||
const data = { | ||
uid: req.uid, | ||
req: req, | ||
timestamp: Date.now(), | ||
content: body.content, | ||
fromQueue: false, | ||
}; | ||
req.body.noscript = 'true'; | ||
|
||
if (!data.content) { | ||
return helpers.noScriptErrors(req, res, '[[error:invalid-data]]', 400); | ||
} | ||
async function queueOrPost(postFn, data) { | ||
const shouldQueue = await posts.shouldQueue(req.uid, data); | ||
if (shouldQueue) { | ||
delete data.req; | ||
return await posts.addToQueue(data); | ||
} | ||
return await postFn(data); | ||
} | ||
|
||
try { | ||
let result; | ||
if (body.tid) { | ||
data.tid = body.tid; | ||
result = await queueOrPost(topics.reply, data); | ||
} else if (body.cid) { | ||
data.cid = body.cid; | ||
data.title = body.title; | ||
data.tags = []; | ||
data.thumb = ''; | ||
result = await queueOrPost(topics.post, data); | ||
} else { | ||
throw new Error('[[error:invalid-data]]'); | ||
} | ||
if (result.queued) { | ||
return res.redirect(`${nconf.get('relative_path') || '/'}?noScriptMessage=[[success:post-queued]]`); | ||
} | ||
const uid = result.uid ? result.uid : result.topicData.uid; | ||
user.updateOnlineUsers(uid); | ||
const path = result.pid ? `/post/${result.pid}` : `/topic/${result.topicData.slug}`; | ||
res.redirect(nconf.get('relative_path') + path); | ||
} catch (err) { | ||
helpers.noScriptErrors(req, res, err.message, 400); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// This is one of the two example files included with the NodeBB repository | ||
// It is the original (untranslated) JavaScript file of social.ts | ||
// This file is meant to serve as an example to assist you with your | ||
// HW1 translation. It is *not* meant to be run. | ||
// You do not have to keep your original JavaScript file for this assignment | ||
|
||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
const plugins = require('./plugins'); | ||
const db = require('./database'); | ||
|
||
const social = module.exports; | ||
|
||
social.postSharing = null; | ||
|
||
social.getPostSharing = async function () { | ||
if (social.postSharing) { | ||
return _.cloneDeep(social.postSharing); | ||
} | ||
|
||
let networks = [ | ||
{ | ||
id: 'facebook', | ||
name: 'Facebook', | ||
class: 'fa-facebook', | ||
}, | ||
{ | ||
id: 'twitter', | ||
name: 'Twitter', | ||
class: 'fa-twitter', | ||
}, | ||
]; | ||
networks = await plugins.hooks.fire('filter:social.posts', networks); | ||
const activated = await db.getSetMembers('social:posts.activated'); | ||
networks.forEach((network) => { | ||
network.activated = activated.includes(network.id); | ||
}); | ||
|
||
social.postSharing = networks; | ||
return _.cloneDeep(networks); | ||
}; | ||
|
||
social.getActivePostSharing = async function () { | ||
const networks = await social.getPostSharing(); | ||
return networks.filter(network => network && network.activated); | ||
}; | ||
|
||
social.setActivePostSharingNetworks = async function (networkIDs) { | ||
social.postSharing = null; | ||
await db.delete('social:posts.activated'); | ||
if (!networkIDs.length) { | ||
return; | ||
} | ||
await db.setAdd('social:posts.activated', networkIDs); | ||
}; | ||
|
||
require('./promisify')(social); |