unblockneteasemusic.lua 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. -- This is a free software, use it under GNU General Public License v3.0.
  2. -- Created By ImmortalWrt
  3. -- https://github.com/immortalwrt
  4. module("luci.controller.unblockneteasemusic", package.seeall)
  5. function index()
  6. if not nixio.fs.access("/etc/config/unblockneteasemusic") then
  7. return
  8. end
  9. local page
  10. page = entry({"admin", "services", "unblockneteasemusic"},firstchild(), _("解除网易云音乐播放限制"), 50)
  11. page.dependent = false
  12. page.acl_depends = { "luci-app-unblockneteasemusic" }
  13. entry({"admin", "services", "unblockneteasemusic", "general"},cbi("unblockneteasemusic/unblockneteasemusic"), _("基本设定"), 1)
  14. entry({"admin", "services", "unblockneteasemusic", "upgrade"},form("unblockneteasemusic/unblockneteasemusic_upgrade"), _("更新组件"), 2).leaf = true
  15. entry({"admin", "services", "unblockneteasemusic", "log"},form("unblockneteasemusic/unblockneteasemusiclog"), _("日志"), 3)
  16. entry({"admin", "services", "unblockneteasemusic", "status"},call("act_status")).leaf=true
  17. entry({"admin", "services", "unblockneteasemusic", "update_luci"},call("act_update_luci"))
  18. entry({"admin", "services", "unblockneteasemusic", "update_core"},call("act_update_core"))
  19. end
  20. function act_status()
  21. local e={}
  22. e.running=luci.sys.call("ps |grep unblockneteasemusic |grep app.js |grep -v grep >/dev/null")==0
  23. luci.http.prepare_content("application/json")
  24. luci.http.write_json(e)
  25. end
  26. function update_luci()
  27. luci_cloud_ver=luci.sys.exec("curl -s 'https://api.github.com/repos/immortalwrt/luci-app-unblockneteasemusic/releases/latest' | jsonfilter -e '@.tag_name'")
  28. if not luci_cloud_ver then
  29. return "1"
  30. else
  31. luci_local_ver=luci.sys.exec("opkg info 'luci-app-unblockneteasemusic' |sed -n '2p' |tr -d 'Version: '")
  32. if not luci_local_ver or (luci_local_ver ~= luci_cloud_ver) then
  33. luci.sys.call("rm -f /usr/share/unblockneteasemusic/update_luci_successfully")
  34. luci.sys.call("/bin/bash /usr/share/unblockneteasemusic/update.sh update_luci")
  35. if not nixio.fs.access("/usr/share/unblockneteasemusic/update_luci_successfully") then
  36. return "2"
  37. else
  38. luci.sys.call("rm -f /usr/share/unblockneteasemusic/update_luci_successfully")
  39. return luci_cloud_ver
  40. end
  41. else
  42. return "0"
  43. end
  44. end
  45. end
  46. function act_update_luci()
  47. luci.http.prepare_content("application/json")
  48. luci.http.write_json({
  49. ret = update_luci();
  50. })
  51. end
  52. function update_core()
  53. core_cloud_ver=luci.sys.exec("curl -s 'https://api.github.com/repos/1715173329/UnblockNeteaseMusic/commits/enhanced' | jsonfilter -e '@.sha'")
  54. core_cloud_ver_mini=string.sub(core_cloud_ver, 1, 7)
  55. if not core_cloud_ver or not core_cloud_ver_mini then
  56. return "1"
  57. else
  58. core_local_ver=luci.sys.exec("cat '/usr/share/unblockneteasemusic/core_local_ver'")
  59. if not core_local_ver or (core_local_ver ~= core_cloud_ver) then
  60. luci.sys.call("rm -f /usr/share/unblockneteasemusic/update_core_successfully")
  61. luci.sys.call("/bin/bash /usr/share/unblockneteasemusic/update.sh update_core_from_luci")
  62. if not nixio.fs.access("/usr/share/unblockneteasemusic/update_core_successfully") then
  63. return "2"
  64. else
  65. luci.sys.call("rm -f /usr/share/unblockneteasemusic/update_core_successfully")
  66. return core_cloud_ver_mini
  67. end
  68. else
  69. return "0"
  70. end
  71. end
  72. end
  73. function act_update_core()
  74. luci.http.prepare_content("application/json")
  75. luci.http.write_json({
  76. ret = update_core();
  77. })
  78. end