This commit is contained in:
Liang Ding 2019-05-17 11:25:44 +08:00
parent 8b0b1503c3
commit d0396da439
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
7 changed files with 18 additions and 74 deletions

View File

@ -102,8 +102,6 @@ func Load(confPath, confData, confServer, confLogLevel string) {
}
func initUsers() {
os.MkdirAll(Wide.Data+PathSeparator+"users", 0755)
f, err := os.Open(Wide.Data + PathSeparator + "users")
if nil != err {
logger.Error(err)
@ -202,12 +200,20 @@ func initWide(confPath, confData, confServer, confLogLevel string) {
}
Wide.Data = strings.Replace(Wide.Data, "${home}", home, -1)
Wide.Data = filepath.Clean(Wide.Data)
if !util.File.IsExist(Wide.Data) {
if err := os.MkdirAll(Wide.Data, 0775); nil != err {
logger.Errorf("Create data directory [%s] error", err)
if err := os.MkdirAll(Wide.Data+"/playground/", 0755); nil != err {
logger.Errorf("Create data directory [%s] error", err)
os.Exit(-1)
}
os.Exit(-1)
}
if err := os.MkdirAll(Wide.Data+"/users/", 0755); nil != err {
logger.Errorf("Create data directory [%s] error", err)
os.Exit(-1)
}
if err := os.MkdirAll(Wide.Data+"/workspaces/", 0755); nil != err {
logger.Errorf("Create data directory [%s] error", err)
os.Exit(-1)
}
// Server

View File

@ -85,7 +85,7 @@ func SaveHandler(w http.ResponseWriter, r *http.Request) {
data["fileName"] = fileName
// Step3. write file
filePath := filepath.Clean(conf.Wide.Data + "/playground" + fileName)
filePath := filepath.Clean(conf.Wide.Data + "/playground/" + fileName)
fout, err := os.Create(filePath)
fout.WriteString(code)
if err := fout.Close(); nil != err {

View File

@ -59,7 +59,7 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
if strings.HasSuffix(r.URL.Path, ".go") {
fileNameArg := r.URL.Path[len("/playground/"):]
filePath := filepath.Clean(conf.Wide.Data+ "/playground" + fileNameArg)
filePath := filepath.Clean(conf.Wide.Data+ "/playground/" + fileNameArg)
bytes, err := ioutil.ReadFile(filePath)
if nil != err {
@ -94,7 +94,6 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
logger.Debugf("User [%s] has [%d] sessions", uid, len(wideSessions))
t, err := template.ParseFiles("views/playground/index.html")
if nil != err {
logger.Error(err)
http.Error(w, err.Error(), http.StatusInternalServerError)

View File

@ -209,14 +209,7 @@ func addUser(userId, userName, userAvatar string) string {
}
// helloWorld generates the 'Hello, 世界' source code.
// 1. src/hello/main.go
// 2. src/web/main.go
func helloWorld(workspace string) {
consoleHello(workspace)
webHello(workspace)
}
func consoleHello(workspace string) {
dir := workspace + conf.PathSeparator + "src" + conf.PathSeparator + "hello"
if err := os.MkdirAll(dir, 0755); nil != err {
logger.Error(err)
@ -232,59 +225,5 @@ func consoleHello(workspace string) {
}
fout.WriteString(conf.HelloWorld)
fout.Close()
}
func webHello(workspace string) {
dir := workspace + conf.PathSeparator + "src" + conf.PathSeparator + "web"
if err := os.MkdirAll(dir, 0755); nil != err {
logger.Error(err)
return
}
fout, err := os.Create(dir + conf.PathSeparator + "main.go")
if nil != err {
logger.Error(err)
return
}
code := `package main
import (
"fmt"
"math/rand"
"net/http"
"strconv"
"time"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello, 世界"))
})
port := getPort()
// you may need to change the address
fmt.Println("Open https://wide.b3log.org:" + port + " in your browser to see the result")
if err := http.ListenAndServe(":"+port, nil); nil != err {
fmt.Println(err)
}
}
func getPort() string {
rand.Seed(time.Now().UnixNano())
return strconv.Itoa(7000 + rand.Intn(8000-7000))
}
`
fout.WriteString(code)
fout.Close()
}

View File

@ -218,7 +218,7 @@ var playground = {
if (!hovered) {
$(".menu .share-panel").hide();
}
}, http.StatusInternalServerError;
}, 500);
});
$(".menu .share-panel").hover(function () {

View File

@ -559,7 +559,7 @@
</div>
<script>
var channelScheme = "https" === window.location.protocol ? "wss":"ws";
var channel = channelScheme + "://" + window.location.hostname;
var channel = channelScheme + "://" + window.location.hostname + ":" + window.location.port;
var config = {
"pathSeparator": '{{.pathSeparator}}',
"label": {{.i18n}},

View File

@ -82,7 +82,7 @@
<div id="dialogShare" class="fn-none"></div>
<script>
var channelScheme = "https" === window.location.protocol ? "wss":"ws";
var channel = channelScheme + "://" + window.location.hostname;
var channel = channelScheme + "://" + window.location.hostname + ":" + window.location.port;
var config = {
"channel": channel,
"wideSessionId": "{{.sid}}",