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

View File

@ -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`;
},
},
};

View File

@ -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) {
</div>
</a>
</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) {
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 += `<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>
<img src="${Profile.Banner}"/>
</div>

View File

@ -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();
};

View File

@ -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