Trying to do universal timelines

This commit is contained in:
octospacc 2023-04-25 15:00:41 +02:00
parent 3f69a8a94d
commit fd0abd9df1
5 changed files with 61 additions and 24 deletions

View File

@ -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({ FakeApi.Friendiiverse.Featured.Featured.push({
Banner: "https://picsum.photos/seed/Testing.Banner/320/180", Banner: "https://picsum.photos/seed/Testing.Banner/320/180",
Icon: "https://picsum.photos/seed/Testing.Icon/64", Icon: "https://picsum.photos/seed/Testing.Icon/64",

View File

@ -22,11 +22,11 @@ var TransSchemas = {
*/ */
var ApiSchema = { var ApiSchema = {
__All__: { //__All__: {
SourceInstance: { // __Software__: {
__Eval__: "", // __EvalSet__: "TypeOld",
}, // },
}, //},
Note: { Note: {
Content: { Content: {
Mastodon: "content", Mastodon: "content",
@ -82,7 +82,7 @@ var ApiSchema = {
var ApiEndpoints = { var ApiEndpoints = {
FetchNotes: { FetchNotes: {
Mastodon(Profile) { Mastodon(Profile) {
return `accounts/${Profile.Id}/statuses`; return `GET accounts/${Profile.Id}/statuses`;
}, },
}, },
}; };

View File

@ -43,7 +43,7 @@ function DoAsync(First, Then, Data) {
}, },
}; };
// Call all First functs // Call all First functs
ForceList(First).forEach(function(Fun, Data){ ForceList(First).forEach(function(Fun){
var Task = RndId(); var Task = RndId();
var Proc = [Job, Task]; var Proc = [Job, Task];
Tasker[Job][Task] = {}; Tasker[Job][Task] = {};
@ -78,24 +78,40 @@ function DisplayProfile(Profile) {
</div> </div>
</a> </a>
</div>`; </div>`;
DoAsync(FetchMastodon, FillTimeline, Profile); DoAsync(FetchNotes, FillTimeline, Profile);
};
function DisplayMastodonTimeline(Data) {
var Window = MkWindow();
Window.innerHTML += `<div class="" style="display: inline-block;">
<a href="${Profile.Url}">
<div>
<img class="" src="${Profile.Banner}"/>
</div>
<div>
<img class="" src="${Profile.Icon}"/>
${Profile.Name}
</div>
</a>
</div>`;
DoAsync(FetchNotes, FillTimeline, Profile);
}; };
function FetchNotes(Profile, Proc) { function FetchNotes(Profile, Proc) {
var Soft = Profile.__Software__; var Soft = Profile.__Software__;
NetApiCall({Target: Soft, Method: ApiEndpoints.FetchNotes[Soft](Profile), CallFine: function(Res){ NetApiCall({Target: UrlBase(Profile.Url), Method: ApiEndpoints.FetchNotes['Mastodon'](Profile), CallFine: function(Res){
var Notes = ApiTransform(Res.responseJson, 'Mastodon', 'Note'); var Notes = ApiTransform(Res.responseJson, Soft, 'Note');
LogDebug(Notes, 'l'); LogDebug(Notes, 'l');
Tasker[Res.Proc[0]].Return(Notes); Tasker[Res.Proc[0]].Return(Notes);
}}, Proc); }}, Proc);
}; };
function FetchMastodon(Proc) { function FetchMastodon(Proc) {
if (UseFakeApi) { //if (UseFakeApi) {
ResFetchMastodon({responseJson: [FakeApi.Mastodon.Status], Proc: Proc}); // ResFetchMastodon({responseJson: [FakeApi.Mastodon.Status], Proc: Proc});
} else { //} else {
NetApiCall({Target: "Mastodon", Method: "timelines/public", CallFine: ResFetchMastodon}, Proc); NetApiCall({Target: "Mastodon", Method: "GET timelines/public", CallFine: ResFetchMastodon}, Proc);
}; //};
}; };
function ResFetchMastodon(Res) { function ResFetchMastodon(Res) {
var Notes = ApiTransform(Res.responseJson, 'Mastodon', 'Note'); var Notes = ApiTransform(Res.responseJson, 'Mastodon', 'Note');
@ -136,7 +152,7 @@ function FillFeatured(Categories) {
Object.values(Categories).forEach(function(Profiles){ Object.values(Categories).forEach(function(Profiles){
Profiles.forEach(function(Profile){ Profiles.forEach(function(Profile){
Window.innerHTML += `<div> Window.innerHTML += `<div>
<a href="${Profile.Url}" onclick="DisplayProfile(ApiCache.Urls['${Profile.Url}']); return false;"> <a href="${Profile.Url}" onclick="${Profile.__Display__}('${Profile.Url}'); return false;">
<div> <div>
<img src="${Profile.Banner}"/> <img src="${Profile.Banner}"/>
</div> </div>

View File

@ -1,5 +1,6 @@
function NetApiCall(Data, Proc) { 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(); var Req = new XMLHttpRequest();
Req.Proc = Proc; Req.Proc = Proc;
Req.onloadend = function(){ Req.onloadend = function(){
@ -24,13 +25,14 @@ function NetApiCall(Data, Proc) {
}; };
}; };
}; };
if (Data.Target == 'Mastodon') { //if (Data.Target == 'Mastodon') {
Req.open('GET', `${MastodonUrl}/api/v1/${Data.Method}`, true); // Req.open(Method, `${MastodonUrl}/api/v1/${Endpoint}`, true);
} else //} else
if (Data.Target == 'Friendica') { //if (Data.Target == 'Friendica') {
Req.open('GET', `${FriendicaUrl}/api/${Data.Method}.json`, true); // Req.open(Method, `${FriendicaUrl}/api/${Endpoint}.json`, true);
Req.setRequestHeader('Authorization', `Basic ${btoa(FriendicaCredentials)}`); // Req.setRequestHeader('Authorization', `Basic ${btoa(FriendicaCredentials)}`);
}; //};
Req.open(Method, `${Data.Target}/api/v1/${Endpoint}`, true);
Req.send(); Req.send();
}; };

View File

@ -6,6 +6,15 @@ function RndId() {
return `${Date.now()}${Math.random() + Math.random()}`; 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) { function UrlDomain(Url) {
return Url.split('//')[1].split('/')[0]; return Url.split('//')[1].split('/')[0];
}; };
@ -117,6 +126,9 @@ function JsonTransformCycleB(TreeOld, SchemaNew, NodeNew, TypeOld) {
if (IsObj(KeyOld)) { if (IsObj(KeyOld)) {
// Object in SchemaNew / Deep nested children in TreeOld // Object in SchemaNew / Deep nested children in TreeOld
Object.keys(KeyOld).forEach(function(KeyObj){ Object.keys(KeyOld).forEach(function(KeyObj){
//if (SchemaNew.__All__) {
// TreeNew.__All__ = SchemaNew.__All__;
//};
if (KeyObj === '__Eval__') { if (KeyObj === '__Eval__') {
eval(KeyOld[KeyObj]); eval(KeyOld[KeyObj]);
} else } else