Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Masken8 committed Oct 14, 2020
0 parents commit 0ba5299
Show file tree
Hide file tree
Showing 47 changed files with 5,102 additions and 0 deletions.
56 changes: 56 additions & 0 deletions CryptoMath.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
local uv = require("uv")
local TableUtils = require("./TableUtils.lua")

local CryptoMath = {}

function CryptoMath.uvrandom(min, max)
assert(min, 'expected lower bound')
assert(max, 'expected upper bound')
assert(max > min, 'expected max > min')
local range = max - min

local log256range = math.ceil(math.log(range, 256)) -- number of bytes required to store range

local bytes = uv.random(log256range * 2) -- get double the bytes required so we can distribute evenly with modulo
local random = 0

for i = 1, #bytes do
random = bit.lshift(random, 8) + bytes:byte(i, i)
end

return random % range + min
end

local charIgnoreList = {
58,
59,
60,
61,
62,
63,
64,
91,
92,
93,
94,
96,
123,
124,
125
}

function CryptoMath.RandomString(length)
local str = ""
for i = 1, length do
--local randomNum = cryptoMath.uvrandom(65,126)
local randomNum
repeat
randomNum = CryptoMath.uvrandom(48,126)
until not TableUtils.Find(charIgnoreList, randomNum)
local randomChar = string.char(randomNum)
str = str..randomChar
end
return str
end

return CryptoMath
20 changes: 20 additions & 0 deletions Endpoints/GetInfo.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local SpotifyAPI = require("./../SpotifyAPIServer.lua")

local GetInfo = {}

GetInfo.method = "GET"

GetInfo.path = "/GetInfo"

GetInfo.callback = function(req, res)
local inforaw = SpotifyAPI:GetInfo(true)

if inforaw then
res.body = inforaw
res.code = 200
else
res.code = 500
end
end

return GetInfo
23 changes: 23 additions & 0 deletions Endpoints/GetMuted.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local SpotifyAPI = require("./../SpotifyAPIServer.lua")
local json = require("json")

local GetMuted = {}

GetMuted.method = "GET"

GetMuted.path = "/GetMuted"

GetMuted.callback = function(req, res)
local isMutedRes = json.stringify({
muted = SpotifyAPI.muted
})

if isMutedRes then
res.body = isMutedRes
res.code = 200
else
res.code = 500
end
end

return GetMuted
15 changes: 15 additions & 0 deletions Endpoints/Next.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
local SpotifyAPI = require("./../SpotifyAPIServer.lua")

local Next = {}

Next.method = "GET"

Next.path = "/Next"

Next.callback = function(req, res)
SpotifyAPI:SkipForward()

res.code = 204
end

return Next
15 changes: 15 additions & 0 deletions Endpoints/Pause.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
local SpotifyAPI = require("./../SpotifyAPIServer.lua")

local Pause = {}

Pause.method = "GET"

Pause.path = "/Pause"

Pause.callback = function(req, res)
SpotifyAPI:Pause()

res.code = 204
end

return Pause
15 changes: 15 additions & 0 deletions Endpoints/Previous.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
local SpotifyAPI = require("./../SpotifyAPIServer.lua")

local Previous = {}

Previous.method = "GET"

Previous.path = "/Previous"

Previous.callback = function(req, res)
SpotifyAPI:SkipBackward()

res.code = 204
end

return Previous
15 changes: 15 additions & 0 deletions Endpoints/Resume.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
local SpotifyAPI = require("./../SpotifyAPIServer.lua")

local Resume = {}

Resume.method = "GET"

Resume.path = "/Resume"

Resume.callback = function(req, res)
SpotifyAPI:Resume()

res.code = 204
end

return Resume
22 changes: 22 additions & 0 deletions Endpoints/SetMuted.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
local SpotifyAPI = require("./../SpotifyAPIServer.lua")
local json = require("json")

local SetMuted = {}

SetMuted.method = "POST"

SetMuted.path = "/SetMuted"

SetMuted.callback = function(req, res)
local params = json.parse(req.body)

if params then
local mute = params["mute"]
SpotifyAPI:SetMuted(mute)
res.code = 204
else
res.code = 400
end
end

return SetMuted
29 changes: 29 additions & 0 deletions Endpoints/ToggleMute.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
local SpotifyAPI = require("./../SpotifyAPIServer.lua")
local json = require("json")

local ToggleMute = {}

ToggleMute.method = "GET"

ToggleMute.path = "/ToggleMute"

ToggleMute.callback = function(req, res)
local info = SpotifyAPI:GetInfo()

if info then
if not SpotifyAPI.muted then
local infoJSON = json.parse(info)
SpotifyAPI.muted = true
SpotifyAPI.volumeBeforeMute = infoJSON["device"]["volume_percent"]
SpotifyAPI:SetVolume(0)
else
SpotifyAPI.muted = false
SpotifyAPI:SetVolume(SpotifyAPI.volumeBeforeMute)
SpotifyAPI.volumeBeforeMute = 100
end
end

res.code = 204
end

return ToggleMute
15 changes: 15 additions & 0 deletions Endpoints/TogglePlaying.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
local SpotifyAPI = require("./../SpotifyAPIServer.lua")

local TogglePlaying = {}

TogglePlaying.method = "GET"

TogglePlaying.path = "/TogglePlaying"

TogglePlaying.callback = function(req, res)
SpotifyAPI:TogglePlaying()

res.code = 204
end

return TogglePlaying
Loading

0 comments on commit 0ba5299

Please sign in to comment.