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: |
python3 ./Build.py
mv ./Dist ./public
cp ./public/Friendiiverse.html ./public/index.html
artifacts:
paths:
- public

View File

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

View File

@ -1,18 +1,35 @@
var FakeApi = {
//
Friendiiverse: {
Featured: {
Featured: [],
Categories: [],
},
},
Mastodon: {
//"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 = {
"avatar": "https://picsum.photos/64",
"url": "https://mastodon.example.com/@Tester",
avatar: "https://picsum.photos/seed/Tester.Icon/64",
display_name: "The Tester",
url: "https://mastodon.example.com/@Tester",
};
FakeApi.Mastodon.Status = {
"account": FakeApi.Mastodon.Account,
"content": "<p>Lorem ipsum dolor sit amet...</p>",
"created_at": "2023-01-01T13:00:00.123Z",
"url": "https://mastodon.example.com/@Tester/1234567890",
account: FakeApi.Mastodon.Account,
content: "<p>Lorem ipsum dolor sit amet...</p>",
created_at: "2023-01-01T13:00:00.123Z",
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) {
if (UseFakeApi) {
ResFetchMastodon({responseJson: [FakeApi.Mastodon.Status], Proc: Proc});
@ -105,13 +99,18 @@ function FetchMastodon(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) {
Notes.forEach(function(Note){
TimelineView.innerHTML += `<div class="View Note">
<a href="${Note.Author.Url}">
<img class="Author Picture" src="${Note.Author.Picture}"/>
${Note.Author.Url}
<img class="Author Icon" src="${Note.Author.Icon}"/>
${Note.Author.Name}
</a>
${Note.Content}
<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 = `
<div>
<h3>Featured</h3>
@ -139,3 +160,6 @@ PlazasView.innerHTML = `
</ul>
</div>
`;
DoAsync(FetchFeatured, FillFeatured);

View File

@ -25,6 +25,6 @@ footer {
margin: 12px;
}
.View.Note .Author.Picture {
.View.Note .Author.Icon {
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
// DEVNOTE: Unsafe, should check for colliding "__" keys from input tree and act accordingly
function JsonTransformA(TreesOld, SchemaCurr, SchemaRoot) {
@ -78,10 +82,10 @@ function JsonTransformB(TreesOld, SchemaNew, NodeNew, TypeOld) {
};
};
function JsonTransformCycleB(TreeOld, SchemaNew, NodeNew, TypeOld) {
var TreeNew = NodeNew;
Object.keys(NodeNew).forEach(function(KeyNew){
if (TypeOld in NodeNew[KeyNew]) {
var KeyOld = NodeNew[KeyNew][TypeOld];
var TreeNew = CopyObj(NodeNew);
Object.keys(TreeNew).forEach(function(KeyNew){
if (TypeOld in TreeNew[KeyNew]) {
var KeyOld = TreeNew[KeyNew][TypeOld];
var ObjOld = TreeOld[KeyOld];
if (typeof(KeyOld) == 'object') {
// Deep nested children in TreeOld