update
							parent
							
								
									863b489412
								
							
						
					
					
						commit
						a956221c4e
					
				
							
								
								
									
										2
									
								
								Makefile
								
								
								
								
							
							
						
						
									
										2
									
								
								Makefile
								
								
								
								
							|  | @ -23,7 +23,7 @@ run: build | ||||||
| .PHONY: web | .PHONY: web | ||||||
| web: | web: | ||||||
| 	npm run build | 	npm run build | ||||||
| 	# npm run js-dev | 	npm run js-dev | ||||||
| 
 | 
 | ||||||
| .PHONY: build | .PHONY: build | ||||||
| build: web | build: web | ||||||
|  |  | ||||||
							
								
								
									
										12
									
								
								file.go
								
								
								
								
							
							
						
						
									
										12
									
								
								file.go
								
								
								
								
							|  | @ -50,34 +50,32 @@ func (f *File) Write(data []byte) error { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (f *File) Do() (string, error) { | func (f *File) Do() (string, error) { | ||||||
| 	log.Println("do ", f.Action) |  | ||||||
| 	if f.Action == "" { | 	if f.Action == "" { | ||||||
| 		return "", nil | 		return "", nil | ||||||
| 	} | 	} | ||||||
| 	timeout := time.After(2 * time.Second) |  | ||||||
| 	cmd := &exec.Cmd{} | 	cmd := &exec.Cmd{} | ||||||
| 	if runtime.GOOS == "windows" { | 	if runtime.GOOS == "windows" { | ||||||
| 		cmd = exec.Command(WIN_SHELL, "/c", f.Action) | 		cmd = exec.Command(WIN_SHELL, "/c", f.Action) | ||||||
| 	} else { | 	} else { | ||||||
| 		exec.Command(UNIX_SHELL, "-c", f.Action) | 		cmd = exec.Command(UNIX_SHELL, "-c", f.Action) | ||||||
| 	} | 	} | ||||||
|  | 	log.Println("DO: ", f.Action) | ||||||
| 	done := make(chan string, 1) | 	done := make(chan string, 1) | ||||||
| 	log.Println("start ", f.Action) |  | ||||||
| 	go func() { | 	go func() { | ||||||
| 		out, _ := cmd.CombinedOutput() | 		out, _ := cmd.CombinedOutput() | ||||||
| 		// real cmd err is only pass down
 | 		// real cmd err is unhandled, but passed to client
 | ||||||
| 		// if err != nil {
 | 		// if err != nil {
 | ||||||
| 		// 	return string(out), err
 | 		// 	return string(out), err
 | ||||||
| 		// }
 | 		// }
 | ||||||
| 		done <- string(out) | 		done <- string(out) | ||||||
| 	}() | 	}() | ||||||
| 	select { | 	select { | ||||||
| 	case <-timeout: | 	case <-time.After(5 * time.Second): | ||||||
| 		cmd.Process.Kill() | 		cmd.Process.Kill() | ||||||
| 		log.Println("timeout") | 		log.Println("timeout") | ||||||
| 		return "", errors.New("command timeout") | 		return "", errors.New("command timeout") | ||||||
| 	case out := <-done: | 	case out := <-done: | ||||||
| 		log.Println(out) | 		log.Println("\n", out) | ||||||
| 		return out, nil | 		return out, nil | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -0,0 +1,104 @@ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | window.ToolIsFollow = false; | ||||||
|  | 
 | ||||||
|  | async function FileGet(follower=false){ | ||||||
|  |   let f = '' | ||||||
|  |   if (Active == 'ConfigUI') { | ||||||
|  |     if (follower) f = '?f=true' | ||||||
|  |     const res = await fetch('/api/conf'+f) | ||||||
|  |       .catch(err=>{console.log(err);return;}); | ||||||
|  |     const body = await res.text(); | ||||||
|  |     if(!res.ok){ | ||||||
|  |       Catch(res) | ||||||
|  |       return | ||||||
|  |     } | ||||||
|  |     editor.session.setValue(body); | ||||||
|  |   } | ||||||
|  |   else { | ||||||
|  |     if (follower) f = '&f=true' | ||||||
|  |     const res = await fetch('/api/file?name=' + Active + f) | ||||||
|  |       .catch(err=>{console.log(err);return;}); | ||||||
|  |     const body = await res.json(); | ||||||
|  |     if(!res.ok){ | ||||||
|  |       Catch(res) | ||||||
|  |       return | ||||||
|  |     } | ||||||
|  |     editor.session.setValue(body.data); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | async function FileSave(){ | ||||||
|  |   if (Active == 'ConfigUI') { | ||||||
|  |     const res = await fetch('/api/conf', { | ||||||
|  |       method: 'POST', | ||||||
|  |       body: editor.getValue(), | ||||||
|  |       headers: new Headers({ | ||||||
|  |         'Content-Type': 'application/json' | ||||||
|  |       }) | ||||||
|  |     }).catch(err=>{console.log(err);return;}); | ||||||
|  |     if (res.ok) window.location.reload(); | ||||||
|  |     else Catch(res) | ||||||
|  |   } | ||||||
|  |   else { | ||||||
|  |     const res = await fetch('/api/file', { | ||||||
|  |       method: 'POST', | ||||||
|  |       body: JSON.stringify({"name":Active,"data":editor.getValue()}), | ||||||
|  |       headers: new Headers({ | ||||||
|  |         'Content-Type': 'application/json' | ||||||
|  |       }) | ||||||
|  |     }).catch(err=>{console.log(err);return;}); | ||||||
|  |     if(!res.ok) Catch(res) | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | async function FileApply(){ | ||||||
|  |   if (Active == 'ConfigUI') { | ||||||
|  |     return; | ||||||
|  |   } | ||||||
|  |   else { | ||||||
|  |     const res = await fetch('/api/apply?name='+ Active, { | ||||||
|  |       method: 'POST', | ||||||
|  |     }).catch(err=>{console.log(err);return;}); | ||||||
|  |     if(!res.ok){ | ||||||
|  |       const result = await Catch(res) | ||||||
|  |       result_editor.session.setValue(result) | ||||||
|  |       return | ||||||
|  |     } | ||||||
|  |     const result = await res.text() | ||||||
|  |     result_editor.session.setValue(result) | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | async function Catch(res){ | ||||||
|  |   console.trace() | ||||||
|  |   console.log(res) | ||||||
|  |   const msg = await res.text() | ||||||
|  |   ShowError(msg) | ||||||
|  |   return msg | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // starting point
 | ||||||
|  | (function(){ | ||||||
|  |   // block ctl-s
 | ||||||
|  |   window.addEventListener("keypress", function(event) { | ||||||
|  |     if (!(event.code == 115 && event.ctrlKey) && !(event.code == 19)) return true | ||||||
|  |     alert("Ctrl-S pressed") | ||||||
|  |     event.preventDefault() | ||||||
|  |     return false | ||||||
|  |   }) | ||||||
|  | 
 | ||||||
|  |   // setup ace editor
 | ||||||
|  |   setEditor() | ||||||
|  | 
 | ||||||
|  |   // setup result code block
 | ||||||
|  |   setResult() | ||||||
|  |    | ||||||
|  |   // for follow mode
 | ||||||
|  |   setInterval((async ()=>{ | ||||||
|  |     if (ToolIsFollow){ | ||||||
|  |       await FileGet(true) | ||||||
|  |       editor.gotoLine(editor.session.getLength()); | ||||||
|  |     } | ||||||
|  |   }), 1000) | ||||||
|  | }()) | ||||||
							
								
								
									
										28
									
								
								src/main.js
								
								
								
								
							
							
						
						
									
										28
									
								
								src/main.js
								
								
								
								
							|  | @ -2,11 +2,12 @@ | ||||||
| 
 | 
 | ||||||
| window.ToolIsFollow = false; | window.ToolIsFollow = false; | ||||||
| 
 | 
 | ||||||
| async function FileGet(follower=false){ | FileGet= async function(follower=false){ | ||||||
|   let f = '' |   let f = '' | ||||||
|   if (Active == 'ConfigUI') { |   if (Active == 'ConfigUI') { | ||||||
|     if (follower) f = '?f=true' |     if (follower) f = '?f=true' | ||||||
|     const res = await fetch('/api/conf'+f); |     const res = await fetch('/api/conf'+f) | ||||||
|  |       .catch(err=>{console.log(err);return;}); | ||||||
|     const body = await res.text(); |     const body = await res.text(); | ||||||
|     if(!res.ok){ |     if(!res.ok){ | ||||||
|       Catch(res) |       Catch(res) | ||||||
|  | @ -16,7 +17,8 @@ async function FileGet(follower=false){ | ||||||
|   } |   } | ||||||
|   else { |   else { | ||||||
|     if (follower) f = '&f=true' |     if (follower) f = '&f=true' | ||||||
|     const res = await fetch('/api/file?name=' + Active + f); |     const res = await fetch('/api/file?name=' + Active + f) | ||||||
|  |       .catch(err=>{console.log(err);return;}); | ||||||
|     const body = await res.json(); |     const body = await res.json(); | ||||||
|     if(!res.ok){ |     if(!res.ok){ | ||||||
|       Catch(res) |       Catch(res) | ||||||
|  | @ -26,7 +28,7 @@ async function FileGet(follower=false){ | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async function FileSave(){ | FileSave = async function(){ | ||||||
|   if (Active == 'ConfigUI') { |   if (Active == 'ConfigUI') { | ||||||
|     const res = await fetch('/api/conf', { |     const res = await fetch('/api/conf', { | ||||||
|       method: 'POST', |       method: 'POST', | ||||||
|  | @ -34,7 +36,7 @@ async function FileSave(){ | ||||||
|       headers: new Headers({ |       headers: new Headers({ | ||||||
|         'Content-Type': 'application/json' |         'Content-Type': 'application/json' | ||||||
|       }) |       }) | ||||||
|     }) |     }).catch(err=>{console.log(err);return;}); | ||||||
|     if (res.ok) window.location.reload(); |     if (res.ok) window.location.reload(); | ||||||
|     else Catch(res) |     else Catch(res) | ||||||
|   } |   } | ||||||
|  | @ -45,19 +47,19 @@ async function FileSave(){ | ||||||
|       headers: new Headers({ |       headers: new Headers({ | ||||||
|         'Content-Type': 'application/json' |         'Content-Type': 'application/json' | ||||||
|       }) |       }) | ||||||
|     }) |     }).catch(err=>{console.log(err);return;}); | ||||||
|     if(!res.ok) Catch(res) |     if(!res.ok) Catch(res) | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async function FileApply(){ | FileApply = async function(){ | ||||||
|   if (Active == 'ConfigUI') { |   if (Active == 'ConfigUI') { | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   else { |   else { | ||||||
|     const res = await fetch('/api/apply?name='+ Active, { |     const res = await fetch('/api/apply?name='+ Active, { | ||||||
|       method: 'POST', |       method: 'POST', | ||||||
|     }) |     }).catch(err=>{console.log(err);return;}); | ||||||
|     if(!res.ok){ |     if(!res.ok){ | ||||||
|       const result = await Catch(res) |       const result = await Catch(res) | ||||||
|       result_editor.session.setValue(result) |       result_editor.session.setValue(result) | ||||||
|  | @ -68,7 +70,7 @@ async function FileApply(){ | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async function Catch(res){ | Catch=async function(res){ | ||||||
|   console.trace() |   console.trace() | ||||||
|   console.log(res) |   console.log(res) | ||||||
|   const msg = await res.text() |   const msg = await res.text() | ||||||
|  | @ -91,4 +93,12 @@ async function Catch(res){ | ||||||
|       editor.gotoLine(editor.session.getLength()); |       editor.gotoLine(editor.session.getLength()); | ||||||
|     } |     } | ||||||
|   }), 1000) |   }), 1000) | ||||||
|  | 
 | ||||||
|  |   // block ctl-s
 | ||||||
|  |   window.addEventListener("keypress", function(event) { | ||||||
|  |     if (!(event.which == 115 && event.ctrlKey) && !(event.which == 19)) return true | ||||||
|  |     alert("Ctrl-S pressed") | ||||||
|  |     event.preventDefault() | ||||||
|  |     return false | ||||||
|  |   }) | ||||||
| }()) | }()) | ||||||
|  | @ -22,7 +22,7 @@ $modal-content-width: 90vw; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| .icn-spinner { | .icn-spinner { | ||||||
|   animation: spin-animation 0.5s infinite; |   animation: spin-animation 1s infinite; | ||||||
|   display: inline-block; |   display: inline-block; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,7 +1,8 @@ | ||||||
| {{define "base/footer"}} | {{define "base/footer"}} | ||||||
|   <script src="/public/ace/js/ace.js" type="text/javascript" charset="utf-8"></script> |   <script src="/public/ace/js/ace.js" type="text/javascript" charset="utf-8"></script> | ||||||
|   <script src="/public/ace/js/ext-beautify.js" type="text/javascript" charset="utf-8"></script> |   <script src="/public/ace/js/ext-beautify.js" type="text/javascript" charset="utf-8"></script> | ||||||
|   <script src="/public/js/main.js"></script> |   <!-- <script src="/public/js/main.js"></script> --> | ||||||
|  |   <script src="/public/js/back.js"></script> | ||||||
|   </body> |   </body> | ||||||
| </html> | </html> | ||||||
| {{end}} | {{end}} | ||||||
|  | @ -29,6 +29,5 @@ var Active = "{{.File.Name}}"; | ||||||
|   </div> |   </div> | ||||||
| </div> | </div> | ||||||
| {{template "components/result" .}} | {{template "components/result" .}} | ||||||
| 
 |  | ||||||
| {{template "base/footer" .}} | {{template "base/footer" .}} | ||||||
| {{end}} | {{end}} | ||||||
		Loading…
	
		Reference in New Issue