module.notepadA.go_disabled 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package main
  2. import (
  3. "net/http"
  4. "encoding/json"
  5. )
  6. func module_notepadA_init(){
  7. http.HandleFunc("/NotepadA/store", module_notepadA_handleStorage)
  8. //Create database for this module
  9. system_db_newTable(sysdb, "NotepadA")
  10. //Register this module to system
  11. registerModule(moduleInfo{
  12. Name: "NotepadA",
  13. Desc: "The best code editor on ArOZ Online",
  14. Group: "Office",
  15. IconPath: "NotepadA/img/module_icon.png",
  16. Version: "1.2",
  17. StartDir: "NotepadA/index.html",
  18. SupportFW: true,
  19. LaunchFWDir: "NotepadA/index.html",
  20. SupportEmb: true,
  21. LaunchEmb: "NotepadA/embedded.html",
  22. InitFWSize: []int{1024, 768},
  23. InitEmbSize: []int{360, 200},
  24. SupportedExt: []string{".bat",".coffee",".cpp",".cs",".csp",".csv",".fs",".dockerfile",".go",".html",".ini",".java",".js",".lua",".mips",".md", ".sql",".txt",".php",".py",".ts",".xml",".yaml"},
  25. })
  26. }
  27. func module_notepadA_handleStorage(w http.ResponseWriter, r *http.Request){
  28. username, err := system_auth_getUserName(w,r);
  29. if (err != nil){
  30. sendErrorResponse(w,"User not logged in")
  31. return;
  32. }
  33. opr, _ := mv(r, "opr", true)
  34. key, _ := mv(r, "key", true)
  35. value, _ := mv(r, "value", true)
  36. userKey := username + "/" + key;
  37. if (opr == "get"){
  38. returnString := "";
  39. err := system_db_read(sysdb, "NotepadA", userKey, &returnString)
  40. if (err != nil){
  41. sendErrorResponse(w, err.Error())
  42. return
  43. }
  44. jsonstring, _ := json.Marshal(returnString)
  45. sendJSONResponse(w, string(jsonstring));
  46. return
  47. }else if (opr == "set"){
  48. err := system_db_write(sysdb, "NotepadA", userKey, value)
  49. if (err != nil){
  50. sendErrorResponse(w, err.Error())
  51. return
  52. }
  53. sendOK(w);
  54. }
  55. }