diff --git a/App/ApiFake.js b/App/ApiFake.js index 636ecfe..601e4b7 100644 --- a/App/ApiFake.js +++ b/App/ApiFake.js @@ -10,6 +10,13 @@ var FakeApi = { }, }; +FakeApi.Friendiiverse.Featured.Featured.push({ + //Banner: "https://picsum.photos/seed/Testing.Banner/320/180", + //Icon: "https://picsum.photos/seed/Testing.Icon/64", + Name: "mastodon.social", + Url: "https://mastodon.social", + __Display__: "DisplayMastodonTimeline", +}); FakeApi.Friendiiverse.Featured.Featured.push({ Banner: "https://picsum.photos/seed/Testing.Banner/320/180", Icon: "https://picsum.photos/seed/Testing.Icon/64", diff --git a/App/ApiTransform.js b/App/ApiTransform.js index 8be498a..95ac3b1 100644 --- a/App/ApiTransform.js +++ b/App/ApiTransform.js @@ -22,11 +22,11 @@ var TransSchemas = { */ var ApiSchema = { - __All__: { - SourceInstance: { - __Eval__: "", - }, - }, + //__All__: { + // __Software__: { + // __EvalSet__: "TypeOld", + // }, + //}, Note: { Content: { Mastodon: "content", @@ -82,7 +82,7 @@ var ApiSchema = { var ApiEndpoints = { FetchNotes: { Mastodon(Profile) { - return `accounts/${Profile.Id}/statuses`; + return `GET accounts/${Profile.Id}/statuses`; }, }, }; diff --git a/App/Main.js b/App/Main.js index fd29f6f..0fba337 100644 --- a/App/Main.js +++ b/App/Main.js @@ -43,7 +43,7 @@ function DoAsync(First, Then, Data) { }, }; // Call all First functs - ForceList(First).forEach(function(Fun, Data){ + ForceList(First).forEach(function(Fun){ var Task = RndId(); var Proc = [Job, Task]; Tasker[Job][Task] = {}; @@ -78,24 +78,40 @@ function DisplayProfile(Profile) { `; - DoAsync(FetchMastodon, FillTimeline, Profile); + DoAsync(FetchNotes, FillTimeline, Profile); +}; + +function DisplayMastodonTimeline(Data) { + var Window = MkWindow(); + Window.innerHTML += `
+ +
+ +
+
+ + ${Profile.Name} +
+
+
`; + DoAsync(FetchNotes, FillTimeline, Profile); }; function FetchNotes(Profile, Proc) { var Soft = Profile.__Software__; - NetApiCall({Target: Soft, Method: ApiEndpoints.FetchNotes[Soft](Profile), CallFine: function(Res){ - var Notes = ApiTransform(Res.responseJson, 'Mastodon', 'Note'); + NetApiCall({Target: UrlBase(Profile.Url), Method: ApiEndpoints.FetchNotes['Mastodon'](Profile), CallFine: function(Res){ + var Notes = ApiTransform(Res.responseJson, Soft, 'Note'); LogDebug(Notes, 'l'); Tasker[Res.Proc[0]].Return(Notes); }}, Proc); }; function FetchMastodon(Proc) { - if (UseFakeApi) { - ResFetchMastodon({responseJson: [FakeApi.Mastodon.Status], Proc: Proc}); - } else { - NetApiCall({Target: "Mastodon", Method: "timelines/public", CallFine: ResFetchMastodon}, Proc); - }; + //if (UseFakeApi) { + // ResFetchMastodon({responseJson: [FakeApi.Mastodon.Status], Proc: Proc}); + //} else { + NetApiCall({Target: "Mastodon", Method: "GET timelines/public", CallFine: ResFetchMastodon}, Proc); + //}; }; function ResFetchMastodon(Res) { var Notes = ApiTransform(Res.responseJson, 'Mastodon', 'Note'); @@ -136,7 +152,7 @@ function FillFeatured(Categories) { Object.values(Categories).forEach(function(Profiles){ Profiles.forEach(function(Profile){ Window.innerHTML += `
- +
diff --git a/App/Net.js b/App/Net.js index b4a7ce6..959f714 100644 --- a/App/Net.js +++ b/App/Net.js @@ -1,5 +1,6 @@ function NetApiCall(Data, Proc) { - // Data = {Target: "Friendica", Method: "...", Data: {}, Call: (), CallFine: (), CallFail: ()} + var Method = Data.Method.split(' ')[0]; + var Endpoint = Data.Method.split(' ').slice(1).join(' '); var Req = new XMLHttpRequest(); Req.Proc = Proc; Req.onloadend = function(){ @@ -24,13 +25,14 @@ function NetApiCall(Data, Proc) { }; }; }; - if (Data.Target == 'Mastodon') { - Req.open('GET', `${MastodonUrl}/api/v1/${Data.Method}`, true); - } else - if (Data.Target == 'Friendica') { - Req.open('GET', `${FriendicaUrl}/api/${Data.Method}.json`, true); - Req.setRequestHeader('Authorization', `Basic ${btoa(FriendicaCredentials)}`); - }; + //if (Data.Target == 'Mastodon') { + // Req.open(Method, `${MastodonUrl}/api/v1/${Endpoint}`, true); + //} else + //if (Data.Target == 'Friendica') { + // Req.open(Method, `${FriendicaUrl}/api/${Endpoint}.json`, true); + // Req.setRequestHeader('Authorization', `Basic ${btoa(FriendicaCredentials)}`); + //}; + Req.open(Method, `${Data.Target}/api/v1/${Endpoint}`, true); Req.send(); }; diff --git a/App/Utils.js b/App/Utils.js index 5d4d5e1..4ac2f1d 100644 --- a/App/Utils.js +++ b/App/Utils.js @@ -6,6 +6,15 @@ function RndId() { return `${Date.now()}${Math.random() + Math.random()}`; }; +function UrlBase(Url) { + var Lower = Url.toLowerCase(); + var Domain = UrlDomain(Url); + if (Lower.startsWith('http://')) return `http://${Domain}`; + else + if (Lower.startsWith('https://')) return `https://${Domain}`; + else + return `//${Domain}`; +}; function UrlDomain(Url) { return Url.split('//')[1].split('/')[0]; }; @@ -117,6 +126,9 @@ function JsonTransformCycleB(TreeOld, SchemaNew, NodeNew, TypeOld) { if (IsObj(KeyOld)) { // Object in SchemaNew / Deep nested children in TreeOld Object.keys(KeyOld).forEach(function(KeyObj){ + //if (SchemaNew.__All__) { + // TreeNew.__All__ = SchemaNew.__All__; + //}; if (KeyObj === '__Eval__') { eval(KeyOld[KeyObj]); } else