diff --git a/App/ApiTransform.js b/App/ApiTransform.js index f96f587..b24f422 100644 --- a/App/ApiTransform.js +++ b/App/ApiTransform.js @@ -60,7 +60,7 @@ var ApiSchema = { }, Icon: { Mastodon: "avatar", - Misskey: "avatarUrl", + Misskey: {__OldOr__: ["avatarUrl", "iconUrl"]}, }, Name: { Mastodon: {__OldOr__: ["display_name", "title"]}, @@ -82,14 +82,18 @@ var ApiSchema = { var ApiEndpoints = { FetchNotes: { Mastodon(Profile) { - return `GET accounts/${Profile.Id}/statuses`; + return `GET api/v1/accounts/${Profile.Id}/statuses`; }, }, ServerInfo: { - Mastodon: "GET instance", + Mastodon: "GET api/v1/instance", + Misskey: { + Method: "POST api/meta", + Data: {"detail": true}, + }, }, ServerTimeline: { - Mastodon: "GET timelines/public", + Mastodon: "GET api/v1/timelines/public", }, }; diff --git a/App/Main.js b/App/Main.js index bf3fce4..db783cb 100644 --- a/App/Main.js +++ b/App/Main.js @@ -88,6 +88,21 @@ function HtmlAssignPropper(El, Data) { }); }; +function TransNetCall(Data, FromSource, DestType, Proc) { + Data.CallOld = Data.Call; + Data.CallFineOld = Data.CallFine; + Data.CallFailOld = Data.CallFail; + NetCall(_.merge(Data, { + //Call: function(Res){ CallFun(Data.Call, Res); }, + CallFine: function(Res){ + Res.responseJsonOld = Res.responseJson; + Res.responseJson = ApiTransform(Res.responseJson, FromSource, DestType); + Res.response = Res.responseJson; + CallFun(Data.CallFineOld, Res); + }, //CallFail: function(Res){ CallFun(Data.CallFail, Res); }, + }), Proc); +}; + function DisplayProfile(Profile) { Profile = UrlObj(Profile); var Window = MkWindow({className: "Profile"}); @@ -124,7 +139,7 @@ function DisplayMastodonTimeline(Data) { function FetchNotes(Profile, Proc) { var Soft = Profile.__Software__; - NetApiCall({Target: UrlBase(Profile.Url), Method: ApiEndpoints.FetchNotes['Mastodon'](Profile), CallFine: function(Res){ + NetCall({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); @@ -135,7 +150,7 @@ function FetchMastodon(Proc) { //if (UseFakeApi) { // ResFetchMastodon({responseJson: [FakeApi.Mastodon.Status], Proc: Proc}); //} else { - NetApiCall({Target: "Mastodon", Method: "GET timelines/public", CallFine: ResFetchMastodon}, Proc); + NetCall({Target: "Mastodon", Method: "GET timelines/public", CallFine: ResFetchMastodon}, Proc); //}; }; function ResFetchMastodon(Res) { @@ -162,26 +177,25 @@ function FillHome() { var Window = MkWindow({className: "Gallery"}); var Categories = ApiStatic.Featured; Object.keys(Categories).forEach(function(Category){ - Window.innerHTML += `

Featured ${Category}

`; + Window.innerHTML += `

Featured ${Category}

`; Categories[Category].forEach(function(Profile){ ApiCache.Urls[Profile.Url] = Profile; var Rnd = RndHtmlId(); - Window.innerHTML += `
+ Window.querySelector('ul').innerHTML += `
  • +
    - -
    -
    - + ${Profile.Url}
    -
  • `; - NetApiCall({Target: Profile.Url, Method: ApiEndpoints.ServerInfo[Profile.ServerSoftware], CallFine: function(Res){ - var Data = ApiTransform(Res.responseJson, Profile.ServerSoftware, 'Profile'); - HtmlAssign(Rnd, Data); - _.merge(ApiCache.Urls[Profile.Url], Data); - }}); + `; + var Endp = ApiEndpoints.ServerInfo[Profile.ServerSoftware]; + var Method = Endp.Method || Endp; + TransNetCall({Target: Profile.Url, Method: Method, Data: Endp.Data, CallFine: function(Res){ + HtmlAssign(Rnd, Res.responseJson); + _.merge(ApiCache.Urls[Profile.Url], Res.responseJson); + }}, Profile.ServerSoftware, 'Profile'); }); }); }; diff --git a/App/Net.js b/App/Net.js index 959f714..dc70342 100644 --- a/App/Net.js +++ b/App/Net.js @@ -1,4 +1,4 @@ -function NetApiCall(Data, Proc) { +function NetCall(Data, Proc) { var Method = Data.Method.split(' ')[0]; var Endpoint = Data.Method.split(' ').slice(1).join(' '); var Req = new XMLHttpRequest(); @@ -6,6 +6,7 @@ function NetApiCall(Data, Proc) { Req.onloadend = function(){ try { this.responseJson = JSON.parse(this.responseText); + this.response = this.responseJson; this.responseLog = this.responseJson; } catch(Ex) { this.responseLog = this.responseText; @@ -25,15 +26,15 @@ function NetApiCall(Data, Proc) { }; }; }; - //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(); + Req.open(Method, `${Data.Target}/${Endpoint}`, true); + _.forOwn(_.merge({"Content-Type": "application/json"}, Data.Headers), function(Val, Key) { + Req.setRequestHeader(Key, Val); + }); + Req.send(JSON.stringify(Data.Data)); }; function IsHttpCodeGood(Code) { diff --git a/App/Style.css b/App/Style.css index f1d7a7e..1113add 100644 --- a/App/Style.css +++ b/App/Style.css @@ -63,10 +63,19 @@ img, video { margin: 12px; } -.View.Note .Profile.Icon { +.Profile.Banner { + width: 384px; +} + +/*.View.Note*/ .Profile.Icon { width: 64px; } -.Gallery > div { - display: inline-block; +.Window.Gallery > ul { + padding: 0; +} + +.Window.Gallery > ul > li { + display: inline-block; + width: 384px; } diff --git a/App/Utils.js b/App/Utils.js index 081f2a9..152ea1d 100644 --- a/App/Utils.js +++ b/App/Utils.js @@ -22,6 +22,19 @@ function UrlDomain(Url) { return Url.split('//')[1].split('/')[0]; }; +function FuncName(Fun) { + Fun = Fun.toString(); + var Name = Fun.split(' ')[1].split('(')[0].split('{')[0]; + var Hash = Fun.hashCode(); + return `f:${Name} (${Fun.hashCode()})`; +}; + +function CallFun(f, a, b, c, d) { + if (typeof(f) === 'function') { + f(a, b, c, d); + }; +}; + function LogDebug(Data, Status) { if (Debug) { if (!Status) { @@ -32,8 +45,7 @@ function LogDebug(Data, Status) { Data[i] = JSON.parse(Data[i]); } catch(_){}; }; - console[{l: "log", e: "error"}[Status.toLowerCase()]](LogDebug.caller.toString().hashCode() - /*Issue trying to get function name on Eruda... .split(' ')[1].split('(')[0]*/, Data); + console[{l: "log", e: "error"}[Status.toLowerCase()]](FuncName(LogDebug.caller), Data); }; };