From afea1367dbdb439dcbc44dfe221c18aebf289605 Mon Sep 17 00:00:00 2001 From: octospacc Date: Wed, 19 Apr 2023 18:06:08 +0200 Subject: [PATCH] Fix Json transformation for nested objects --- Build.py | 3 +- Source/ApiTransform.js | 26 +++++ Source/FakeApi.js | 6 ++ .../Friendiiverse.html | 7 +- Main.js => Source/Main.js | 98 ++++++------------- Strings.js => Source/Strings.js | 0 Style.css => Source/Style.css | 2 +- Source/Utils.js | 52 ++++++++++ Test.txt | 33 ------- Translations.js | 51 ---------- Utils.js | 7 -- 11 files changed, 123 insertions(+), 162 deletions(-) create mode 100644 Source/ApiTransform.js create mode 100644 Source/FakeApi.js rename Friendiiverse.html => Source/Friendiiverse.html (84%) rename Main.js => Source/Main.js (53%) rename Strings.js => Source/Strings.js (100%) rename Style.css => Source/Style.css (95%) create mode 100644 Source/Utils.js delete mode 100644 Test.txt delete mode 100644 Translations.js delete mode 100644 Utils.js diff --git a/Build.py b/Build.py index f832a6b..548e87f 100755 --- a/Build.py +++ b/Build.py @@ -2,12 +2,13 @@ import os from pathlib import Path +os.chdir(os.path.dirname(os.path.abspath(__file__))) os.makedirs('./Dist', exist_ok=True) with open('./Friendiiverse.html', 'r') as Base: Base = Base.read() -def FragReplace(Find, Replace, Pattern='*.*', Folder='./'): +def FragReplace(Find, Replace, Pattern='*.*', Folder='./Source/'): global Base for File in Path('./').rglob(Pattern): with open(File, 'r') as Frag: diff --git a/Source/ApiTransform.js b/Source/ApiTransform.js new file mode 100644 index 0000000..8c6853b --- /dev/null +++ b/Source/ApiTransform.js @@ -0,0 +1,26 @@ +var TransSchemas = { + Mastodon: { + Account: { + "__": "Author", + "url": "Url", + }, + Status: { + "__": "Note", + "account": {"__": "Account"}, + "content": "Content", + "created_at": "Time", + "url": "Url", + }, + }, +}; + +var TransParsers = { + Mastodon: { + Account(Data) { + return JsonTransform(Data, TransSchemas.Mastodon.Author, TransSchemas.Mastodon); + }, + Status(Data) { + return JsonTransform(Data, TransSchemas.Mastodon.Status, TransSchemas.Mastodon); + }, + }, +}; diff --git a/Source/FakeApi.js b/Source/FakeApi.js new file mode 100644 index 0000000..35bebeb --- /dev/null +++ b/Source/FakeApi.js @@ -0,0 +1,6 @@ +var FakeApi = { + // + Mastodon: { + //"timelines/public": + }, +}; diff --git a/Friendiiverse.html b/Source/Friendiiverse.html similarity index 84% rename from Friendiiverse.html rename to Source/Friendiiverse.html index d72e558..87f7209 100644 --- a/Friendiiverse.html +++ b/Source/Friendiiverse.html @@ -6,7 +6,7 @@ - + +