mirror of
https://onedev.site.tesses.net/tytd2025
synced 2026-06-01 18:05:32 +00:00
Add some api docs
This commit is contained in:
@@ -31,6 +31,16 @@ class TYTDApp {
|
||||
ctx.WithMimeType("text/html").SendText(Pages.Index(this.TYTD));
|
||||
return true;
|
||||
}
|
||||
else if(ctx.Path == "/api")
|
||||
{
|
||||
ctx.WithMimeType("text/html").SendText(Pages.Api());
|
||||
return true;
|
||||
}
|
||||
else if(ctx.Path == "/api-v1")
|
||||
{
|
||||
ctx.WithMimeType("text/html").SendText(Pages.ApiV1());
|
||||
return true;
|
||||
}
|
||||
else if(ctx.Path == "/api/v1/download")
|
||||
{
|
||||
var v = ctx.QueryParams.TryGetFirst("v");
|
||||
@@ -44,12 +54,29 @@ class TYTDApp {
|
||||
if(path != null)
|
||||
{
|
||||
var info = this.TYTD.GetVideo(v);
|
||||
var filename = $"{info.title}-{info.videoId}.{path.GetExtension()}";
|
||||
var filename = $"{info.title}-{info.videoId}-{res}{path.GetExtension()}";
|
||||
var strm = this.TYTD.Storage.OpenFile(path,"rb");
|
||||
ctx.WithMimeType(Net.Http.MimeType(path.ToString())).WithContentDisposition(filename,inline).SendStream(strm);
|
||||
strm.Close();
|
||||
}
|
||||
}
|
||||
else if(ctx.Path == "/api/v1/progress.json")
|
||||
{
|
||||
var jo = {
|
||||
CurrentVideoProgress = this.TYTD.CurrentVideoProgress,
|
||||
CurrentVideo = this.TYTD.CurrentVideo
|
||||
|
||||
};
|
||||
ctx.WithMimeType("application/json").SendJson(jo);
|
||||
return true;
|
||||
}
|
||||
else if(ctx.Path == "/api/v1/video.json")
|
||||
{
|
||||
var id = ctx.QueryParams.TryGetFirst("v");
|
||||
if(TypeOf(id)!="String") id = "";
|
||||
ctx.WithMimeType("application/json").SendJson(this.TYTD.GetVideo(id));
|
||||
return true;
|
||||
}
|
||||
else if(ctx.Path == "/api/v1/playlist.json")
|
||||
{
|
||||
var id = ctx.QueryParams.TryGetFirst("id");
|
||||
@@ -102,6 +129,105 @@ class TYTDApp {
|
||||
ctx.WithMimeType("application/json").SendJson(result);
|
||||
return true;
|
||||
}
|
||||
else if(ctx.Path == "/api/v1/database.db")
|
||||
{
|
||||
this.TYTD.SendDatabase(ctx);
|
||||
return true;
|
||||
}
|
||||
else if(ctx.Path == "/api/v1/personal")
|
||||
{
|
||||
/*
|
||||
GET /api/v1/personal
|
||||
GET /api/v1/personal?name=NAME
|
||||
DELETE /api/v1/personal
|
||||
name=NAME
|
||||
id=THEID //If this does not exist delete the entire list
|
||||
POST /api/v1/personal
|
||||
id=THEID or description=
|
||||
name=
|
||||
*/
|
||||
|
||||
if(ctx.Method == "GET")
|
||||
{
|
||||
var name = ctx.QueryParams.TryGetFirst("name");
|
||||
if(TypeOf(name) == "String")
|
||||
{
|
||||
var page = ctx.QueryParams.TryGetFirstInt("page") ?? 1;
|
||||
var count = ctx.QueryParams.TryGetFirstInt("count") ?? 20;
|
||||
|
||||
var json = {
|
||||
description = this.TYTD.GetPersonalListDescription(name),
|
||||
items = this.TYTD.GetPersonalListContents(name,page-1,count)
|
||||
};
|
||||
ctx.WithMimeType("application/json").SendJson(json);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
var json = {
|
||||
items = this.TYTD.GetPersonalLists()
|
||||
};
|
||||
ctx.WithMimeType("application/json").SendJson(json);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(ctx.Method == "POST")
|
||||
{
|
||||
//{name="",id="",description=""}
|
||||
|
||||
var j = ctx.ReadJson();
|
||||
if(TypeOf(j.name) == "String")
|
||||
{
|
||||
var idHas = TypeOf(j.id) == "String" && j.id != "";
|
||||
var descHas = TypeOf(j.description) == "String" && j.description != "";
|
||||
if(idHas && descHas)
|
||||
{
|
||||
ctx.WithMimeType("application/json").SendJson({success=false,reason="You provided both a description (to set the list description) and id (to add a item) (you can only provide one)"});
|
||||
}
|
||||
else if(idHas)
|
||||
{
|
||||
this.TYTD.AddToPersonalList(j.name, j.id);
|
||||
ctx.WithMimeType("application/json").SendJson({success=true});
|
||||
}
|
||||
else if(descHas)
|
||||
{
|
||||
this.TYTD.SetPersonalListDescription(j.name,j.description);
|
||||
ctx.WithMimeType("application/json").SendJson({success=true});
|
||||
}
|
||||
else {
|
||||
ctx.WithMimeType("application/json").SendJson({success=false,reason="You must provide either a description (to set the list description) or id (to add a item)"});
|
||||
}
|
||||
}
|
||||
else {
|
||||
ctx.WithMimeType("application/json").SendJson({success=false, reason="Need a name"});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if(ctx.Method == "DELETE")
|
||||
{
|
||||
var j = ctx.ReadJson();
|
||||
/*
|
||||
public RemoveFromPersonalList(name,id)
|
||||
public RemovePersonalList(name)
|
||||
*/
|
||||
if(TypeOf(j.name) == "String")
|
||||
{
|
||||
if(TypeOf(j.id) == "String" && j.id != "")
|
||||
{
|
||||
this.TYTD.RemoveFromPersonalList(j.name,j.id);
|
||||
}
|
||||
else {
|
||||
this.TYTD.RemovePersonalList(j.name);
|
||||
}
|
||||
ctx.WithMimeType("application/json").SendJson({success=true});
|
||||
}
|
||||
else {
|
||||
ctx.WithMimeType("application/json").SendJson({success=false, reason="Need a name"});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
else if(ctx.Path == "/subscribe")
|
||||
{
|
||||
var id = ctx.QueryParams.TryGetFirst("id");
|
||||
@@ -125,6 +251,23 @@ class TYTDApp {
|
||||
ctx.WithMimeType("text/html").SendText(Components.Subscribe(this.TYTD,id));
|
||||
return true;
|
||||
}
|
||||
else if(ctx.Path == "/edit-personal-description")
|
||||
{
|
||||
var name = ctx.QueryParams.TryGetFirst("name");
|
||||
if(ctx.Method == "GET")
|
||||
{
|
||||
ctx.WithMimeType("text/html").SendText(Components.PersonalListDescription(this.TYTD,name,true));
|
||||
return true;
|
||||
}
|
||||
else if(ctx.Method == "POST")
|
||||
{
|
||||
var description =ctx.QueryParams.TryGetFirst("description");
|
||||
this.TYTD.SetPersonalListDescription(name,description);
|
||||
ctx.WithMimeType("text/html").SendText(Components.PersonalListDescription(this.TYTD,name,false));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(ctx.Path == "/downloads")
|
||||
{
|
||||
ctx.WithMimeType("text/html").SendText(Pages.Downloads(this.TYTD,ctx));
|
||||
|
||||
Reference in New Issue
Block a user