From d8f35afa53fc926364654b8e58905e8a078edfcc Mon Sep 17 00:00:00 2001 From: octospacc Date: Fri, 28 Apr 2023 17:25:42 +0200 Subject: [PATCH] Api fix for Misskey timeline --- App/ApiTransform.js | 15 +++++++++++++-- App/JsonTransform.js | 26 +++++++++++++++++++------- App/Main.js | 7 ++++++- App/Net.js | 3 +++ Bundle.py | 12 ------------ 5 files changed, 41 insertions(+), 22 deletions(-) mode change 100755 => 100644 Bundle.py diff --git a/App/ApiTransform.js b/App/ApiTransform.js index 4b894ca..ebb9537 100644 --- a/App/ApiTransform.js +++ b/App/ApiTransform.js @@ -24,8 +24,9 @@ var TransSchemas = { var ApiSchema = { __All__: { ServerSoftware: { //TODO: Handle this in JsonTransform - Mastodon: {__Set__: "Mastodon"}, - Misskey: {__Set__: "Misskey"}, + //Mastodon: {__Set__: "Mastodon"}, + //Misskey: {__Set__: "Misskey"}, + __All__: {__EvalSet__: "TypeOld"}, }, }, Note: { @@ -34,10 +35,12 @@ var ApiSchema = { Misskey: "text", }, Profile: { + __: "Profile", Mastodon: "account", Misskey: "user", }, Quoting: { + __: "Note", Mastodon: "reblog", Misskey: "renote", }, @@ -73,9 +76,13 @@ var ApiSchema = { else if (TreeOld.group) 'Group'; `}, + Misskey: {__EvalSet__: ` + if (TreeOld.isBot) 'Bot'; + `}, }, Url: { Mastodon: "url", + Misskey: "uri", }, }, }; @@ -85,6 +92,9 @@ var ApiEndpoints = { Mastodon(Profile) { return `GET api/v1/accounts/${Profile.Id}/statuses`; }, + Misskey(Profile) { + return ``; + }, }, ServerInfo: { Mastodon: "GET api/v1/instance", @@ -95,6 +105,7 @@ var ApiEndpoints = { }, ServerTimeline: { Mastodon: "GET api/v1/timelines/public", + Misskey: "POST api/notes/local-timeline", }, }; diff --git a/App/JsonTransform.js b/App/JsonTransform.js index 5018bd0..64a66bc 100644 --- a/App/JsonTransform.js +++ b/App/JsonTransform.js @@ -57,7 +57,7 @@ function JsonTransformB(TreesOld, SchemaNew, NodeNew, TypeOld) { return ListNew; } else { // Object - if (TreesOld) { + if (TreesOld && SchemaNew && NodeNew) { return JsonTransformCycleB(TreesOld, SchemaNew, NodeNew, TypeOld); }; }; @@ -66,19 +66,31 @@ function JsonTransformB(TreesOld, SchemaNew, NodeNew, TypeOld) { function JsonTransformCycleB(TreeOld, SchemaNew, NodeNew, TypeOld) { var TreeNew = CopyObj(NodeNew); if (SchemaNew.__All__) { - TreeNew.__All__ = CopyObj(SchemaNew.__All__); + //TreeNew.__All__ = CopyObj(SchemaNew.__All__); + //console.log(1, '__All__') + //_.forOwn(TreeNew, function(KeyNewVal, KeyNew){ + // console.log(1, KeyNew) + //}); + _.forOwn(SchemaNew.__All__, function(Val, Key){ + //console.log(1, Key) + TreeNew[Key] = CopyObj(Val); + }); }; _.forOwn(TreeNew, function(KeyNewVal, KeyNew){ + //if (KeyNew === '__All__') { + // console.log(1, KeyNew) + // _.forOwn(KeyOld, function(KeyObjVal, KeyObj){}); + //}; + if (KeyNewVal.__All__ && !KeyNewVal[TypeOld]) { + //console.log(3, KeyNewVal.__All__) + KeyNewVal[TypeOld] = KeyNewVal.__All__; + }; if (KeyNewVal[TypeOld]) { var KeyOld = KeyNewVal[TypeOld]; var ObjOld = TreeOld[KeyOld]; if (IsObj(KeyOld)) { // Object in NodeNew / Deep nested children in TreeOld _.forOwn(KeyOld, function(KeyObjVal, KeyObj){ - //if (KeyObj === '__All__') { //NOTE: This must be handle as directly nested, not deep (how?) - // console.log('__All__') - // //TreeNew.__All__ = SchemaNew.__All__; - //}; if (KeyObj === '__Eval__') { eval(KeyObjVal); } else @@ -102,7 +114,7 @@ function JsonTransformCycleB(TreeOld, SchemaNew, NodeNew, TypeOld) { } else { // Value in NodeNew / Direct children in TreeOld if (IsObj(ObjOld)) { - TreeNew[KeyNew] = JsonTransformB(ObjOld, SchemaNew, SchemaNew[KeyNew], TypeOld); + TreeNew[KeyNew] = JsonTransformB(ObjOld, SchemaNew, SchemaNew[TreeNew[KeyNew].__], TypeOld); } else { TreeNew[KeyNew] = ObjOld; }; diff --git a/App/Main.js b/App/Main.js index 51c5bca..398b98b 100644 --- a/App/Main.js +++ b/App/Main.js @@ -127,7 +127,9 @@ function FetchNotes(Profile, Proc) { var Method = Profile.Type == 'Server' ? ApiEndpoints.ServerTimeline[Soft] : ApiEndpoints.FetchNotes[Soft](Profile); - NetCall({Target: UrlBase(Profile.Url), Method: Method, CallFine: function(Res){ + var Endp = Method; + var Method = Endp.Method || Endp; + NetCall({Target: UrlBase(Profile.Url), Method: Method, Data: Endp.Data, CallFine: function(Res){ var Notes = ApiTransform(Res.responseJson, Soft, 'Note'); LogDebug(Notes, 'l'); Tasker[Res.Proc[0]].Return(Notes); @@ -150,6 +152,9 @@ function ResFetchMastodon(Res) { function FillTimeline(Notes) { Notes.forEach(function(Note){ ApiCache.__UrlStore__(Note.Profile); + if (Note.Quoting) { + Note = Note.Quoting; + }; Root.lastChild.innerHTML += `
diff --git a/App/Net.js b/App/Net.js index 7811195..3ba21c9 100644 --- a/App/Net.js +++ b/App/Net.js @@ -34,6 +34,9 @@ function NetCall(Data, Proc) { _.forOwn(_.merge({"Content-Type": "application/json"}, Data.Headers), function(Val, Key) { Req.setRequestHeader(Key, Val); }); + if (Method === 'POST' && !Data.Data) { + Data.Data = {}; + }; Req.send(JSON.stringify(Data.Data)); }; diff --git a/Bundle.py b/Bundle.py old mode 100755 new mode 100644 index 838b07e..e2a2c83 --- a/Bundle.py +++ b/Bundle.py @@ -4,18 +4,6 @@ from base64 import b64encode from mimetypes import guess_type from pathlib import Path -#def MinifyJs(Js): -# New = '' -# Js = Js.replace('\\\n', '\n') -# BlockOpen = False -# for Line in Js.splitlines(): -# if '/*' in Line: BlockOpen = True -# if '*/' in Line: BlockOpen = False -# if '//' in Line and not BlockOpen: -# Line = Line.replace('//', '/*') + '*/' -# New += Line -# return New.replace('\n', ' ') - os.chdir(os.path.dirname(os.path.abspath(__file__))) os.makedirs('./Dist', exist_ok=True)