zamkamec

Paste

Sep 24th, 2026 (edited)
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.52 KB | None | 0 0
  1. -- Pastebin Developer Utility App (apps/pastebin.lua)
  2. return {
  3. name = "Pastebin",
  4. color = colors.orange,
  5. symbol = "P",
  6. page = 1,
  7. run = function(w, h, drawBottomBar)
  8. local tab = "GET" -- "GET" or "PUT"
  9. local statusMsg = ""
  10. local statusColor = colors.white
  11.  
  12. -- Prompt Input Helper
  13. local function promptInput(title, defaultVal)
  14. term.setBackgroundColor(colors.gray)
  15. term.setTextColor(colors.white)
  16. term.setCursorPos(2, 17)
  17. term.write(string.rep(" ", w - 2))
  18. term.setCursorPos(2, 17)
  19. term.write(title .. ": ")
  20. term.setTextColor(colors.yellow)
  21.  
  22. local input = read()
  23. if input and #input > 0 then
  24. return input
  25. end
  26. return defaultVal or ""
  27. end
  28.  
  29. local getCode = ""
  30. local getFilename = "newapp.lua"
  31.  
  32. local putFilename = ""
  33.  
  34. while true do
  35. term.setBackgroundColor(colors.black)
  36. term.clear()
  37.  
  38. -- 1. Top Header
  39. term.setBackgroundColor(colors.gray)
  40. term.setTextColor(colors.white)
  41. term.setCursorPos(1, 1)
  42. term.write(" Pastebin Dev Tool " .. string.rep(" ", w - 19))
  43.  
  44. -- 2. Mode Selector Tabs (Replaced darkGray with gray)
  45. term.setCursorPos(2, 3)
  46. term.setBackgroundColor(tab == "GET" and colors.blue or colors.gray)
  47. term.setTextColor(colors.white)
  48. term.write(" [ GET Code ] ")
  49.  
  50. term.setCursorPos(15, 3)
  51. term.setBackgroundColor(tab == "PUT" and colors.green or colors.gray)
  52. term.setTextColor(colors.white)
  53. term.write(" [ UPLOAD File ] ")
  54.  
  55. -- 3. Render GET Interface
  56. if tab == "GET" then
  57. term.setBackgroundColor(colors.black)
  58. term.setTextColor(colors.yellow)
  59. term.setCursorPos(2, 5)
  60. term.write("Pastebin Code / Key:")
  61.  
  62. term.setCursorPos(2, 7)
  63. term.setBackgroundColor(colors.gray)
  64. term.setTextColor(colors.white)
  65. term.write(string.format(" Key: %-16s ", getCode == "" and "Tap to set" or getCode))
  66.  
  67. term.setBackgroundColor(colors.black)
  68. term.setTextColor(colors.yellow)
  69. term.setCursorPos(2, 9)
  70. term.write("Save File Name (in /apps):")
  71.  
  72. term.setCursorPos(2, 11)
  73. term.setBackgroundColor(colors.gray)
  74. term.setTextColor(colors.white)
  75. term.write(string.format(" File: %-15s ", getFilename))
  76.  
  77. -- Execute Download Button
  78. term.setCursorPos(2, 14)
  79. term.setBackgroundColor(colors.blue)
  80. term.setTextColor(colors.white)
  81. term.write(" [ Download File ] ")
  82.  
  83. -- 4. Render UPLOAD Interface
  84. elseif tab == "PUT" then
  85. term.setBackgroundColor(colors.black)
  86. term.setTextColor(colors.yellow)
  87. term.setCursorPos(2, 5)
  88. term.write("Local File to Upload:")
  89.  
  90. term.setCursorPos(2, 7)
  91. term.setBackgroundColor(colors.gray)
  92. term.setTextColor(colors.white)
  93. term.write(string.format(" Path: %-15s ", putFilename == "" and "Tap to set" or putFilename))
  94.  
  95. -- Execute Upload Button
  96. term.setCursorPos(2, 10)
  97. term.setBackgroundColor(colors.green)
  98. term.setTextColor(colors.white)
  99. term.write(" [ Upload to Pastebin ] ")
  100. end
  101.  
  102. -- 5. Status Output Area
  103. if statusMsg ~= "" then
  104. term.setBackgroundColor(colors.black)
  105. term.setTextColor(statusColor)
  106. term.setCursorPos(2, 16)
  107. term.write(statusMsg)
  108. end
  109.  
  110. -- 6. Bottom Navigation Bar
  111. drawBottomBar()
  112.  
  113. -- 7. Event Loop
  114. local event, button, clickX, clickY = os.pullEvent("mouse_click")
  115.  
  116. if button == 1 then
  117. -- Intercept Bottom Navigation Bar Click
  118. if clickY == h then
  119. return "bottom_bar", clickX
  120. end
  121.  
  122. -- Switch Tabs
  123. if clickY == 3 then
  124. if clickX >= 2 and clickX <= 13 then
  125. tab = "GET"
  126. statusMsg = ""
  127. elseif clickX >= 15 and clickX <= 26 then
  128. tab = "PUT"
  129. statusMsg = ""
  130. end
  131. end
  132.  
  133. -- GET Mode Actions
  134. if tab == "GET" then
  135. -- Set Pastebin Key
  136. if clickY == 7 and clickX >= 2 and clickX <= 24 then
  137. getCode = promptInput("Pastebin Key", getCode)
  138. if getCode:find("pastebin.com/") then
  139. getCode = getCode:match("pastebin.com/([%a%d]+)") or getCode
  140. end
  141. end
  142.  
  143. -- Set Output File Name
  144. if clickY == 11 and clickX >= 2 and clickX <= 24 then
  145. getFilename = promptInput("Filename", getFilename)
  146. end
  147.  
  148. -- Trigger Download
  149. if clickY == 14 and clickX >= 2 and clickX <= 18 then
  150. if getCode == "" then
  151. statusMsg = "Error: Key empty!"
  152. statusColor = colors.red
  153. else
  154. statusMsg = "Downloading..."
  155. statusColor = colors.yellow
  156.  
  157. term.setCursorPos(2, 16)
  158. term.setTextColor(statusColor)
  159. term.write(statusMsg)
  160.  
  161. local response = http.get("https://pastebin.com/raw/" .. textutils.urlEncode(getCode))
  162. if response then
  163. local content = response.readAll()
  164. response.close()
  165.  
  166. -- Ensure target path is inside /apps/
  167. local savePath = getFilename
  168. if not savePath:find("^apps/") and not savePath:find("^/apps/") then
  169. savePath = "apps/" .. savePath
  170. end
  171.  
  172. local file = fs.open(savePath, "w")
  173. file.write(content)
  174. file.close()
  175.  
  176. statusMsg = "Saved: " .. savePath
  177. statusColor = colors.lime
  178. else
  179. statusMsg = "Fetch failed! Bad key."
  180. statusColor = colors.red
  181. end
  182. end
  183. end
  184.  
  185. -- UPLOAD Mode Actions
  186. elseif tab == "PUT" then
  187. -- Set Local File Path
  188. if clickY == 7 and clickX >= 2 and clickX <= 24 then
  189. putFilename = promptInput("File Path", putFilename)
  190. end
  191.  
  192. -- Trigger Upload
  193. if clickY == 10 and clickX >= 2 and clickX <= 22 then
  194. if putFilename == "" or not fs.exists(putFilename) then
  195. statusMsg = "Error: File not found!"
  196. statusColor = colors.red
  197. elseif fs.isDir(putFilename) then
  198. statusMsg = "Error: Is a directory!"
  199. statusColor = colors.red
  200. else
  201. statusMsg = "Uploading..."
  202. statusColor = colors.yellow
  203.  
  204. term.setCursorPos(2, 16)
  205. term.setTextColor(statusColor)
  206. term.write(statusMsg)
  207.  
  208. local file = fs.open(putFilename, "r")
  209. local content = file.readAll()
  210. file.close()
  211.  
  212. local response = http.post(
  213. "https://pastebin.com/api/api_post.php",
  214. "api_option=paste&api_dev_key=1d205e012b189d288d448378f844a476&api_paste_code=" ..
  215. textutils.urlEncode(content)
  216. )
  217.  
  218. if response then
  219. local key = response.readAll()
  220. response.close()
  221. if key:find("http") then
  222. key = key:match("pastebin.com/([%a%d]+)") or key
  223. end
  224. statusMsg = "Code: " .. key
  225. statusColor = colors.lime
  226. else
  227. statusMsg = "Upload failed!"
  228. statusColor = colors.red
  229. end
  230. end
  231. end
  232. end
  233. end
  234. end
  235. end
  236. }
Advertisement
Add Comment
Please, Sign In to add comment