Api fix for Misskey timeline

This commit is contained in:
octospacc 2023-04-28 17:25:42 +02:00
parent 9e9464e297
commit d8f35afa53
5 changed files with 41 additions and 22 deletions

View File

@ -24,8 +24,9 @@ var TransSchemas = {
var ApiSchema = {
__All__: {
ServerSoftware: { //TODO: Handle this in JsonTransform
Mastodon: {__Set__: "Mastodon"},
Misskey: {__Set__: "Misskey"},
//Mastodon: {__Set__: "Mastodon"},
//Misskey: {__Set__: "Misskey"},
__All__: {__EvalSet__: "TypeOld"},
},
},
Note: {
@ -34,10 +35,12 @@ var ApiSchema = {
Misskey: "text",
},
Profile: {
__: "Profile",
Mastodon: "account",
Misskey: "user",
},
Quoting: {
__: "Note",
Mastodon: "reblog",
Misskey: "renote",
},
@ -73,9 +76,13 @@ var ApiSchema = {
else
if (TreeOld.group) 'Group';
`},
Misskey: {__EvalSet__: `
if (TreeOld.isBot) 'Bot';
`},
},
Url: {
Mastodon: "url",
Misskey: "uri",
},
},
};
@ -85,6 +92,9 @@ var ApiEndpoints = {
Mastodon(Profile) {
return `GET api/v1/accounts/${Profile.Id}/statuses`;
},
Misskey(Profile) {
return ``;
},
},
ServerInfo: {
Mastodon: "GET api/v1/instance",
@ -95,6 +105,7 @@ var ApiEndpoints = {
},
ServerTimeline: {
Mastodon: "GET api/v1/timelines/public",
Misskey: "POST api/notes/local-timeline",
},
};

View File

@ -57,7 +57,7 @@ function JsonTransformB(TreesOld, SchemaNew, NodeNew, TypeOld) {
return ListNew;
} else {
// Object
if (TreesOld) {
if (TreesOld && SchemaNew && NodeNew) {
return JsonTransformCycleB(TreesOld, SchemaNew, NodeNew, TypeOld);
};
};
@ -66,19 +66,31 @@ function JsonTransformB(TreesOld, SchemaNew, NodeNew, TypeOld) {
function JsonTransformCycleB(TreeOld, SchemaNew, NodeNew, TypeOld) {
var TreeNew = CopyObj(NodeNew);
if (SchemaNew.__All__) {
TreeNew.__All__ = CopyObj(SchemaNew.__All__);
//TreeNew.__All__ = CopyObj(SchemaNew.__All__);
//console.log(1, '__All__')
//_.forOwn(TreeNew, function(KeyNewVal, KeyNew){
// console.log(1, KeyNew)
//});
_.forOwn(SchemaNew.__All__, function(Val, Key){
//console.log(1, Key)
TreeNew[Key] = CopyObj(Val);
});
};
_.forOwn(TreeNew, function(KeyNewVal, KeyNew){
//if (KeyNew === '__All__') {
// console.log(1, KeyNew)
// _.forOwn(KeyOld, function(KeyObjVal, KeyObj){});
//};
if (KeyNewVal.__All__ && !KeyNewVal[TypeOld]) {
//console.log(3, KeyNewVal.__All__)
KeyNewVal[TypeOld] = KeyNewVal.__All__;
};
if (KeyNewVal[TypeOld]) {
var KeyOld = KeyNewVal[TypeOld];
var ObjOld = TreeOld[KeyOld];
if (IsObj(KeyOld)) {
// Object in NodeNew / Deep nested children in TreeOld
_.forOwn(KeyOld, function(KeyObjVal, KeyObj){
//if (KeyObj === '__All__') { //NOTE: This must be handle as directly nested, not deep (how?)
// console.log('__All__')
// //TreeNew.__All__ = SchemaNew.__All__;
//};
if (KeyObj === '__Eval__') {
eval(KeyObjVal);
} else
@ -102,7 +114,7 @@ function JsonTransformCycleB(TreeOld, SchemaNew, NodeNew, TypeOld) {
} else {
// Value in NodeNew / Direct children in TreeOld
if (IsObj(ObjOld)) {
TreeNew[KeyNew] = JsonTransformB(ObjOld, SchemaNew, SchemaNew[KeyNew], TypeOld);
TreeNew[KeyNew] = JsonTransformB(ObjOld, SchemaNew, SchemaNew[TreeNew[KeyNew].__], TypeOld);
} else {
TreeNew[KeyNew] = ObjOld;
};

View File

@ -127,7 +127,9 @@ function FetchNotes(Profile, Proc) {
var Method = Profile.Type == 'Server'
? ApiEndpoints.ServerTimeline[Soft]
: ApiEndpoints.FetchNotes[Soft](Profile);
NetCall({Target: UrlBase(Profile.Url), Method: Method, CallFine: function(Res){
var Endp = Method;
var Method = Endp.Method || Endp;
NetCall({Target: UrlBase(Profile.Url), Method: Method, Data: Endp.Data, CallFine: function(Res){
var Notes = ApiTransform(Res.responseJson, Soft, 'Note');
LogDebug(Notes, 'l');
Tasker[Res.Proc[0]].Return(Notes);
@ -150,6 +152,9 @@ function ResFetchMastodon(Res) {
function FillTimeline(Notes) {
Notes.forEach(function(Note){
ApiCache.__UrlStore__(Note.Profile);
if (Note.Quoting) {
Note = Note.Quoting;
};
Root.lastChild.innerHTML += `<div class="View Note">
<a href="${Note.Profile.Url}" onclick="DisplayProfile('${Note.Profile.Url}'); return false;">
<img class="Profile Icon" src="${Note.Profile.Icon}"/>

View File

@ -34,6 +34,9 @@ function NetCall(Data, Proc) {
_.forOwn(_.merge({"Content-Type": "application/json"}, Data.Headers), function(Val, Key) {
Req.setRequestHeader(Key, Val);
});
if (Method === 'POST' && !Data.Data) {
Data.Data = {};
};
Req.send(JSON.stringify(Data.Data));
};

12
Bundle.py Executable file → Normal file
View File

@ -4,18 +4,6 @@ from base64 import b64encode
from mimetypes import guess_type
from pathlib import Path
#def MinifyJs(Js):
# New = ''
# Js = Js.replace('\\\n', '\n')
# BlockOpen = False
# for Line in Js.splitlines():
# if '/*' in Line: BlockOpen = True
# if '*/' in Line: BlockOpen = False
# if '//' in Line and not BlockOpen:
# Line = Line.replace('//', '/*') + '*/'
# New += Line
# return New.replace('\n', ' ')
os.chdir(os.path.dirname(os.path.abspath(__file__)))
os.makedirs('./Dist', exist_ok=True)