-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Web app hot fix * Small tweak
- Loading branch information
Showing
8 changed files
with
451 additions
and
2 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
69 changes: 69 additions & 0 deletions
69
playlet-lib/src/components/Web/PlayletWebServer/Middleware/ProxyRouter.bs
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,69 @@ | ||
import "pkg:/source/services/HttpClient.bs" | ||
|
||
namespace Http | ||
|
||
class ProxyRouter extends HttpRouter | ||
|
||
function new(server as object) | ||
super() | ||
|
||
task = server.task | ||
m.invidiousNode = task.invidious | ||
m.invidiousService = new Invidious.InvidiousService(m.invidiousNode) | ||
end function | ||
|
||
@post("/api/proxy") | ||
function ProxyRequest(context as object) as boolean | ||
request = context.request | ||
response = context.response | ||
|
||
requestArgs = request.Json() | ||
if requestArgs = invalid | ||
response.Default(400, "Invalid request body") | ||
return true | ||
end if | ||
|
||
httpReq = HttpClient.FromObject(requestArgs) | ||
httpRes = httpReq.Await() | ||
|
||
result = { | ||
"status": httpRes.StatusCode() | ||
"headers": httpRes.Headers() | ||
"body": httpRes.Text() | ||
} | ||
|
||
response.Json(result) | ||
return true | ||
end function | ||
|
||
@post("/api/ytjs-cache") | ||
function CacheVideoInfo(context as object) as boolean | ||
request = context.request | ||
response = context.response | ||
|
||
json = request.Json() | ||
if json = invalid | ||
response.Default(400, "Invalid request body") | ||
return true | ||
end if | ||
|
||
instance = m.invidiousService.GetInstance() | ||
videoId = json.videoId | ||
|
||
url = `${instance}${Invidious.VIDEOS_ENDPOINT}/${videoId}` | ||
|
||
' Place a fake cache so we can read it later | ||
requestObj = HttpClient.Get(url) | ||
requestObj.CacheSeconds(18000) | ||
responseObj = new HttpClient.HttpResponse(requestObj, invalid) | ||
responseObj.OverrideStatusCode(200) | ||
responseObj.OverrideText(request.body) | ||
HttpClientCache.Set(responseObj) | ||
|
||
response.Default(204, "OK") | ||
return true | ||
end function | ||
|
||
end class | ||
|
||
end namespace |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.