Friendiiverse/App/ApiTransform.js

114 lines
2.0 KiB
JavaScript
Raw Normal View History

2023-04-20 22:08:38 +02:00
/*
var TransSchemas = {
Mastodon: {
Account: {
"__": "Author",
"url": "Url",
2023-04-20 00:19:19 +02:00
"avatar": "Picture",
"header": "Banner",
},
Instance: {
"thumbnail": "Banner",
},
Status: {
"__": "Note",
"account": {"__": "Account"},
"content": "Content",
"created_at": "Time",
"url": "Url",
},
},
};
2023-04-20 22:08:38 +02:00
*/
2023-04-20 18:13:47 +02:00
var ApiSchema = {
2023-04-23 19:46:01 +02:00
__All__: {
SourceInstance: {
__Eval__: "",
},
},
Note: {
2023-04-22 17:09:59 +02:00
Content: {
Mastodon: "content",
Misskey: "text",
},
Profile: {
Mastodon: "account",
Misskey: "user",
},
2023-04-23 00:48:14 +02:00
Quoting: {
Mastodon: "reblog",
2023-04-25 00:55:20 +02:00
Misskey: "renote",
2023-04-23 00:48:14 +02:00
},
2023-04-22 17:09:59 +02:00
Time: {
Mastodon: "created_at",
Misskey: "createdAt",
},
Url: {
Mastodon: "url",
},
},
Profile: {
Avatar: {}, // would "Character" be better?
2023-04-20 18:13:47 +02:00
Banner: {
Mastodon: "header",
2023-04-20 22:08:38 +02:00
Misskey: "bannerUrl",
},
Description: {
Mastodon: "note",
Misskey: "description",
2023-04-20 18:13:47 +02:00
},
Icon: {
Mastodon: "avatar",
2023-04-20 22:08:38 +02:00
Misskey: "avatarUrl",
2023-04-20 15:17:00 +02:00
},
2023-04-20 18:13:47 +02:00
Name: {
Mastodon: "display_name",
2023-04-20 22:08:38 +02:00
Misskey: "name",
2023-04-20 15:17:00 +02:00
},
2023-04-23 00:48:14 +02:00
Type: { // user, bot, channel, group
2023-04-23 19:46:01 +02:00
Mastodon: {__EvalSet__: `
if (TreeOld.bot) 'Bot';
else
if (TreeOld.group) 'Group';
2023-04-23 00:48:14 +02:00
`},
},
2023-04-20 18:13:47 +02:00
Url: {
Mastodon: "url",
2023-04-20 00:19:19 +02:00
},
},
};
2023-04-25 00:55:20 +02:00
var ApiEndpoints = {
FetchNotes: {
Mastodon(Profile) {
return `accounts/${Profile.Id}/statuses`;
},
},
};
2023-04-23 00:48:14 +02:00
function ApiTransform(Data, FromSource, DestType) {
2023-04-25 00:55:20 +02:00
LogDebug([Data, DestType, FromSource]);
2023-04-23 00:48:14 +02:00
return JsonTransformB(Data, ApiSchema, ApiSchema[DestType], FromSource);
};
/*
var TransParsers = {
Mastodon: {
Account(Data) {
2023-04-22 10:06:31 +02:00
//return JsonTransformA(Data, TransSchemas.Mastodon.Author, TransSchemas.Mastodon);
2023-04-22 17:09:59 +02:00
return JsonTransformB(Data, ApiSchema, ApiSchema.Profile, 'Mastodon');
2023-04-20 00:19:19 +02:00
},
Instance(Data) {
return JsonTransformA(Data, TransSchemas.Mastodon.Instance, TransSchemas.Mastodon);
},
Status(Data) {
2023-04-20 18:13:47 +02:00
//return JsonTransformA(Data, TransSchemas.Mastodon.Status, TransSchemas.Mastodon);
return JsonTransformB(Data, ApiSchema, ApiSchema.Note, 'Mastodon');
},
},
2023-04-20 22:08:38 +02:00
Misskey: {
},
};
2023-04-23 00:48:14 +02:00
*/