This commit is contained in:
parent
b5aa4f9a7d
commit
003354ffe4
|
@ -76,7 +76,7 @@ type editor struct {
|
||||||
TabSize string
|
TabSize string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save saves the user's configurations in conf/users/{username}.json.
|
// Save saves the user's configurations in conf/users/{userId}.json.
|
||||||
func (u *User) Save() bool {
|
func (u *User) Save() bool {
|
||||||
bytes, err := json.MarshalIndent(u, "", " ")
|
bytes, err := json.MarshalIndent(u, "", " ")
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ var Docker bool
|
||||||
// Docker image to run user's program
|
// Docker image to run user's program
|
||||||
const DockerImageGo = "golang"
|
const DockerImageGo = "golang"
|
||||||
|
|
||||||
// Load loads the Wide configurations from wide.json and users' configurations from users/{username}.json.
|
// Load loads the Wide configurations from wide.json and users' configurations from users/{userId}.json.
|
||||||
func Load(confPath, confUsers, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, confPlayground string, confUsersWorkspaces string) {
|
func Load(confPath, confUsers, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, confPlayground string, confUsersWorkspaces string) {
|
||||||
initWide(confPath, confUsers, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, confPlayground, confUsersWorkspaces)
|
initWide(confPath, confUsers, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, confPlayground, confUsersWorkspaces)
|
||||||
initUsers()
|
initUsers()
|
||||||
|
@ -391,7 +391,7 @@ func initCustomizedConfs() {
|
||||||
|
|
||||||
// UpdateCustomizedConf creates (if not exists) or updates user customized configuration files.
|
// UpdateCustomizedConf creates (if not exists) or updates user customized configuration files.
|
||||||
//
|
//
|
||||||
// 1. /static/user/{username}/style.css
|
// 1. /static/user/{userId}/style.css
|
||||||
func UpdateCustomizedConf(userId string) {
|
func UpdateCustomizedConf(userId string) {
|
||||||
var u *User
|
var u *User
|
||||||
for _, user := range Users { // maybe it is a beauty of the trade-off of the another world between design and implementation
|
for _, user := range Users { // maybe it is a beauty of the trade-off of the another world between design and implementation
|
||||||
|
|
|
@ -40,7 +40,7 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
username := session.Values["username"].(string)
|
uid := session.Values["uid"].(string)
|
||||||
|
|
||||||
var args map[string]interface{}
|
var args map[string]interface{}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
result.Data = data
|
result.Data = data
|
||||||
|
|
||||||
fmt := conf.GetGoFmt(username)
|
fmt := conf.GetGoFmt(uid)
|
||||||
|
|
||||||
argv := []string{filePath}
|
argv := []string{filePath}
|
||||||
cmd := exec.Command(fmt, argv...)
|
cmd := exec.Command(fmt, argv...)
|
||||||
|
|
|
@ -204,8 +204,8 @@ func GetFileHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
data["mode"] = "img"
|
data["mode"] = "img"
|
||||||
|
|
||||||
username := conf.GetOwner(path)
|
userId := conf.GetOwner(path)
|
||||||
if "" == username {
|
if "" == userId {
|
||||||
logger.Warnf("The path [%s] has no owner", path)
|
logger.Warnf("The path [%s] has no owner", path)
|
||||||
data["path"] = ""
|
data["path"] = ""
|
||||||
|
|
||||||
|
|
|
@ -155,8 +155,6 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// logger.Debugf("User [%s, %s] is building [id=%d, dir=%s]", username, sid, runningId, curDir)
|
|
||||||
|
|
||||||
channelRet["cmd"] = "build"
|
channelRet["cmd"] = "build"
|
||||||
channelRet["executable"] = executable
|
channelRet["executable"] = executable
|
||||||
|
|
||||||
|
|
|
@ -155,8 +155,6 @@ func CrossCompilationHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
defer util.Recover()
|
defer util.Recover()
|
||||||
defer cmd.Wait()
|
defer cmd.Wait()
|
||||||
|
|
||||||
// logger.Debugf("User [%s, %s] is building [id=%d, dir=%s]", username, sid, runningId, curDir)
|
|
||||||
|
|
||||||
// read all
|
// read all
|
||||||
buf, _ := ioutil.ReadAll(reader)
|
buf, _ := ioutil.ReadAll(reader)
|
||||||
|
|
||||||
|
@ -235,8 +233,6 @@ func CrossCompilationHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil != session.OutputWS[sid] {
|
if nil != session.OutputWS[sid] {
|
||||||
// logger.Debugf("User [%s, %s] 's build [id=%d, dir=%s] has done", username, sid, runningId, curDir)
|
|
||||||
|
|
||||||
wsChannel := session.OutputWS[sid]
|
wsChannel := session.OutputWS[sid]
|
||||||
err := wsChannel.WriteJSON(&channelRet)
|
err := wsChannel.WriteJSON(&channelRet)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
|
@ -43,7 +43,7 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
httpSession, _ := session.HTTPSession.Get(r, "wide-session")
|
httpSession, _ := session.HTTPSession.Get(r, "wide-session")
|
||||||
if httpSession.IsNew {
|
if httpSession.IsNew {
|
||||||
httpSession.Values["id"] = strconv.Itoa(rand.Int())
|
httpSession.Values["id"] = strconv.Itoa(rand.Int())
|
||||||
httpSession.Values["username"] = "playground"
|
httpSession.Values["uid"] = "playground"
|
||||||
}
|
}
|
||||||
|
|
||||||
httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge
|
httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge
|
||||||
|
|
|
@ -111,7 +111,7 @@ func GithubCallbackHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// create a HTTP session
|
// create a HTTP session
|
||||||
httpSession, _ := HTTPSession.Get(r, "wide-session")
|
httpSession, _ := HTTPSession.Get(r, "wide-session")
|
||||||
httpSession.Values["username"] = userName
|
httpSession.Values["uid"] = githubId
|
||||||
|
|
||||||
httpSession.Values["id"] = strconv.Itoa(rand.Int())
|
httpSession.Values["id"] = strconv.Itoa(rand.Int())
|
||||||
httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge
|
httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge
|
||||||
|
@ -120,7 +120,7 @@ func GithubCallbackHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
httpSession.Save(r, w)
|
httpSession.Save(r, w)
|
||||||
|
|
||||||
logger.Debugf("Created a HTTP session [%s] for user [%s]", httpSession.Values["id"].(string), userName)
|
logger.Debugf("Created a HTTP session [%s] for user [%s]", httpSession.Values["id"].(string), githubId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GitHubUserInfo returns GitHub user info specified by the given access token.
|
// GitHubUserInfo returns GitHub user info specified by the given access token.
|
||||||
|
|
|
@ -122,7 +122,7 @@ func FixedTimeRelease() {
|
||||||
|
|
||||||
// Online user statistic report.
|
// Online user statistic report.
|
||||||
type userReport struct {
|
type userReport struct {
|
||||||
username string
|
userId string
|
||||||
sessionCnt int
|
sessionCnt int
|
||||||
processCnt int
|
processCnt int
|
||||||
updated time.Time
|
updated time.Time
|
||||||
|
@ -130,7 +130,7 @@ type userReport struct {
|
||||||
|
|
||||||
// report returns a online user statistics in pretty format.
|
// report returns a online user statistics in pretty format.
|
||||||
func (u *userReport) report() string {
|
func (u *userReport) report() string {
|
||||||
return "[" + u.username + "] has [" + strconv.Itoa(u.sessionCnt) + "] sessions and [" + strconv.Itoa(u.processCnt) +
|
return "[" + u.userId + "] has [" + strconv.Itoa(u.sessionCnt) + "] sessions and [" + strconv.Itoa(u.processCnt) +
|
||||||
"] running processes, latest activity [" + u.updated.Format("2006-01-02 15:04:05") + "]"
|
"] running processes, latest activity [" + u.updated.Format("2006-01-02 15:04:05") + "]"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ func FixedTimeReport() {
|
||||||
report.sessionCnt++
|
report.sessionCnt++
|
||||||
report.processCnt += processCnt
|
report.processCnt += processCnt
|
||||||
} else {
|
} else {
|
||||||
users = append(users, &userReport{username: s.UserId, sessionCnt: 1, processCnt: processCnt, updated: s.Updated})
|
users = append(users, &userReport{userId: s.UserId, sessionCnt: 1, processCnt: processCnt, updated: s.Updated})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,9 +174,9 @@ func FixedTimeReport() {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func contains(reports []*userReport, username string) (*userReport, bool) {
|
func contains(reports []*userReport, userId string) (*userReport, bool) {
|
||||||
for _, ur := range reports {
|
for _, ur := range reports {
|
||||||
if username == ur.username {
|
if userId == ur.userId {
|
||||||
return ur, true
|
return ur, true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue