forked from CMU-313/cmu-313-f24-nodebb-f24-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.
successfully installed and add flow dependency to package.json file
- Loading branch information
1 parent
66a9b1e
commit d9493e0
Showing
37 changed files
with
5,124 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"presets": ["@babel/preset-flow"], | ||
"plugins": ["babel-plugin-syntax-hermes-parser"], | ||
} |
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,14 @@ | ||
[ignore] | ||
|
||
[include] | ||
|
||
[libs] | ||
|
||
[lints] | ||
untyped-type-import=error | ||
internal-type=error | ||
deprecated-type-bool=error | ||
|
||
[options] | ||
|
||
[strict] |
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,96 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const sanitizeHTML = require('sanitize-html'); | ||
const nconf = require('nconf'); | ||
const winston = require('winston'); | ||
const file = require('../file'); | ||
Check failure on line 8 in lib/admin/search.js GitHub Actions / test
|
||
const { | ||
Translator | ||
Check failure on line 10 in lib/admin/search.js GitHub Actions / test
|
||
} = require('../translator'); | ||
Check failure on line 11 in lib/admin/search.js GitHub Actions / test
Check failure on line 11 in lib/admin/search.js GitHub Actions / test
|
||
function filterDirectories(directories) { | ||
return directories.map(dir => dir.replace(/^.*(admin.*?).tpl$/, '$1').split(path.sep).join('/')).filter(dir => !dir.endsWith('.js') && !dir.includes('/partials/') && /\/.*\//.test(dir) && !/manage\/(category|group|category-analytics)$/.test(dir)); | ||
} | ||
async function getAdminNamespaces() { | ||
const directories = await file.walk(path.resolve(nconf.get('views_dir'), 'admin')); | ||
return filterDirectories(directories); | ||
} | ||
function sanitize(html) { | ||
return sanitizeHTML(html, { | ||
allowedTags: [], | ||
allowedAttributes: [] | ||
}); | ||
} | ||
function simplify(translations) { | ||
return translations.replace(/(?:\{{1,2}[^}]*?\}{1,2})/g, '').replace(/(?:[ \t]*[\n\r]+[ \t]*)+/g, '\n').replace(/[\t ]+/g, ' '); | ||
} | ||
function nsToTitle(namespace) { | ||
return namespace.replace('admin/', '').split('/').map(str => str[0].toUpperCase() + str.slice(1)).join(' > ').replace(/[^a-zA-Z> ]/g, ' '); | ||
} | ||
const fallbackCache = {}; | ||
async function initFallback(namespace) { | ||
const template = await fs.promises.readFile(path.resolve(nconf.get('views_dir'), `${namespace}.tpl`), 'utf8'); | ||
const title = nsToTitle(namespace); | ||
let translations = sanitize(template); | ||
translations = Translator.removePatterns(translations); | ||
translations = simplify(translations); | ||
translations += `\n${title}`; | ||
return { | ||
namespace: namespace, | ||
translations: translations, | ||
title: title | ||
}; | ||
} | ||
async function fallback(namespace) { | ||
if (fallbackCache[namespace]) { | ||
return fallbackCache[namespace]; | ||
} | ||
const params = await initFallback(namespace); | ||
fallbackCache[namespace] = params; | ||
return params; | ||
} | ||
async function initDict(language) { | ||
const namespaces = await getAdminNamespaces(); | ||
return await Promise.all(namespaces.map(ns => buildNamespace(language, ns))); | ||
} | ||
async function buildNamespace(language, namespace) { | ||
const translator = Translator.create(language); | ||
try { | ||
const translations = await translator.getTranslation(namespace); | ||
if (!translations || !Object.keys(translations).length) { | ||
return await fallback(namespace); | ||
} | ||
let str = Object.keys(translations).map(key => translations[key]).join('\n'); | ||
str = sanitize(str); | ||
let title = namespace; | ||
title = title.match(/admin\/(.+?)\/(.+?)$/); | ||
title = `[[admin/menu:section-${title[1] === 'development' ? 'advanced' : title[1]}]]${title[2] ? ` > [[admin/menu:${title[1]}/${title[2]}]]` : ''}`; | ||
title = await translator.translate(title); | ||
return { | ||
namespace: namespace, | ||
translations: `${str}\n${title}`, | ||
title: title | ||
}; | ||
} catch (err) { | ||
winston.error(err.stack); | ||
return { | ||
namespace: namespace, | ||
translations: '' | ||
}; | ||
} | ||
} | ||
const cache = {}; | ||
async function getDictionary(language) { | ||
if (cache[language]) { | ||
return cache[language]; | ||
} | ||
const params = await initDict(language); | ||
cache[language] = params; | ||
return params; | ||
} | ||
module.exports.getDictionary = getDictionary; | ||
module.exports.filterDirectories = filterDirectories; | ||
module.exports.simplify = simplify; | ||
module.exports.sanitize = sanitize; | ||
require('../promisify')(module.exports); |
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,40 @@ | ||
'use strict'; | ||
|
||
const request = require('../request'); | ||
const meta = require('../meta'); | ||
let versionCache = ''; | ||
let versionCacheLastModified = ''; | ||
const isPrerelease = /^v?\d+\.\d+\.\d+-.+$/; | ||
const latestReleaseUrl = 'https://api.github.com/repos/NodeBB/NodeBB/releases/latest'; | ||
async function getLatestVersion() { | ||
const headers = { | ||
Accept: 'application/vnd.github.v3+json', | ||
'User-Agent': encodeURIComponent(`NodeBB Admin Control Panel/${meta.config.title}`) | ||
}; | ||
if (versionCacheLastModified) { | ||
headers['If-Modified-Since'] = versionCacheLastModified; | ||
} | ||
const { | ||
body: latestRelease, | ||
response | ||
} = await request.get(latestReleaseUrl, { | ||
headers: headers, | ||
timeout: 2000 | ||
}); | ||
if (response.statusCode === 304) { | ||
return versionCache; | ||
} | ||
if (response.statusCode !== 200) { | ||
throw new Error(response.statusText); | ||
} | ||
if (!latestRelease || !latestRelease.tag_name) { | ||
throw new Error('[[error:cant-get-latest-release]]'); | ||
} | ||
const tagName = latestRelease.tag_name.replace(/^v/, ''); | ||
versionCache = tagName; | ||
versionCacheLastModified = response.headers['last-modified']; | ||
return versionCache; | ||
} | ||
exports.getLatestVersion = getLatestVersion; | ||
exports.isPrerelease = isPrerelease; | ||
require('../promisify')(exports); |
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,7 @@ | ||
'use strict'; | ||
|
||
const { | ||
AsyncLocalStorage | ||
} = require('async_hooks'); | ||
const asyncLocalStorage = new AsyncLocalStorage(); | ||
module.exports = asyncLocalStorage; |
Oops, something went wrong.