mirror of https://github.com/iconify/api.git
Few bug fixes and changes
This commit is contained in:
parent
c45a1a298a
commit
2597f662a9
2
app.js
2
app.js
|
|
@ -89,7 +89,7 @@ function loadIcons(firstLoad) {
|
|||
newCollections = new Collections(config, console.log);
|
||||
|
||||
console.log('Loading collections at ' + (new Date()).toString());
|
||||
newCollections.reload().then(() => {
|
||||
newCollections.reload(dirs.getRepos()).then(() => {
|
||||
console.log('Loaded in ' + (Date.now() - t) + 'ms');
|
||||
fulfill(newCollections);
|
||||
}).catch(err => {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"region": "",
|
||||
"env-region": true,
|
||||
"reload-secret": "",
|
||||
"custom-icon-dir": "{dir}/json",
|
||||
"custom-icons-dir": "{dir}/json",
|
||||
"serve-default-icons": true,
|
||||
"index-page": "https://simplesvg.com/",
|
||||
"cache": {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ To check which server you are connected to, open /version in browser.
|
|||
|
||||
If true, script will check for environment variable "REGION" and if it is set, it will overwrite configuration option "region"
|
||||
|
||||
#### custom-icon-dir
|
||||
#### custom-icons-dir
|
||||
|
||||
Directory with custom json files.
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ By default server will be running on port 3000. You can change port and other co
|
|||
|
||||
File config.json is the same as config-default.json, but contains only values you have customized. See [config.md](config.md)
|
||||
|
||||
It is better to run server on obscure port such as 3000 hidden behind firewall and use nginx reverse proxy. This way you can offload connection handling to nginx and you can easily use SSL.
|
||||
|
||||
|
||||
### Node vs PHP
|
||||
|
||||
|
|
|
|||
|
|
@ -103,12 +103,9 @@ class Collections {
|
|||
*
|
||||
* @returns {Promise}
|
||||
*/
|
||||
reload() {
|
||||
reload(repos) {
|
||||
return new Promise((fulfill, reject) => {
|
||||
let promises = [
|
||||
this._findCollections('simple-svg'),
|
||||
this._findCollections('custom')
|
||||
];
|
||||
let promises = repos.map(repo => this._findCollections(repo));
|
||||
|
||||
Promise.all(promises).then(() => {
|
||||
return this.loadQueue();
|
||||
|
|
|
|||
26
src/dirs.js
26
src/dirs.js
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
let config, _dirs;
|
||||
|
||||
let repos;
|
||||
|
||||
const functions = {
|
||||
/**
|
||||
* Get root directory of repository
|
||||
|
|
@ -25,11 +27,9 @@ const functions = {
|
|||
dir = functions.rootDir(repo);
|
||||
return dir === '' ? '' : dir + '/json';
|
||||
|
||||
case 'custom':
|
||||
default:
|
||||
return functions.rootDir(repo);
|
||||
}
|
||||
|
||||
return '';
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -40,8 +40,8 @@ const functions = {
|
|||
*/
|
||||
setRootDir: (repo, dir) => {
|
||||
let extraKey = repo + '-dir';
|
||||
if (config[extraKey] !== void 0 && config[extraKey] !== '') {
|
||||
let extra = config[extraKey];
|
||||
if (config.sync && config.sync[extraKey] !== void 0 && config.sync[extraKey] !== '') {
|
||||
let extra = config.sync[extraKey];
|
||||
if (extra.slice(0, 1) !== '/') {
|
||||
extra = '/' + extra;
|
||||
}
|
||||
|
|
@ -58,21 +58,31 @@ const functions = {
|
|||
*
|
||||
* @returns {string[]}
|
||||
*/
|
||||
keys: () => Object.keys(_dirs)
|
||||
keys: () => Object.keys(_dirs),
|
||||
|
||||
/**
|
||||
* Get all repositories
|
||||
*
|
||||
* @returns {string[]}
|
||||
*/
|
||||
getRepos: () => repos,
|
||||
};
|
||||
|
||||
module.exports = appConfig => {
|
||||
config = appConfig;
|
||||
_dirs = {};
|
||||
repos = [];
|
||||
|
||||
// Set default directories
|
||||
if (config['serve-default-icons']) {
|
||||
let icons = require('simple-svg-icons');
|
||||
repos.push('simple-svg');
|
||||
_dirs['simple-svg'] = icons.rootDir();
|
||||
}
|
||||
|
||||
if (config['custom-icon-dir']) {
|
||||
_dirs['custom'] = config['custom-icon-dir'].replace('{dir}', config._dir);
|
||||
if (config['custom-icons-dir']) {
|
||||
repos.push('custom');
|
||||
_dirs['custom'] = config['custom-icons-dir'].replace('{dir}', config._dir);
|
||||
}
|
||||
|
||||
config._dirs = functions;
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@ const fs = require('fs'),
|
|||
child_process = require('child_process'),
|
||||
promiseQueue = require('./promise');
|
||||
|
||||
const repos = ['simple-svg', 'custom'];
|
||||
|
||||
let synchronized = {},
|
||||
active = false,
|
||||
cleaning = false,
|
||||
|
|
@ -13,7 +11,7 @@ let synchronized = {},
|
|||
reSync = {},
|
||||
syncQueue = {};
|
||||
|
||||
let config, dirs, _baseDir, _repoDir, _versionsFile;
|
||||
let config, dirs, repos, _baseDir, _repoDir, _versionsFile;
|
||||
|
||||
/**
|
||||
* Start synchronization
|
||||
|
|
@ -397,6 +395,7 @@ function init() {
|
|||
module.exports = appConfig => {
|
||||
config = appConfig;
|
||||
dirs = config._dirs;
|
||||
repos = dirs.getRepos();
|
||||
init();
|
||||
|
||||
config._sync = functions;
|
||||
|
|
|
|||
Loading…
Reference in New Issue