Api fixes and progress

This commit is contained in:
octospacc 2023-04-20 18:13:47 +02:00
parent f6e2dff546
commit 279691e9a1
6 changed files with 91 additions and 39 deletions

View File

@ -18,6 +18,7 @@ pages:
script: | script: |
python3 ./Build.py python3 ./Build.py
mv ./Dist ./public mv ./Dist ./public
cp ./public/Friendiiverse.html ./public/index.html
artifacts: artifacts:
paths: paths:
- public - public

View File

@ -18,33 +18,39 @@ var TransSchemas = {
}, },
}, },
}; };
var TransSchemas_ = {
"Author": { var ApiSchema = {
"Banner": { __Account__: {
"Mastodon": "header" Banner: {
Mastodon: "header",
}, },
"Picture": { Icon: {
"Mastodon": "avatar" Mastodon: "avatar",
}, },
"Url": { Name: {
"Mastodon": "url" Mastodon: "display_name",
},
Url: {
Mastodon: "url",
}, },
}, },
"Note": { Note: {
"Author": { Author: {
"Mastodon": "account" Mastodon: "account",
}, },
"Content": { Content: {
"Mastodon": "content" Mastodon: "content",
}, },
"Time": { Time: {
"Mastodon": "created_at" Mastodon: "created_at",
}, },
"Url": { Url: {
"Mastodon": "url" Mastodon: "url",
}, },
}, },
}; };
ApiSchema.Author = CopyObj(ApiSchema.__Account__);
ApiSchema.Channel = CopyObj(ApiSchema.__Account__);
var TransParsers = { var TransParsers = {
Mastodon: { Mastodon: {
@ -55,8 +61,8 @@ var TransParsers = {
return JsonTransformA(Data, TransSchemas.Mastodon.Instance, TransSchemas.Mastodon); return JsonTransformA(Data, TransSchemas.Mastodon.Instance, TransSchemas.Mastodon);
}, },
Status(Data) { Status(Data) {
return JsonTransformA(Data, TransSchemas.Mastodon.Status, TransSchemas.Mastodon); //return JsonTransformA(Data, TransSchemas.Mastodon.Status, TransSchemas.Mastodon);
//return JsonTransformB(Data, TransSchemas_, TransSchemas_.Note, 'Mastodon'); return JsonTransformB(Data, ApiSchema, ApiSchema.Note, 'Mastodon');
}, },
}, },
}; };

View File

@ -1,18 +1,35 @@
var FakeApi = { var FakeApi = {
// Friendiiverse: {
Featured: {
Featured: [],
Categories: [],
},
},
Mastodon: { Mastodon: {
//"timelines/public": //"timelines/public":
}, },
}; };
FakeApi.Friendiiverse.Featured.Featured.push({
Banner: "https://picsum.photos/seed/Testing.Banner/320/180",
Icon: "https://picsum.photos/seed/Testing.Icon/64",
Name: "Testing Channel",
});
FakeApi.Friendiiverse.Featured.Categories.push({
Banner: "https://picsum.photos/seed/fediverse.Banner/320/180",
Icon: "https://picsum.photos/seed/fediverse.Icon/64",
Name: "#fediverse",
});
FakeApi.Mastodon.Account = { FakeApi.Mastodon.Account = {
"avatar": "https://picsum.photos/64", avatar: "https://picsum.photos/seed/Tester.Icon/64",
"url": "https://mastodon.example.com/@Tester", display_name: "The Tester",
url: "https://mastodon.example.com/@Tester",
}; };
FakeApi.Mastodon.Status = { FakeApi.Mastodon.Status = {
"account": FakeApi.Mastodon.Account, account: FakeApi.Mastodon.Account,
"content": "<p>Lorem ipsum dolor sit amet...</p>", content: "<p>Lorem ipsum dolor sit amet...</p>",
"created_at": "2023-01-01T13:00:00.123Z", created_at: "2023-01-01T13:00:00.123Z",
"url": "https://mastodon.example.com/@Tester/1234567890", url: "https://mastodon.example.com/@Tester/1234567890",
}; };

View File

@ -92,12 +92,6 @@ function DisplayFriendicaTimeline(Timeline) {
}}); }});
}; };
function ResFetchMastodon(Res) {
var Notes = TransParsers.Mastodon.Status(Res.responseJson);
LogDebug(Notes, 'l');
CurrTasks[Res.Proc[0]].Return(Notes);
};
function FetchMastodon(Proc) { function FetchMastodon(Proc) {
if (UseFakeApi) { if (UseFakeApi) {
ResFetchMastodon({responseJson: [FakeApi.Mastodon.Status], Proc: Proc}); ResFetchMastodon({responseJson: [FakeApi.Mastodon.Status], Proc: Proc});
@ -105,13 +99,18 @@ function FetchMastodon(Proc) {
ApiCall({Target: "Mastodon", Method: "timelines/public", CallFine: ResFetchMastodon}, Proc); ApiCall({Target: "Mastodon", Method: "timelines/public", CallFine: ResFetchMastodon}, Proc);
}; };
}; };
function ResFetchMastodon(Res) {
var Notes = TransParsers.Mastodon.Status(Res.responseJson);
LogDebug(Notes, 'l');
CurrTasks[Res.Proc[0]].Return(Notes);
};
function FillTimeline(Notes) { function FillTimeline(Notes) {
Notes.forEach(function(Note){ Notes.forEach(function(Note){
TimelineView.innerHTML += `<div class="View Note"> TimelineView.innerHTML += `<div class="View Note">
<a href="${Note.Author.Url}"> <a href="${Note.Author.Url}">
<img class="Author Picture" src="${Note.Author.Picture}"/> <img class="Author Icon" src="${Note.Author.Icon}"/>
${Note.Author.Url} ${Note.Author.Name}
</a> </a>
${Note.Content} ${Note.Content}
<a href="${Note.Url}">${Note.Time}</a> <a href="${Note.Url}">${Note.Time}</a>
@ -119,6 +118,28 @@ function FillTimeline(Notes) {
}); });
}; };
function FetchFeatured(Proc) {
//if (UseFakeApi) {
CurrTasks[Proc[0]].Return(FakeApi.Friendiiverse.Featured);
//} else {
//};
};
function FillFeatured(Categories) {
Object.values(Categories).forEach(function(Channels){
Channels.forEach(function(Channel){
PlazasView.innerHTML += `<div>
<a href="${Channel.Url}">
<img class="" src="${Channel.Banner}"/>
<img class="" src="${Channel.Icon}"/>
${Channel.Name}
</a>
</div>`;
});
});
};
PlazasView.innerHTML = ` PlazasView.innerHTML = `
<div> <div>
<h3>Featured</h3> <h3>Featured</h3>
@ -139,3 +160,6 @@ PlazasView.innerHTML = `
</ul> </ul>
</div> </div>
`; `;
DoAsync(FetchFeatured, FillFeatured);

View File

@ -25,6 +25,6 @@ footer {
margin: 12px; margin: 12px;
} }
.View.Note .Author.Picture { .View.Note .Author.Icon {
width: 64px; width: 64px;
} }

View File

@ -20,6 +20,10 @@ function LogDebug(Data, Status) {
}; };
}; };
function CopyObj(Obj) {
return JSON.parse(JSON.stringify(Obj));
};
// Transform JSON tree into a new using a template schema // Transform JSON tree into a new using a template schema
// DEVNOTE: Unsafe, should check for colliding "__" keys from input tree and act accordingly // DEVNOTE: Unsafe, should check for colliding "__" keys from input tree and act accordingly
function JsonTransformA(TreesOld, SchemaCurr, SchemaRoot) { function JsonTransformA(TreesOld, SchemaCurr, SchemaRoot) {
@ -78,10 +82,10 @@ function JsonTransformB(TreesOld, SchemaNew, NodeNew, TypeOld) {
}; };
}; };
function JsonTransformCycleB(TreeOld, SchemaNew, NodeNew, TypeOld) { function JsonTransformCycleB(TreeOld, SchemaNew, NodeNew, TypeOld) {
var TreeNew = NodeNew; var TreeNew = CopyObj(NodeNew);
Object.keys(NodeNew).forEach(function(KeyNew){ Object.keys(TreeNew).forEach(function(KeyNew){
if (TypeOld in NodeNew[KeyNew]) { if (TypeOld in TreeNew[KeyNew]) {
var KeyOld = NodeNew[KeyNew][TypeOld]; var KeyOld = TreeNew[KeyNew][TypeOld];
var ObjOld = TreeOld[KeyOld]; var ObjOld = TreeOld[KeyOld];
if (typeof(KeyOld) == 'object') { if (typeof(KeyOld) == 'object') {
// Deep nested children in TreeOld // Deep nested children in TreeOld