Fix #74
This commit is contained in:
parent
91a8fdf871
commit
0fad1e3e34
|
@ -7,6 +7,7 @@
|
|||
"login": "Login",
|
||||
"username": "Username",
|
||||
"current_user": "Current User",
|
||||
"current_session": "Current Session",
|
||||
"password": "Password",
|
||||
"login_error": "Login Error",
|
||||
"run": "Run",
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
"login": "ログイン",
|
||||
"username": "ユーザ名",
|
||||
"current_user": "現在のユーザ",
|
||||
"current_session": "現在のセッション",
|
||||
"password": "パスワード",
|
||||
"login_error": "ログインエラー",
|
||||
"run": "実行",
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
"login": "登录",
|
||||
"username": "用户名",
|
||||
"current_user": "当前用户",
|
||||
"current_session": "当前会话",
|
||||
"password": "密码",
|
||||
"login_error": "登录失败",
|
||||
"run": "运行",
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
"login": "登錄",
|
||||
"username": "用户名字",
|
||||
"current_user": "當前用户名",
|
||||
"current_session": "當前會話",
|
||||
"password": "密碼",
|
||||
"login_error": "登錄失败",
|
||||
"run": "執行",
|
||||
|
|
14
main.go
14
main.go
|
@ -3,9 +3,11 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"html/template"
|
||||
"math/rand"
|
||||
"mime"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/b3log/wide/conf"
|
||||
|
@ -53,7 +55,9 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
|
|||
httpSession.Save(r, w)
|
||||
|
||||
// create a Wide session
|
||||
wideSession := session.WideSessions.New(httpSession)
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
sid := strconv.Itoa(rand.Int())
|
||||
wideSession := session.WideSessions.New(httpSession, sid)
|
||||
|
||||
username := httpSession.Values["username"].(string)
|
||||
user := conf.Wide.GetUser(username)
|
||||
|
@ -112,8 +116,14 @@ func startHandler(w http.ResponseWriter, r *http.Request) {
|
|||
locale := conf.Wide.GetUser(username).Locale
|
||||
userWorkspace := conf.Wide.GetUserWorkspace(username)
|
||||
|
||||
sid := r.URL.Query()["sid"][0]
|
||||
wSession := session.WideSessions.Get(sid)
|
||||
if nil == wSession {
|
||||
glog.Errorf("Session [%s] not found", sid)
|
||||
}
|
||||
|
||||
model := map[string]interface{}{"conf": conf.Wide, "i18n": i18n.GetAll(locale), "locale": locale,
|
||||
"username": username, "workspace": userWorkspace, "ver": conf.WideVersion}
|
||||
"username": username, "workspace": userWorkspace, "ver": conf.WideVersion, "session": wSession}
|
||||
|
||||
t, err := template.ParseFiles("views/start.html")
|
||||
|
||||
|
|
|
@ -75,9 +75,8 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
|
|||
sid := r.URL.Query()["sid"][0]
|
||||
|
||||
wSession := session.WideSessions.Get(sid)
|
||||
if nil == wSession {
|
||||
glog.Errorf("Session [%s] not found", sid)
|
||||
|
||||
if nil == wSession {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -10,10 +10,8 @@ package session
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -97,9 +95,18 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
|
|||
sid := r.URL.Query()["sid"][0]
|
||||
wSession := WideSessions.Get(sid)
|
||||
if nil == wSession {
|
||||
glog.Errorf("Session [%s] not found", sid)
|
||||
httpSession, _ := HTTPSession.Get(r, "wide-session")
|
||||
|
||||
return
|
||||
if httpSession.IsNew {
|
||||
return
|
||||
}
|
||||
|
||||
httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge
|
||||
httpSession.Save(r, w)
|
||||
|
||||
WideSessions.New(httpSession, sid)
|
||||
|
||||
glog.Infof("Created a wide session [%s] for websocket reconnecting", sid)
|
||||
}
|
||||
|
||||
conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024)
|
||||
|
@ -107,7 +114,7 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
SessionWS[sid] = &wsChan
|
||||
|
||||
ret := map[string]interface{}{"output": "Ouput initialized", "cmd": "init-session"}
|
||||
ret := map[string]interface{}{"output": "Session initialized", "cmd": "init-session"}
|
||||
wsChan.Conn.WriteJSON(&ret)
|
||||
|
||||
glog.V(4).Infof("Open a new [Session Channel] with session [%s], %d", sid, len(SessionWS))
|
||||
|
@ -185,20 +192,17 @@ func (s *WideSession) Refresh() {
|
|||
}
|
||||
|
||||
// New creates a wide session.
|
||||
func (sessions *Sessions) New(httpSession *sessions.Session) *WideSession {
|
||||
func (sessions *Sessions) New(httpSession *sessions.Session, sid string) *WideSession {
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
id := strconv.Itoa(rand.Int())
|
||||
now := time.Now()
|
||||
|
||||
// create user event queue
|
||||
userEventQueue := event.UserEventQueues.New(id)
|
||||
// create user event queuselect
|
||||
userEventQueue := event.UserEventQueues.New(sid)
|
||||
|
||||
ret := &WideSession{
|
||||
Id: id,
|
||||
Id: sid,
|
||||
Username: httpSession.Values["username"].(string),
|
||||
HTTPSession: httpSession,
|
||||
EventQueue: userEventQueue,
|
||||
|
|
|
@ -3,10 +3,12 @@ package shell
|
|||
|
||||
import (
|
||||
"html/template"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -37,7 +39,9 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
|||
httpSession.Save(r, w)
|
||||
|
||||
// create a wide session
|
||||
wideSession := session.WideSessions.New(httpSession)
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
sid := strconv.Itoa(rand.Int())
|
||||
wideSession := session.WideSessions.New(httpSession, sid)
|
||||
|
||||
username := httpSession.Values["username"].(string)
|
||||
locale := conf.Wide.GetUser(username).Locale
|
||||
|
|
|
@ -180,7 +180,7 @@ var editors = {
|
|||
title: '<span title="' + config.label.start_page + '">' + config.label.start_page + '</span>',
|
||||
content: '<div id="startPage"></div>',
|
||||
after: function () {
|
||||
$("#startPage").load('/start');
|
||||
$("#startPage").load('/start?sid=' + config.wideSessionId);
|
||||
$.ajax({
|
||||
url: "http://symphony.b3log.org/apis/articles?tags=wide,golang&p=1&size=30",
|
||||
type: "GET",
|
||||
|
|
|
@ -30,7 +30,6 @@ var notification = {
|
|||
|
||||
notificationWS.onclose = function (e) {
|
||||
console.log('[notification onclose] disconnected (' + e.code + ')');
|
||||
delete notificationWS;
|
||||
};
|
||||
|
||||
notificationWS.onerror = function (e) {
|
||||
|
|
|
@ -83,16 +83,56 @@ var session = {
|
|||
|
||||
sessionWS.onopen = function () {
|
||||
console.log('[session onopen] connected');
|
||||
|
||||
var dateFormat = function (time, fmt) {
|
||||
var date = new Date(time);
|
||||
var dateObj = {
|
||||
"M+": date.getMonth() + 1, //月份
|
||||
"d+": date.getDate(), //日
|
||||
"h+": date.getHours(), //小时
|
||||
"m+": date.getMinutes(), //分
|
||||
"s+": date.getSeconds(), //秒
|
||||
"q+": Math.floor((date.getMonth() + 3) / 3), //季度
|
||||
"S": date.getMilliseconds() //毫秒
|
||||
};
|
||||
if (/(y+)/.test(fmt))
|
||||
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
|
||||
for (var k in dateObj)
|
||||
if (new RegExp("(" + k + ")").test(fmt)) {
|
||||
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1)
|
||||
? (dateObj[k]) : (("00" + dateObj[k]).substr(("" + dateObj[k]).length)));
|
||||
}
|
||||
return fmt;
|
||||
};
|
||||
|
||||
var data = {type: "Network", severity: "INFO",
|
||||
message: "Connected to server [sid=" + config.wideSessionId + "], " + dateFormat(new Date().getTime(), 'yyyy-MM-dd hh:mm:ss')},
|
||||
$notification = $('.bottom-window-group .notification > table'),
|
||||
notificationHTML = '';
|
||||
|
||||
notificationHTML += '<tr><td class="severity">' + data.severity
|
||||
+ '</td><td class="message">' + data.message
|
||||
+ '</td><td class="type">' + data.type + '</td></tr>';
|
||||
$notification.append(notificationHTML);
|
||||
};
|
||||
|
||||
sessionWS.onmessage = function (e) {
|
||||
console.log('[session onmessage]' + e.data);
|
||||
var data = JSON.parse(e.data);
|
||||
|
||||
};
|
||||
sessionWS.onclose = function (e) {
|
||||
console.log('[session onclose] disconnected (' + e.code + ')');
|
||||
delete sessionWS;
|
||||
|
||||
var data = {type: "Network", severity: "ERROR",
|
||||
message: "Disconnected from server, trying to reconnect it [sid=" + config.wideSessionId + "]"},
|
||||
$notification = $('.bottom-window-group .notification > table'),
|
||||
notificationHTML = '';
|
||||
|
||||
notificationHTML += '<tr><td class="severity">' + data.severity
|
||||
+ '</td><td class="message">' + data.message
|
||||
+ '</td><td class="type">' + data.type + '</td></tr>';
|
||||
$notification.append(notificationHTML);
|
||||
|
||||
$(".notification-count").show();
|
||||
};
|
||||
sessionWS.onerror = function (e) {
|
||||
console.log('[session onerror] ' + JSON.parse(e));
|
||||
|
|
|
@ -14,7 +14,6 @@ var shell = {
|
|||
};
|
||||
shell.shellWS.onclose = function (e) {
|
||||
console.log('[shell onclose] disconnected (' + e.code + ')');
|
||||
delete shell.shellWS;
|
||||
};
|
||||
shell.shellWS.onerror = function (e) {
|
||||
console.log('[shell onerror] ' + e);
|
||||
|
|
|
@ -387,7 +387,6 @@ var wide = {
|
|||
};
|
||||
outputWS.onclose = function (e) {
|
||||
console.log('[output onclose] disconnected (' + e.code + ')');
|
||||
delete outputWS;
|
||||
};
|
||||
outputWS.onerror = function (e) {
|
||||
console.log('[output onerror] ' + e);
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
<label>{{.i18n.current_user}}{{.i18n.colon}}</label>
|
||||
{{.username}}
|
||||
</li>
|
||||
<li>
|
||||
<label>{{.i18n.current_session}}{{.i18n.colon}}</label>
|
||||
{{.session.Id}}
|
||||
</li>
|
||||
<li class="border workspace">
|
||||
<label>{{.i18n.workspace}}{{.i18n.colon}}</label>
|
||||
<span>{{.workspace}}</span>
|
||||
|
|
Loading…
Reference in New Issue