Skip to content

Commit c628737

Browse files
committed
Merge branch 'develop' into refactor-realtime
Signed-off-by: BoHong Li <raccoon@hackmd.io> # Conflicts: # README.md # package.json
2 parents 0f51d1e + 7f60206 commit c628737

File tree

19 files changed

+494
-49
lines changed

19 files changed

+494
-49
lines changed

README.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
2-
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
3-
# Table of Contents
4-
5-
- [CodiMD](#codimd)
6-
- [CodiMD - The Open Source HackMD](#codimd---the-open-source-hackmd)
7-
- [Documentation](#documentation)
8-
- [Deployment](#deployment)
9-
- [Configuration](#configuration)
10-
- [Upgrading and Migration](#upgrading-and-migration)
11-
- [Developer](#developer)
12-
- [Contribution and Discussion](#contribution-and-discussion)
13-
- [Browser Support](#browser-support)
14-
- [License](#license)
15-
16-
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
17-
181
CodiMD
192
===
203

214
[![CodiMD on Gitter][gitter-image]][gitter-url]
225
[![build status][travis-image]][travis-url]
236
[![version][github-version-badge]][github-release-page]
7+
[![Gitter][gitter-image]][gitter-url]
248
[![POEditor][poeditor-image]][poeditor-url]
259

2610
CodiMD lets you collaborate in real-time with markdown.
2711
Built on [HackMD](https://hackmd.io) source code, CodiMD lets you host and control your team's content with speed and ease.
2812

13+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
14+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
15+
# Table of Contents
16+
17+
- [CodiMD - The Open Source HackMD](#codimd---the-open-source-hackmd)
18+
- [Documentation](#documentation)
19+
- [Deployment](#deployment)
20+
- [Configuration](#configuration)
21+
- [Upgrading and Migration](#upgrading-and-migration)
22+
- [Developer](#developer)
23+
- [Contribution and Discussion](#contribution-and-discussion)
24+
- [Browser Support](#browser-support)
25+
- [License](#license)
26+
27+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
28+
2929
## CodiMD - The Open Source HackMD
3030
[HackMD](https://hackmd.io) helps developers write better documents and build active communities with open collaboration.
3131
HackMD is built with one promise - **You own and control all your content**:
@@ -47,7 +47,7 @@ If you want to spin up an instance and start using immediately, see [Docker depl
4747
If you want to contribute to the project, start with [manual deployment](https://hackmd.io/c/codimd-documentation/%2Fs%2Fcodimd-manual-deployment).
4848

4949
### Configuration
50-
CodiMD is highly customizable. Learn about all configuration options of networking, security, performance, resources, privilege, privacy, image storage, and authentication in [CodiMD Configuration](https://hackmd.io/c/codimd-documentation/%2Fs%2Fcodimd-configuration).
50+
CodiMD is highly customizable, learn about all configuration options of networking, security, performance, resources, privilege, privacy, image storage, and authentication in [CodiMD Configuration](https://hackmd.io/c/codimd-documentation/%2Fs%2Fcodimd-configuration).
5151

5252
### Upgrading and Migration
5353
Upgrade CodiMD from previous version? See [this guide](https://hackmd.io/c/codimd-documentation/%2Fs%2Fcodimd-upgrade)
@@ -61,10 +61,10 @@ All contributions are welcome! Even asking a question helps.
6161

6262
| Project | Contribution Types | Contribution Venue |
6363
| ------- | ------------------ | ------------------ |
64-
|**CodiMD**|:couple: Community chat|[Gitter](https://gitter.im/hackmdio/hackmd)|
64+
|**CodiMD**|:couple: Community chat|[Gitter][gitter-url]|
6565
||:bug: Issues, bugs, and feature requests|[Issue tracker](https://github.com/hackmdio/codimd/issues)|
6666
||:books: Improve documentation|[Documentations](https://hackmd.io/c/codimd-documentation)|
67-
||:pencil: Translation|[POEditor](https://poeditor.com/join/project/q0nuPWyztp)|
67+
||:pencil: Translation|[POEditor][poeditor-url]|
6868
||:coffee: Donation|[Buy us coffee](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=KDGS4PREHX6QQ&lc=US&item_name=HackMD&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted)|
6969
|**HackMD**|:question: Issues related to [HackMD](https://hackmd.io/)|[Issue tracker](https://github.com/hackmdio/hackmd-io-issues/issues)|
7070
||:pencil2: Translation|[hackmd-locales](https://github.com/hackmdio/hackmd-locales/tree/master/locales)|
@@ -96,8 +96,8 @@ To stay up to date with your installation it's recommended to subscribe the [rel
9696

9797
[gitter-image]: https://img.shields.io/badge/gitter-hackmdio/codimd-blue.svg
9898
[gitter-url]: https://gitter.im/hackmdio/hackmd
99-
[travis-image]: https://travis-ci.com/hackmdio/codimd.svg?branch=develop
100-
[travis-url]: https://travis-ci.org/hackmdio/codimd
99+
[travis-image]: https://travis-ci.com/hackmdio/codimd.svg?branch=master
100+
[travis-url]: https://travis-ci.com/hackmdio/codimd
101101
[github-version-badge]: https://img.shields.io/github/release/hackmdio/codimd.svg
102102
[github-release-page]: https://github.com/hackmdio/codimd/releases
103103
[github-release-feed]: https://github.com/hackmdio/codimd/releases.atom

app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"Markdown",
77
"Notes"
88
],
9-
"website": "https://codimd.org",
9+
"website": "https://github.com/hackmdio/codimd",
1010
"repository": "https://github.com/hackmdio/codimd",
1111
"logo": "https://github.com/hackmdio/codimd/raw/master/public/codimd-icon-1024.png",
1212
"success_url": "/",

lib/config/default.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ module.exports = {
5656
// socket.io
5757
heartbeatInterval: 5000,
5858
heartbeatTimeout: 10000,
59+
// toobusy-js
60+
responseMaxLag: 70,
5961
// document
6062
documentMaxLength: 100000,
6163
// image upload setting, available options are imgur/s3/filesystem/azure

lib/config/environment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module.exports = {
3333
dbURL: process.env.CMD_DB_URL,
3434
sessionSecret: process.env.CMD_SESSION_SECRET,
3535
sessionLife: toIntegerConfig(process.env.CMD_SESSION_LIFE),
36+
responseMaxLag: toIntegerConfig(process.env.CMD_RESPONSE_MAX_LAG),
3637
imageUploadType: process.env.CMD_IMAGE_UPLOAD_TYPE,
3738
imgur: {
3839
clientID: process.env.CMD_IMGUR_CLIENTID

lib/config/hackmdEnvironment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module.exports = {
2828
dbURL: process.env.HMD_DB_URL,
2929
sessionSecret: process.env.HMD_SESSION_SECRET,
3030
sessionLife: toIntegerConfig(process.env.HMD_SESSION_LIFE),
31+
responseMaxLag: toIntegerConfig(process.env.HMD_RESPONSE_MAX_LAG),
3132
imageUploadType: process.env.HMD_IMAGE_UPLOAD_TYPE,
3233
imgur: {
3334
clientID: process.env.HMD_IMGUR_CLIENTID

lib/web/middleware/tooBusy.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
const toobusy = require('toobusy-js')
44

5+
const config = require('../../config')
56
const response = require('../../response')
67

8+
toobusy.maxLag(config.responseMaxLag)
9+
710
module.exports = function (req, res, next) {
811
if (toobusy()) {
912
response.errorServiceUnavailable(res)

lib/web/userRouter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ UserRouter.get('/me', function (req, res) {
3333
return response.errorInternalError(res)
3434
})
3535
} else {
36-
res.send({
36+
res.status(401).send({
3737
status: 'forbidden'
3838
})
3939
}

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"test:ci": "npm run-script lint && npm run-script jsonlint && npm run-script coverage:ci"
3030
},
3131
"dependencies": {
32-
"@hackmd/codemirror": "~5.41.2",
32+
"@hackmd/codemirror": "~5.46.2",
3333
"@hackmd/diff-match-patch": "~1.1.1",
3434
"@hackmd/idle-js": "~1.0.1",
3535
"@hackmd/imgur": "~0.4.1",
@@ -48,6 +48,7 @@
4848
"bootstrap-validator": "~0.11.8",
4949
"chance": "~1.0.4",
5050
"cheerio": "~0.22.0",
51+
"compression": "~1.7.4",
5152
"connect-flash": "~0.1.1",
5253
"connect-session-sequelize": "~6.0.0",
5354
"cookie": "~0.3.1",
@@ -58,7 +59,7 @@
5859
"express": "~4.16.4",
5960
"express-session": "~1.16.1",
6061
"file-saver": "~1.3.3",
61-
"flowchart.js": "~1.6.4",
62+
"flowchart.js": "~1.12.0",
6263
"fork-awesome": "~1.1.3",
6364
"formidable": "~1.2.1",
6465
"gist-embed": "~2.6.0",
@@ -94,7 +95,7 @@
9495
"markdown-pdf": "~9.0.0",
9596
"mathjax": "~2.7.0",
9697
"mattermost-redux": "~5.9.0",
97-
"mermaid": "~7.1.0",
98+
"mermaid": "~8.2.3",
9899
"method-override": "~2.3.7",
99100
"minimist": "~1.2.0",
100101
"minio": "~6.0.0",
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
var ElapsedTimeBar = {
2+
// default value
3+
barColor: 'rgb(200,0,0)',
4+
pausedBarColor: 'rgba(200,0,0,.6)',
5+
6+
isPaused: false,
7+
isFinished: false,
8+
9+
allottedTime: null,
10+
timeProgressBar: null,
11+
startTime: null,
12+
pauseTime: null,
13+
pauseTimeDuration: 0,
14+
15+
/**
16+
* initialize elements
17+
*/
18+
handleReady() {
19+
var config = Reveal.getConfig();
20+
21+
// activate this plugin if config.allottedTime exists.
22+
if (!config.allottedTime) {
23+
console.warn('Failed to start ElapsedTimeBar plugin. "allottedTime" property is required.');
24+
return;
25+
}
26+
27+
// set configurations
28+
this.barColor = config.barColor || this.barColor;
29+
this.pausedBarColor = config.pausedBarColor || this.pausedBarColor;
30+
31+
// calc barHeight from config.barHeight or page-progress container
32+
var barHeight;
33+
var pageProgressContainer = document.querySelector('.progress');
34+
if (config.progressBarHeight) {
35+
barHeight = parseInt(config.progressBarHeight, 10) + 'px';
36+
37+
// override height of page-progress container
38+
pageProgressContainer && (pageProgressContainer.style.height = barHeight);
39+
} else if (config.progress && pageProgressContainer) {
40+
// get height from page-progress container
41+
barHeight = pageProgressContainer.getBoundingClientRect().height + 'px';
42+
} else {
43+
// default
44+
barHeight = '3px';
45+
}
46+
47+
// create container of time-progress
48+
var timeProgressContainer = document.createElement('div');
49+
timeProgressContainer.classList.add('progress');
50+
Object.entries({
51+
display: 'block',
52+
position: 'fixed',
53+
bottom: config.progress ? barHeight : 0,
54+
width: '100%',
55+
height: barHeight
56+
}).forEach(([k, v]) => {
57+
timeProgressContainer.style[k] = v;
58+
});
59+
document.querySelector('.reveal').appendChild(timeProgressContainer);
60+
61+
// create content of time-progress
62+
this.timeProgressBar = document.createElement('div');
63+
Object.entries({
64+
height: '100%',
65+
willChange: 'width'
66+
}).forEach(([k, v]) => {
67+
this.timeProgressBar.style[k] = v;
68+
});
69+
timeProgressContainer.appendChild(this.timeProgressBar);
70+
71+
// start timer
72+
this.start(config.allottedTime);
73+
},
74+
75+
/**
76+
* update repeatedly using requestAnimationFrame.
77+
*/
78+
loop() {
79+
if (this.isPaused) return;
80+
var now = +new Date();
81+
var elapsedTime = now - this.startTime - this.pauseTimeDuration;
82+
if (elapsedTime > this.allottedTime) {
83+
this.timeProgressBar.style.width = '100%';
84+
this.isFinished = true;
85+
} else {
86+
this.timeProgressBar.style.width = elapsedTime / this.allottedTime * 100 + '%';
87+
requestAnimationFrame(this.loop.bind(this));
88+
}
89+
},
90+
91+
/**
92+
* set color of progress bar
93+
*/
94+
setBarColor() {
95+
if (this.isPaused) {
96+
this.timeProgressBar.style.backgroundColor = this.pausedBarColor;
97+
} else {
98+
this.timeProgressBar.style.backgroundColor = this.barColor;
99+
}
100+
},
101+
102+
/**
103+
* start(reset) timer with new allotted time.
104+
* @param {number} allottedTime
105+
* @param {number} [elapsedTime=0]
106+
*/
107+
start(allottedTime, elapsedTime = 0) {
108+
this.isFinished = false;
109+
this.isPaused = false;
110+
this.allottedTime = allottedTime;
111+
this.startTime = +new Date() - elapsedTime;
112+
this.pauseTimeDuration = 0;
113+
this.setBarColor();
114+
this.loop();
115+
},
116+
117+
reset() {
118+
this.start(this.allottedTime);
119+
},
120+
121+
pause() {
122+
if (this.isPaused) return;
123+
this.isPaused = true;
124+
this.pauseTime = +new Date();
125+
this.setBarColor();
126+
},
127+
128+
resume() {
129+
if (!this.isPaused) return;
130+
131+
// add paused time duration
132+
this.isPaused = false;
133+
this.pauseTimeDuration += new Date() - this.pauseTime;
134+
this.pauseTime = null;
135+
this.setBarColor();
136+
this.loop();
137+
}
138+
};
139+
140+
if (Reveal.isReady()) {
141+
ElapsedTimeBar.handleReady();
142+
} else {
143+
Reveal.addEventListener('ready', () => ElapsedTimeBar.handleReady());
144+
}

0 commit comments

Comments
 (0)