Api fix for Misskey timeline
This commit is contained in:
parent
9e9464e297
commit
d8f35afa53
|
@ -24,8 +24,9 @@ var TransSchemas = {
|
||||||
var ApiSchema = {
|
var ApiSchema = {
|
||||||
__All__: {
|
__All__: {
|
||||||
ServerSoftware: { //TODO: Handle this in JsonTransform
|
ServerSoftware: { //TODO: Handle this in JsonTransform
|
||||||
Mastodon: {__Set__: "Mastodon"},
|
//Mastodon: {__Set__: "Mastodon"},
|
||||||
Misskey: {__Set__: "Misskey"},
|
//Misskey: {__Set__: "Misskey"},
|
||||||
|
__All__: {__EvalSet__: "TypeOld"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Note: {
|
Note: {
|
||||||
|
@ -34,10 +35,12 @@ var ApiSchema = {
|
||||||
Misskey: "text",
|
Misskey: "text",
|
||||||
},
|
},
|
||||||
Profile: {
|
Profile: {
|
||||||
|
__: "Profile",
|
||||||
Mastodon: "account",
|
Mastodon: "account",
|
||||||
Misskey: "user",
|
Misskey: "user",
|
||||||
},
|
},
|
||||||
Quoting: {
|
Quoting: {
|
||||||
|
__: "Note",
|
||||||
Mastodon: "reblog",
|
Mastodon: "reblog",
|
||||||
Misskey: "renote",
|
Misskey: "renote",
|
||||||
},
|
},
|
||||||
|
@ -73,9 +76,13 @@ var ApiSchema = {
|
||||||
else
|
else
|
||||||
if (TreeOld.group) 'Group';
|
if (TreeOld.group) 'Group';
|
||||||
`},
|
`},
|
||||||
|
Misskey: {__EvalSet__: `
|
||||||
|
if (TreeOld.isBot) 'Bot';
|
||||||
|
`},
|
||||||
},
|
},
|
||||||
Url: {
|
Url: {
|
||||||
Mastodon: "url",
|
Mastodon: "url",
|
||||||
|
Misskey: "uri",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -85,6 +92,9 @@ var ApiEndpoints = {
|
||||||
Mastodon(Profile) {
|
Mastodon(Profile) {
|
||||||
return `GET api/v1/accounts/${Profile.Id}/statuses`;
|
return `GET api/v1/accounts/${Profile.Id}/statuses`;
|
||||||
},
|
},
|
||||||
|
Misskey(Profile) {
|
||||||
|
return ``;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
ServerInfo: {
|
ServerInfo: {
|
||||||
Mastodon: "GET api/v1/instance",
|
Mastodon: "GET api/v1/instance",
|
||||||
|
@ -95,6 +105,7 @@ var ApiEndpoints = {
|
||||||
},
|
},
|
||||||
ServerTimeline: {
|
ServerTimeline: {
|
||||||
Mastodon: "GET api/v1/timelines/public",
|
Mastodon: "GET api/v1/timelines/public",
|
||||||
|
Misskey: "POST api/notes/local-timeline",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ function JsonTransformB(TreesOld, SchemaNew, NodeNew, TypeOld) {
|
||||||
return ListNew;
|
return ListNew;
|
||||||
} else {
|
} else {
|
||||||
// Object
|
// Object
|
||||||
if (TreesOld) {
|
if (TreesOld && SchemaNew && NodeNew) {
|
||||||
return JsonTransformCycleB(TreesOld, SchemaNew, NodeNew, TypeOld);
|
return JsonTransformCycleB(TreesOld, SchemaNew, NodeNew, TypeOld);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -66,19 +66,31 @@ function JsonTransformB(TreesOld, SchemaNew, NodeNew, TypeOld) {
|
||||||
function JsonTransformCycleB(TreeOld, SchemaNew, NodeNew, TypeOld) {
|
function JsonTransformCycleB(TreeOld, SchemaNew, NodeNew, TypeOld) {
|
||||||
var TreeNew = CopyObj(NodeNew);
|
var TreeNew = CopyObj(NodeNew);
|
||||||
if (SchemaNew.__All__) {
|
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){
|
_.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]) {
|
if (KeyNewVal[TypeOld]) {
|
||||||
var KeyOld = KeyNewVal[TypeOld];
|
var KeyOld = KeyNewVal[TypeOld];
|
||||||
var ObjOld = TreeOld[KeyOld];
|
var ObjOld = TreeOld[KeyOld];
|
||||||
if (IsObj(KeyOld)) {
|
if (IsObj(KeyOld)) {
|
||||||
// Object in NodeNew / Deep nested children in TreeOld
|
// Object in NodeNew / Deep nested children in TreeOld
|
||||||
_.forOwn(KeyOld, function(KeyObjVal, KeyObj){
|
_.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__') {
|
if (KeyObj === '__Eval__') {
|
||||||
eval(KeyObjVal);
|
eval(KeyObjVal);
|
||||||
} else
|
} else
|
||||||
|
@ -102,7 +114,7 @@ function JsonTransformCycleB(TreeOld, SchemaNew, NodeNew, TypeOld) {
|
||||||
} else {
|
} else {
|
||||||
// Value in NodeNew / Direct children in TreeOld
|
// Value in NodeNew / Direct children in TreeOld
|
||||||
if (IsObj(ObjOld)) {
|
if (IsObj(ObjOld)) {
|
||||||
TreeNew[KeyNew] = JsonTransformB(ObjOld, SchemaNew, SchemaNew[KeyNew], TypeOld);
|
TreeNew[KeyNew] = JsonTransformB(ObjOld, SchemaNew, SchemaNew[TreeNew[KeyNew].__], TypeOld);
|
||||||
} else {
|
} else {
|
||||||
TreeNew[KeyNew] = ObjOld;
|
TreeNew[KeyNew] = ObjOld;
|
||||||
};
|
};
|
||||||
|
|
|
@ -127,7 +127,9 @@ function FetchNotes(Profile, Proc) {
|
||||||
var Method = Profile.Type == 'Server'
|
var Method = Profile.Type == 'Server'
|
||||||
? ApiEndpoints.ServerTimeline[Soft]
|
? ApiEndpoints.ServerTimeline[Soft]
|
||||||
: ApiEndpoints.FetchNotes[Soft](Profile);
|
: 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');
|
var Notes = ApiTransform(Res.responseJson, Soft, 'Note');
|
||||||
LogDebug(Notes, 'l');
|
LogDebug(Notes, 'l');
|
||||||
Tasker[Res.Proc[0]].Return(Notes);
|
Tasker[Res.Proc[0]].Return(Notes);
|
||||||
|
@ -150,6 +152,9 @@ function ResFetchMastodon(Res) {
|
||||||
function FillTimeline(Notes) {
|
function FillTimeline(Notes) {
|
||||||
Notes.forEach(function(Note){
|
Notes.forEach(function(Note){
|
||||||
ApiCache.__UrlStore__(Note.Profile);
|
ApiCache.__UrlStore__(Note.Profile);
|
||||||
|
if (Note.Quoting) {
|
||||||
|
Note = Note.Quoting;
|
||||||
|
};
|
||||||
Root.lastChild.innerHTML += `<div class="View Note">
|
Root.lastChild.innerHTML += `<div class="View Note">
|
||||||
<a href="${Note.Profile.Url}" onclick="DisplayProfile('${Note.Profile.Url}'); return false;">
|
<a href="${Note.Profile.Url}" onclick="DisplayProfile('${Note.Profile.Url}'); return false;">
|
||||||
<img class="Profile Icon" src="${Note.Profile.Icon}"/>
|
<img class="Profile Icon" src="${Note.Profile.Icon}"/>
|
||||||
|
|
|
@ -34,6 +34,9 @@ function NetCall(Data, Proc) {
|
||||||
_.forOwn(_.merge({"Content-Type": "application/json"}, Data.Headers), function(Val, Key) {
|
_.forOwn(_.merge({"Content-Type": "application/json"}, Data.Headers), function(Val, Key) {
|
||||||
Req.setRequestHeader(Key, Val);
|
Req.setRequestHeader(Key, Val);
|
||||||
});
|
});
|
||||||
|
if (Method === 'POST' && !Data.Data) {
|
||||||
|
Data.Data = {};
|
||||||
|
};
|
||||||
Req.send(JSON.stringify(Data.Data));
|
Req.send(JSON.stringify(Data.Data));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,18 +4,6 @@ from base64 import b64encode
|
||||||
from mimetypes import guess_type
|
from mimetypes import guess_type
|
||||||
from pathlib import Path
|
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.chdir(os.path.dirname(os.path.abspath(__file__)))
|
||||||
os.makedirs('./Dist', exist_ok=True)
|
os.makedirs('./Dist', exist_ok=True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue