mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-26 03:33:58 -05:00
Merge branch 't216-refactor-common' into 'frontend-next'
T216 refactor common See merge request !5
This commit is contained in:
commit
75e28a1d5e
14 changed files with 45 additions and 69 deletions
|
@ -16,7 +16,6 @@
|
||||||
],
|
],
|
||||||
"array-callback-return": "error",
|
"array-callback-return": "error",
|
||||||
"arrow-body-style": "error",
|
"arrow-body-style": "error",
|
||||||
"arrow-parens": "error",
|
|
||||||
"arrow-spacing": "error",
|
"arrow-spacing": "error",
|
||||||
"block-scoped-var": "off",
|
"block-scoped-var": "off",
|
||||||
"block-spacing": "error",
|
"block-spacing": "error",
|
||||||
|
@ -123,7 +122,7 @@
|
||||||
"no-extend-native": "error",
|
"no-extend-native": "error",
|
||||||
"no-extra-bind": "error",
|
"no-extra-bind": "error",
|
||||||
"no-extra-label": "error",
|
"no-extra-label": "error",
|
||||||
"no-extra-parens": "error",
|
"no-extra-parens": "warn",
|
||||||
"no-floating-decimal": "error",
|
"no-floating-decimal": "error",
|
||||||
"no-global-assign": "error",
|
"no-global-assign": "error",
|
||||||
"no-implicit-coercion": "error",
|
"no-implicit-coercion": "error",
|
||||||
|
@ -195,7 +194,7 @@
|
||||||
"no-unneeded-ternary": "error",
|
"no-unneeded-ternary": "error",
|
||||||
"no-unsafe-negation": "error",
|
"no-unsafe-negation": "error",
|
||||||
"no-unused-expressions": "error",
|
"no-unused-expressions": "error",
|
||||||
"no-use-before-define": "error",
|
"no-use-before-define": "warn",
|
||||||
"no-useless-call": "error",
|
"no-useless-call": "error",
|
||||||
"no-useless-computed-key": "error",
|
"no-useless-computed-key": "error",
|
||||||
"no-useless-concat": "error",
|
"no-useless-concat": "error",
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -18,7 +18,6 @@ backups/
|
||||||
|
|
||||||
# ignore config files
|
# ignore config files
|
||||||
config.json
|
config.json
|
||||||
public/js/config.js
|
|
||||||
.sequelizerc
|
.sequelizerc
|
||||||
|
|
||||||
# ignore webpack build
|
# ignore webpack build
|
||||||
|
|
16
README.md
16
README.md
|
@ -97,19 +97,9 @@ Configuration files
|
||||||
There are some configs you need to change in the files below
|
There are some configs you need to change in the files below
|
||||||
|
|
||||||
```
|
```
|
||||||
./config.json --- for server settings
|
./config.json ----application settings
|
||||||
./public/js/config.js --- for client settings
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Client settings `config.js`
|
|
||||||
---
|
|
||||||
|
|
||||||
| variables | example values | description |
|
|
||||||
| --------- | ------ | ----------- |
|
|
||||||
| debug | `true` or `false` | set debug mode, show more logs |
|
|
||||||
| domain | `localhost` | domain name |
|
|
||||||
| urlpath | `hackmd` | sub url path, like: `www.example.com/<urlpath>` |
|
|
||||||
|
|
||||||
Environment variables (will overwrite other server configs)
|
Environment variables (will overwrite other server configs)
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -158,7 +148,7 @@ Environment variables (will overwrite other server configs)
|
||||||
| HMD_S3_REGION | `ap-northeast-1` | AWS S3 region |
|
| HMD_S3_REGION | `ap-northeast-1` | AWS S3 region |
|
||||||
| HMD_S3_BUCKET | no example | AWS S3 bucket name |
|
| HMD_S3_BUCKET | no example | AWS S3 bucket name |
|
||||||
|
|
||||||
Server settings `config.json`
|
Application settings `config.json`
|
||||||
---
|
---
|
||||||
|
|
||||||
| variables | example values | description |
|
| variables | example values | description |
|
||||||
|
@ -207,7 +197,7 @@ Third-party integration api key settings
|
||||||
| ------- | --------- | ----------- |
|
| ------- | --------- | ----------- |
|
||||||
| facebook, twitter, github, gitlab, dropbox, google, ldap | environment variables or `config.json` | for signin |
|
| facebook, twitter, github, gitlab, dropbox, google, ldap | environment variables or `config.json` | for signin |
|
||||||
| imgur | environment variables or `config.json` | for image upload |
|
| imgur | environment variables or `config.json` | for image upload |
|
||||||
| google drive, dropbox | `public/js/config.js` | for export and import |
|
| google drive(`google/apiKey`, `google/clientID`), dropbox(`dropbox/appKey`) | `config.json` | for export and import |
|
||||||
|
|
||||||
Third-party integration oauth callback urls
|
Third-party integration oauth callback urls
|
||||||
---
|
---
|
||||||
|
|
|
@ -28,8 +28,6 @@ EOF
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
cp public/js/config.js.example public/js/config.js
|
|
||||||
|
|
||||||
# build app
|
# build app
|
||||||
npm run build
|
npm run build
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -21,10 +21,6 @@ if [ ! -f config.json ]; then
|
||||||
cp config.json.example config.json
|
cp config.json.example config.json
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f publis/js/config.js ]; then
|
|
||||||
cp public/js/config.js.example public/js/config.js
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -f .sequelizerc ]; then
|
if [ ! -f .sequelizerc ]; then
|
||||||
cp .sequelizerc.example .sequelizerc
|
cp .sequelizerc.example .sequelizerc
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -45,11 +45,13 @@
|
||||||
},
|
},
|
||||||
"dropbox": {
|
"dropbox": {
|
||||||
"clientID": "change this",
|
"clientID": "change this",
|
||||||
"clientSecret": "change this"
|
"clientSecret": "change this",
|
||||||
|
"appKey": "change this"
|
||||||
},
|
},
|
||||||
"google": {
|
"google": {
|
||||||
"clientID": "change this",
|
"clientID": "change this",
|
||||||
"clientSecret": "change this"
|
"clientSecret": "change this",
|
||||||
|
"apiKey": "change this"
|
||||||
},
|
},
|
||||||
"ldap": {
|
"ldap": {
|
||||||
"url": "ldap://change_this",
|
"url": "ldap://change_this",
|
||||||
|
|
|
@ -90,11 +90,11 @@ var gitlab = (process.env.HMD_GITLAB_CLIENTID && process.env.HMD_GITLAB_CLIENTSE
|
||||||
var dropbox = (process.env.HMD_DROPBOX_CLIENTID && process.env.HMD_DROPBOX_CLIENTSECRET) ? {
|
var dropbox = (process.env.HMD_DROPBOX_CLIENTID && process.env.HMD_DROPBOX_CLIENTSECRET) ? {
|
||||||
clientID: process.env.HMD_DROPBOX_CLIENTID,
|
clientID: process.env.HMD_DROPBOX_CLIENTID,
|
||||||
clientSecret: process.env.HMD_DROPBOX_CLIENTSECRET
|
clientSecret: process.env.HMD_DROPBOX_CLIENTSECRET
|
||||||
} : config.dropbox || false;
|
} : (config.dropbox && config.dropbox.clientID && config.dropbox.clientSecret) || false;
|
||||||
var google = (process.env.HMD_GOOGLE_CLIENTID && process.env.HMD_GOOGLE_CLIENTSECRET) ? {
|
var google = (process.env.HMD_GOOGLE_CLIENTID && process.env.HMD_GOOGLE_CLIENTSECRET) ? {
|
||||||
clientID: process.env.HMD_GOOGLE_CLIENTID,
|
clientID: process.env.HMD_GOOGLE_CLIENTID,
|
||||||
clientSecret: process.env.HMD_GOOGLE_CLIENTSECRET
|
clientSecret: process.env.HMD_GOOGLE_CLIENTSECRET
|
||||||
} : config.google || false;
|
} : (config.google && config.google.clientID && config.google.clientSecret) || false;
|
||||||
var ldap = config.ldap || (
|
var ldap = config.ldap || (
|
||||||
process.env.HMD_LDAP_URL ||
|
process.env.HMD_LDAP_URL ||
|
||||||
process.env.HMD_LDAP_BINDDN ||
|
process.env.HMD_LDAP_BINDDN ||
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
domain: '', // domain name
|
|
||||||
urlpath: '', // sub url path, like: www.example.com/<urlpath>
|
|
||||||
|
|
||||||
// settings
|
|
||||||
debug: false,
|
|
||||||
|
|
||||||
GOOGLE_API_KEY: '',
|
|
||||||
GOOGLE_CLIENT_ID: '',
|
|
||||||
DROPBOX_APP_KEY: ''
|
|
||||||
};
|
|
|
@ -9,7 +9,7 @@ import {
|
||||||
getLoginState,
|
getLoginState,
|
||||||
resetCheckAuth,
|
resetCheckAuth,
|
||||||
setloginStateChangeEvent
|
setloginStateChangeEvent
|
||||||
} from './common';
|
} from './lib/common/login';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
clearDuplicatedHistory,
|
clearDuplicatedHistory,
|
||||||
|
|
|
@ -11,7 +11,7 @@ import PDFObject from 'pdfobject';
|
||||||
import S from 'string';
|
import S from 'string';
|
||||||
import { saveAs } from 'file-saver';
|
import { saveAs } from 'file-saver';
|
||||||
|
|
||||||
require('./common');
|
require('./lib/common/login');
|
||||||
require('../vendor/md-toc');
|
require('../vendor/md-toc');
|
||||||
var Viz = require("viz.js");
|
var Viz = require("viz.js");
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
import store from 'store';
|
import store from 'store';
|
||||||
import S from 'string';
|
import S from 'string';
|
||||||
|
|
||||||
|
import {
|
||||||
|
checkIfAuth
|
||||||
|
} from './lib/common/login';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
checkIfAuth,
|
|
||||||
urlpath
|
urlpath
|
||||||
} from './common';
|
} from './lib/config';
|
||||||
|
|
||||||
window.migrateHistoryFromTempCallback = null;
|
window.migrateHistoryFromTempCallback = null;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,10 @@ var List = require('list.js');
|
||||||
|
|
||||||
import {
|
import {
|
||||||
checkLoginStateChanged,
|
checkLoginStateChanged,
|
||||||
setloginStateChangeEvent,
|
setloginStateChangeEvent
|
||||||
|
} from './lib/common/login';
|
||||||
|
|
||||||
|
import {
|
||||||
debug,
|
debug,
|
||||||
DROPBOX_APP_KEY,
|
DROPBOX_APP_KEY,
|
||||||
GOOGLE_API_KEY,
|
GOOGLE_API_KEY,
|
||||||
|
@ -28,7 +31,7 @@ import {
|
||||||
noteurl,
|
noteurl,
|
||||||
urlpath,
|
urlpath,
|
||||||
version
|
version
|
||||||
} from './common';
|
} from './lib/config';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
autoLinkify,
|
autoLinkify,
|
||||||
|
|
|
@ -1,21 +1,4 @@
|
||||||
// import config from './config';
|
import { serverurl } from '../config';
|
||||||
|
|
||||||
import {
|
|
||||||
domain, // domain name
|
|
||||||
urlpath, // sub url path, like: www.example.com/<urlpath>
|
|
||||||
debug,
|
|
||||||
GOOGLE_API_KEY,
|
|
||||||
GOOGLE_CLIENT_ID,
|
|
||||||
DROPBOX_APP_KEY
|
|
||||||
} from './config';
|
|
||||||
|
|
||||||
//common
|
|
||||||
export const port = window.location.port;
|
|
||||||
window.serverurl = `${window.location.protocol}//${domain ? domain : window.location.hostname}${port ? ':' + port : ''}${urlpath ? '/' + urlpath : ''}`;
|
|
||||||
export const noteid = urlpath ? window.location.pathname.slice(urlpath.length + 1, window.location.pathname.length).split('/')[1] : window.location.pathname.split('/')[1];
|
|
||||||
export const noteurl = `${serverurl}/${noteid}`;
|
|
||||||
|
|
||||||
export const version = '0.5.0';
|
|
||||||
|
|
||||||
let checkAuth = false;
|
let checkAuth = false;
|
||||||
let profile = null;
|
let profile = null;
|
||||||
|
@ -49,7 +32,7 @@ export function setLoginState(bool, id) {
|
||||||
|
|
||||||
export function checkLoginStateChanged() {
|
export function checkLoginStateChanged() {
|
||||||
if (getLoginState() != lastLoginState || getUserId() != lastUserId) {
|
if (getLoginState() != lastLoginState || getUserId() != lastUserId) {
|
||||||
if(loginStateChangeEvent) {
|
if (loginStateChangeEvent) {
|
||||||
loginStateChangeEvent();
|
loginStateChangeEvent();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -101,12 +84,6 @@ export function checkIfAuth(yesCallback, noCallback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
domain,
|
|
||||||
urlpath,
|
|
||||||
debug,
|
|
||||||
GOOGLE_API_KEY,
|
|
||||||
GOOGLE_CLIENT_ID,
|
|
||||||
DROPBOX_APP_KEY,
|
|
||||||
checkAuth,
|
checkAuth,
|
||||||
profile,
|
profile,
|
||||||
lastLoginState,
|
lastLoginState,
|
19
public/js/lib/config/index.js
Normal file
19
public/js/lib/config/index.js
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import configJson from '../../../../config.json'; // root path json config
|
||||||
|
|
||||||
|
const config = 'production' === process.env.NODE_ENV ? configJson.production : configJson.development;
|
||||||
|
|
||||||
|
export const GOOGLE_API_KEY = (config.google && config.google.apiKey) || '';
|
||||||
|
export const GOOGLE_CLIENT_ID = (config.google && config.google.clientID) || '';
|
||||||
|
export const DROPBOX_APP_KEY = (config.dropbox && config.dropbox.appKey) || '';
|
||||||
|
|
||||||
|
export const domain = config.domain || ''; // domain name
|
||||||
|
export const urlpath = config.urlpath || ''; // sub url path, like: www.example.com/<urlpath>
|
||||||
|
export const debug = config.debug || false;
|
||||||
|
|
||||||
|
export const port = window.location.port;
|
||||||
|
export const serverurl = `${window.location.protocol}//${domain ? domain : window.location.hostname}${port ? ':' + port : ''}${urlpath ? '/' + urlpath : ''}`;
|
||||||
|
window.serverurl = serverurl;
|
||||||
|
export const noteid = urlpath ? window.location.pathname.slice(urlpath.length + 1, window.location.pathname.length).split('/')[1] : window.location.pathname.split('/')[1];
|
||||||
|
export const noteurl = `${serverurl}/${noteid}`;
|
||||||
|
|
||||||
|
export const version = '0.5.0';
|
Loading…
Reference in a new issue