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
# 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
image: alpine:latest
stages:
- test
- deploy
before_script: |
apk update
apk add python3
sast:
stage: test
include:
- 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: {
"__": "Author",
"url": "Url",
"avatar": "Picture",
"header": "Banner",
},
Instance: {
"thumbnail": "Banner",
},
Status: {
"__": "Note",
@ -13,14 +18,31 @@ var TransSchemas = {
},
},
};
var TransSchemas_ = {
"Note": {
"Author": {
"Mastodon": "Status.account"
},
"Content": {
"Mastodon": "Status.content"
},
"Url": {
"Mastodon": "Status.url"
},
},
};
var TransParsers = {
Mastodon: {
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) {
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!
</div>
<div id="PlazasView"></div>
<textarea id="Input"></textarea>
<button id="Post">Post</button>
<div id="TimelineView"></div>
<xmp id="DataView"></xmp>
</main>

View File

@ -49,22 +49,22 @@ function ApiCall(Data, Proc) {
var Status = String(this.status);
if (Data.Call) {
Data.Call(this);
}
};
if (HttpCodeGood(this.status)) {
LogDebug([this.status, this.responseText], 'l');
if (Data.CallFine) {
Data.CallFine(this);
};
LogDebug([this.status, this.responseText], 'l');
} else {
LogDebug([this.status, this.responseText], 'e');
if (Data.CallFail) {
Data.CallFail(this);
};
LogDebug([this.status, this.responseText], 'e');
};
};
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)}`);
@ -89,7 +89,7 @@ function DisplayFriendicaTimeline(Timeline) {
function FetchMastodon(Proc) {
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');
CurrTasks[Proc[0]].Return(Notes);
}}, Proc);
@ -97,9 +97,12 @@ function FetchMastodon(Proc) {
function FillTimeline(Notes) {
Notes.forEach(function(Note){
TimelineView.innerHTML += `<div class="NoteView">
TimelineView.innerHTML += `<div class="Note">
<a href="${Note.Author.Url}">
<img class="Author Picture" src="${Note.Author.Picture}"/>
${Note.Author.Url}
</a>
<a href="${Note.Url}">${Note.Time}</a>
${Note.Author.Url}
${Note.Content}
</div>`;
});

View File

@ -20,7 +20,11 @@ footer {
white-space: break-spaces;
}
.NoteView {
.Note {
border: 4px solid purple;
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
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 = {};
Object.keys(TreeOld).forEach(function(KeyOld){
var Content = TreeOld[KeyOld];
@ -29,19 +41,23 @@ function JsonTransform(TreeOld, SchemaCurr, SchemaRoot) {
if (typeof(Content) == 'object' && Content !== null) {
if (Array.isArray(Content)) {
// Lists
var ListNew = [];
/* var ListNew = [];
Content.forEach(function(Value){
ListNew.push(JsonTransform(Value, KeyNew));
});
TreeNew[KeyNew] = ListNew;
TreeNew[KeyNew] = ListNew;*/
} else {
// Dicts
if (!KeyNew.__) {
KeyNew.__ = KeyOld;
// Strange bug, in this context we can't assign new value to child of the object, we use a variable
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 {
// Values
@ -50,3 +66,13 @@ function JsonTransform(TreeOld, SchemaCurr, SchemaRoot) {
});
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;
};