Upd. CI; User features updates

This commit is contained in:
octospacc 2023-04-20 00:19:19 +02:00
parent afea1367db
commit 76865b605d
6 changed files with 94 additions and 25 deletions

View File

@ -1,13 +1,25 @@
# You can override the included template(s) by including variable overrides image: alpine:latest
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings
# Note that environment variables can be set in several places
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
stages: stages:
- test - test
- deploy
before_script: |
apk update
apk add python3
sast: sast:
stage: test stage: test
include: include:
- template: Security/SAST.gitlab-ci.yml - template: Security/SAST.gitlab-ci.yml
pages:
stage: deploy
script: |
python3 ./Build.py
artifacts:
paths:
- public
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH

View File

@ -3,6 +3,11 @@ var TransSchemas = {
Account: { Account: {
"__": "Author", "__": "Author",
"url": "Url", "url": "Url",
"avatar": "Picture",
"header": "Banner",
},
Instance: {
"thumbnail": "Banner",
}, },
Status: { Status: {
"__": "Note", "__": "Note",
@ -13,14 +18,31 @@ var TransSchemas = {
}, },
}, },
}; };
var TransSchemas_ = {
"Note": {
"Author": {
"Mastodon": "Status.account"
},
"Content": {
"Mastodon": "Status.content"
},
"Url": {
"Mastodon": "Status.url"
},
},
};
var TransParsers = { var TransParsers = {
Mastodon: { Mastodon: {
Account(Data) { Account(Data) {
return JsonTransform(Data, TransSchemas.Mastodon.Author, TransSchemas.Mastodon); return JsonTransformA(Data, TransSchemas.Mastodon.Author, TransSchemas.Mastodon);
},
Instance(Data) {
return JsonTransformA(Data, TransSchemas.Mastodon.Instance, TransSchemas.Mastodon);
}, },
Status(Data) { Status(Data) {
return JsonTransform(Data, TransSchemas.Mastodon.Status, TransSchemas.Mastodon); return JsonTransformA(Data, TransSchemas.Mastodon.Status, TransSchemas.Mastodon);
// return JsonTransformB({Status: Data}, TransSchemas_, TransSchemas_.Note, 'Mastodon');
}, },
}, },
}; };

View File

@ -25,6 +25,8 @@ var UseFakeApi = true;
No Script! No Script!
</div> </div>
<div id="PlazasView"></div> <div id="PlazasView"></div>
<textarea id="Input"></textarea>
<button id="Post">Post</button>
<div id="TimelineView"></div> <div id="TimelineView"></div>
<xmp id="DataView"></xmp> <xmp id="DataView"></xmp>
</main> </main>

View File

@ -49,22 +49,22 @@ function ApiCall(Data, Proc) {
var Status = String(this.status); var Status = String(this.status);
if (Data.Call) { if (Data.Call) {
Data.Call(this); Data.Call(this);
} };
if (HttpCodeGood(this.status)) { if (HttpCodeGood(this.status)) {
LogDebug([this.status, this.responseText], 'l');
if (Data.CallFine) { if (Data.CallFine) {
Data.CallFine(this); Data.CallFine(this);
}; };
LogDebug([this.status, this.responseText], 'l');
} else { } else {
LogDebug([this.status, this.responseText], 'e');
if (Data.CallFail) { if (Data.CallFail) {
Data.CallFail(this); Data.CallFail(this);
}; };
LogDebug([this.status, this.responseText], 'e');
}; };
}; };
if (Data.Target == 'Mastodon') { if (Data.Target == 'Mastodon') {
Req.open('GET', `${MastodonUrl}/api/v1/${Data.Method}`, true); Req.open('GET', `${MastodonUrl}/api/v1/${Data.Method}`, true);
}; } else
if (Data.Target == 'Friendica') { if (Data.Target == 'Friendica') {
Req.open('GET', `${FriendicaUrl}/api/${Data.Method}.json`, true); Req.open('GET', `${FriendicaUrl}/api/${Data.Method}.json`, true);
Req.setRequestHeader('Authorization', `Basic ${btoa(FriendicaCredentials)}`); Req.setRequestHeader('Authorization', `Basic ${btoa(FriendicaCredentials)}`);
@ -89,7 +89,7 @@ function DisplayFriendicaTimeline(Timeline) {
function FetchMastodon(Proc) { function FetchMastodon(Proc) {
ApiCall({Target: "Mastodon", Method: "timelines/public", CallFine: function(Res){ ApiCall({Target: "Mastodon", Method: "timelines/public", CallFine: function(Res){
var Notes = [ TransParsers.Mastodon.Status( JSON.parse(Res.responseText)[0] ) ]; var Notes = TransParsers.Mastodon.Status(JSON.parse(Res.responseText));
LogDebug(Notes, 'l'); LogDebug(Notes, 'l');
CurrTasks[Proc[0]].Return(Notes); CurrTasks[Proc[0]].Return(Notes);
}}, Proc); }}, Proc);
@ -97,9 +97,12 @@ function FetchMastodon(Proc) {
function FillTimeline(Notes) { function FillTimeline(Notes) {
Notes.forEach(function(Note){ Notes.forEach(function(Note){
TimelineView.innerHTML += `<div class="NoteView"> TimelineView.innerHTML += `<div class="Note">
<a href="${Note.Url}">${Note.Time}</a> <a href="${Note.Author.Url}">
<img class="Author Picture" src="${Note.Author.Picture}"/>
${Note.Author.Url} ${Note.Author.Url}
</a>
<a href="${Note.Url}">${Note.Time}</a>
${Note.Content} ${Note.Content}
</div>`; </div>`;
}); });

View File

@ -20,7 +20,11 @@ footer {
white-space: break-spaces; white-space: break-spaces;
} }
.NoteView { .Note {
border: 4px solid purple; border: 4px solid purple;
margin: 12px; margin: 12px;
} }
.Note > .Author.Picture {
width: 64px;
}

View File

@ -21,7 +21,19 @@ function LogDebug(Data, Status) {
}; };
// Transform JSON tree into a new using a template schema // Transform JSON tree into a new using a template schema
function JsonTransform(TreeOld, SchemaCurr, SchemaRoot) { // DEVNOTE: Unsafe, should check for colliding "__" keys from input tree and act accordingly
function JsonTransformA(TreesOld, SchemaCurr, SchemaRoot) {
if (Array.isArray(TreesOld)) {
var ListNew = [];
ForceList(TreesOld).forEach(function(TreeOld){
ListNew.push(JsonTransformCycleA(TreeOld, SchemaCurr, SchemaRoot));
});
return ListNew;
} else {
return JsonTransformCycleA(TreesOld, SchemaCurr, SchemaRoot);
};
};
function JsonTransformCycleA(TreeOld, SchemaCurr, SchemaRoot) {
var TreeNew = {}; var TreeNew = {};
Object.keys(TreeOld).forEach(function(KeyOld){ Object.keys(TreeOld).forEach(function(KeyOld){
var Content = TreeOld[KeyOld]; var Content = TreeOld[KeyOld];
@ -29,19 +41,23 @@ function JsonTransform(TreeOld, SchemaCurr, SchemaRoot) {
if (typeof(Content) == 'object' && Content !== null) { if (typeof(Content) == 'object' && Content !== null) {
if (Array.isArray(Content)) { if (Array.isArray(Content)) {
// Lists // Lists
var ListNew = []; /* var ListNew = [];
Content.forEach(function(Value){ Content.forEach(function(Value){
ListNew.push(JsonTransform(Value, KeyNew)); ListNew.push(JsonTransform(Value, KeyNew));
}); });
TreeNew[KeyNew] = ListNew; TreeNew[KeyNew] = ListNew;*/
} else { } else {
// Dicts // Dicts
if (!KeyNew.__) { // Strange bug, in this context we can't assign new value to child of the object, we use a variable
KeyNew.__ = KeyOld; NameKeyNew = KeyNew.__;
if (!NameKeyNew) {
NameKeyNew = KeyOld;
};
TreeNew[NameKeyNew] = JsonTransformA(Content, SchemaRoot[NameKeyNew], SchemaRoot);
if (NameKeyNew !== KeyOld) {
TreeNew[SchemaRoot[NameKeyNew].__] = TreeNew[NameKeyNew];
delete TreeNew[NameKeyNew];
}; };
TreeNew[KeyNew.__] = JsonTransform(Content, SchemaRoot[KeyNew.__], SchemaRoot);
TreeNew[SchemaRoot[KeyNew.__].__] = TreeNew[KeyNew.__];
delete TreeNew[KeyNew.__];
}; };
} else { } else {
// Values // Values
@ -50,3 +66,13 @@ function JsonTransform(TreeOld, SchemaCurr, SchemaRoot) {
}); });
return TreeNew; return TreeNew;
}; };
function JsonTransformB(TreesOld, Schema, Node, Source) {
};
function JsonTransformCycleB(TreeOld, Schema, Node, Source) {
var TreeNew = {};
Object.keys(Node).forEach(function(KeyOld){
console.log(KeyOld)
});
return TreeNew;
};