upd: add new endpoint to mk api, add preferences to masto api
This commit is contained in:
parent
035d600406
commit
871407ce53
5 changed files with 112 additions and 8 deletions
|
@ -961,21 +961,54 @@ export default class Misskey implements MegalodonInterface {
|
|||
// ======================================
|
||||
// accounts/preferences
|
||||
// ======================================
|
||||
|
||||
private async getDefaultPostPrivacy(): Promise<"public" | "unlisted" | "private" | "direct"> {
|
||||
// NOTE: get-unsecure is sharkey's extension.
|
||||
// Misskey doesn't have this endpoint and regular `/i/registry/get` won't work
|
||||
// unless you have a 'nativeToken', which is reserved for the frontend webapp.
|
||||
|
||||
return this.client
|
||||
.post<string>("/api/i/registry/get-unsecure", {
|
||||
key: "defaultNoteVisibility",
|
||||
scope: ["client", "base"],
|
||||
})
|
||||
.then((res) => {
|
||||
if (
|
||||
!res.data ||
|
||||
(res.data != "public" &&
|
||||
res.data != "home" &&
|
||||
res.data != "followers" &&
|
||||
res.data != "specified")
|
||||
)
|
||||
return "public";
|
||||
return MisskeyAPI.Converter.visibility(res.data);
|
||||
})
|
||||
.catch((_) => "public");
|
||||
}
|
||||
|
||||
public async getPreferences(): Promise<Response<Entity.Preferences>> {
|
||||
return new Promise((_, reject) => {
|
||||
const err = new NoImplementedError('misskey does not support')
|
||||
reject(err)
|
||||
})
|
||||
return this.client.post<MisskeyAPI.Entity.UserDetail>("/api/i")
|
||||
.then(async (res) => {
|
||||
return Object.assign(res, {
|
||||
data: MisskeyAPI.Converter.userPreferences(
|
||||
await this.getDefaultPostPrivacy(),
|
||||
),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ======================================
|
||||
// accounts/followed_tags
|
||||
// ======================================
|
||||
public async getFollowedTags(): Promise<Response<Array<Entity.Tag>>> {
|
||||
return new Promise((_, reject) => {
|
||||
const err = new NoImplementedError('misskey does not support')
|
||||
reject(err)
|
||||
})
|
||||
const tags: Entity.Tag[] = [];
|
||||
const res: Response = {
|
||||
headers: undefined,
|
||||
statusText: "",
|
||||
status: 200,
|
||||
data: tags,
|
||||
};
|
||||
return new Promise((resolve) => resolve(res));
|
||||
}
|
||||
|
||||
// ======================================
|
||||
|
|
|
@ -140,6 +140,16 @@ namespace MisskeyAPI {
|
|||
}
|
||||
}
|
||||
|
||||
export const userPreferences = (v: "public" | "unlisted" | "private" | "direct"): MegalodonEntity.Preferences => {
|
||||
return {
|
||||
"reading:expand:media": "default",
|
||||
"reading:expand:spoilers": false,
|
||||
"posting:default:language": "english",
|
||||
"posting:default:sensitive": false,
|
||||
"posting:default:visibility": v,
|
||||
};
|
||||
};
|
||||
|
||||
export const visibility = (v: 'public' | 'home' | 'followers' | 'specified'): 'public' | 'unlisted' | 'private' | 'direct' => {
|
||||
switch (v) {
|
||||
case 'public':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue