-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0ba5299
Showing
47 changed files
with
5,102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.