mirror of
https://github.com/Sevichecc/m-oauth.git
synced 2025-04-30 06:59:29 +08:00
style: add comments
This commit is contained in:
parent
5a87613452
commit
c418934e7a
2 changed files with 129 additions and 59 deletions
186
lib/scopes.ts
186
lib/scopes.ts
|
@ -1,6 +1,8 @@
|
|||
import { ScopeInfo } from "./types";
|
||||
import { InstanceType } from "./types";
|
||||
|
||||
export const READ_SCOPES = [
|
||||
// Mastodon Scopes
|
||||
const READ_SCOPES = [
|
||||
"read:accounts",
|
||||
"read:blocks",
|
||||
"read:bookmarks",
|
||||
|
@ -14,7 +16,7 @@ export const READ_SCOPES = [
|
|||
"read:statuses",
|
||||
];
|
||||
|
||||
export const WRITE_SCOPES = [
|
||||
const WRITE_SCOPES = [
|
||||
"write:account",
|
||||
"write:blocks",
|
||||
"write:bookmarks",
|
||||
|
@ -29,7 +31,7 @@ export const WRITE_SCOPES = [
|
|||
"write:reports",
|
||||
];
|
||||
|
||||
export const ADMIN_READ_SCOPES = [
|
||||
const ADMIN_READ_SCOPES = [
|
||||
"admin:read",
|
||||
"admin:read:account",
|
||||
"admin:read:reports",
|
||||
|
@ -40,7 +42,7 @@ export const ADMIN_READ_SCOPES = [
|
|||
"admin:read:canonical_email_blocks",
|
||||
];
|
||||
|
||||
export const ADMIN_WRITE_SCOPES = [
|
||||
const ADMIN_WRITE_SCOPES = [
|
||||
"admin:write",
|
||||
"admin:write:account",
|
||||
"admin:write:reports",
|
||||
|
@ -51,33 +53,17 @@ export const ADMIN_WRITE_SCOPES = [
|
|||
"admin:write:canonical_email_blocks",
|
||||
];
|
||||
|
||||
export const PLEROMA_READ_SCOPE = [
|
||||
// Pleroma Scopes
|
||||
const PLEROMA_READ_SCOPE = [
|
||||
...READ_SCOPES,
|
||||
"read:backups",
|
||||
"read:chats",
|
||||
"read:securit",
|
||||
];
|
||||
|
||||
export const PLEROMA_WRITE_SCOPE = [
|
||||
...WRITE_SCOPES,
|
||||
"write:chats",
|
||||
"write:security",
|
||||
];
|
||||
const PLEROMA_WRITE_SCOPE = [...WRITE_SCOPES, "write:chats", "write:security"];
|
||||
|
||||
export const AKKOMA_READ_SCOPE = [
|
||||
...READ_SCOPES,
|
||||
"read:backups",
|
||||
"read:chats",
|
||||
"read:securit",
|
||||
];
|
||||
|
||||
export const AKKOMA_WRITE_SCOPE = [
|
||||
...WRITE_SCOPES,
|
||||
"write:chats",
|
||||
"write:security",
|
||||
];
|
||||
|
||||
export const PLEROMA_ADMIN_READ_SCOPES = [
|
||||
const PLEROMA_ADMIN_READ_SCOPES = [
|
||||
...ADMIN_READ_SCOPES,
|
||||
"admin:read:chats",
|
||||
"admin:read:invites",
|
||||
|
@ -85,7 +71,7 @@ export const PLEROMA_ADMIN_READ_SCOPES = [
|
|||
"admin:read:follows",
|
||||
"admin:read:media_proxy_caches",
|
||||
];
|
||||
export const PLEROMA_ADMIN_WRITE_SCOPES = [
|
||||
const PLEROMA_ADMIN_WRITE_SCOPES = [
|
||||
...ADMIN_READ_SCOPES,
|
||||
"admin:write:chats",
|
||||
"admin:write:invites",
|
||||
|
@ -94,39 +80,121 @@ export const PLEROMA_ADMIN_WRITE_SCOPES = [
|
|||
"admin:write:media_proxy_caches",
|
||||
];
|
||||
|
||||
export const scopesInfo: ScopeInfo[] = [
|
||||
{
|
||||
method: "read",
|
||||
label: "Read",
|
||||
scopes: READ_SCOPES,
|
||||
description: "read account's data",
|
||||
},
|
||||
{
|
||||
method: "write",
|
||||
label: "Write",
|
||||
scopes: WRITE_SCOPES,
|
||||
description: "modify account's data",
|
||||
},
|
||||
{
|
||||
method: "admin",
|
||||
label: "Admin",
|
||||
scopes: [ADMIN_READ_SCOPES, ADMIN_WRITE_SCOPES],
|
||||
description: "read all data on the server",
|
||||
},
|
||||
{
|
||||
method: "follow",
|
||||
label: "Follow",
|
||||
description: "modify account relationships,deprecated in 3.5.0 and newer.",
|
||||
},
|
||||
{
|
||||
method: "push",
|
||||
label: "Push",
|
||||
description: "receive push notifications",
|
||||
},
|
||||
// Akkoma Scopes
|
||||
const AKKOMA_READ_SCOPE = PLEROMA_WRITE_SCOPE.filter(
|
||||
(scope) => scope !== "read:chats"
|
||||
);
|
||||
const AKKOMA_WRITE_SCOPE = PLEROMA_WRITE_SCOPE.filter(
|
||||
(scope) => scope !== "write:chats"
|
||||
);
|
||||
const AKKOMA_ADMIN_READ_SCOPES = PLEROMA_ADMIN_READ_SCOPES.filter(
|
||||
(scope) => scope !== "admin:read:chats"
|
||||
);
|
||||
const AKKOMA_ADMIN_WRITE_SCOPES = PLEROMA_ADMIN_WRITE_SCOPES.filter(
|
||||
(scope) => scope !== "admin:write:chats"
|
||||
);
|
||||
|
||||
{
|
||||
method: "crypto",
|
||||
label: "Crypto",
|
||||
description: "use end-to-end encryption",
|
||||
},
|
||||
// Miskky Scopes
|
||||
|
||||
const MISSKEY_READ_SCOPES = [
|
||||
"read:account",
|
||||
"read:blocks",
|
||||
"read:drive",
|
||||
"read:favorites",
|
||||
"read:following",
|
||||
"read:messaging",
|
||||
"read:mutes",
|
||||
"read:notifications",
|
||||
"read:reactions",
|
||||
"read:pages",
|
||||
"read:page-likes",
|
||||
"read:user-groups",
|
||||
"read:channels",
|
||||
"read:gallery",
|
||||
"read:gallery-likes",
|
||||
];
|
||||
|
||||
const MISSKEY_WRITE_SCOPES = [
|
||||
"write:account",
|
||||
"write:blocks",
|
||||
"write:drive",
|
||||
"write:favorites",
|
||||
"write:following",
|
||||
"write:messaging",
|
||||
"write:mutes",
|
||||
"write:notes",
|
||||
"write:notifications",
|
||||
"write:reactions",
|
||||
"write:votes",
|
||||
"write:pages",
|
||||
"write:page-likes",
|
||||
"write:user-groups",
|
||||
"write:channels",
|
||||
"write:gallery",
|
||||
"write:gallery-likes",
|
||||
'write:clip-favorite',
|
||||
'write:flash'
|
||||
];
|
||||
|
||||
export const getScopes = (instanceType: InstanceType): ScopeInfo[] => {
|
||||
let readScopes = READ_SCOPES;
|
||||
let writeScopes = WRITE_SCOPES;
|
||||
let adminScopes = [ADMIN_READ_SCOPES, ADMIN_WRITE_SCOPES];
|
||||
|
||||
switch (instanceType) {
|
||||
case "mastodon":
|
||||
break;
|
||||
case "akkoma":
|
||||
readScopes = AKKOMA_READ_SCOPE;
|
||||
writeScopes = AKKOMA_WRITE_SCOPE;
|
||||
adminScopes = [AKKOMA_ADMIN_READ_SCOPES, AKKOMA_ADMIN_WRITE_SCOPES];
|
||||
break;
|
||||
case "pleroma":
|
||||
readScopes = PLEROMA_READ_SCOPE;
|
||||
writeScopes = PLEROMA_WRITE_SCOPE;
|
||||
adminScopes = [PLEROMA_ADMIN_READ_SCOPES, PLEROMA_ADMIN_WRITE_SCOPES];
|
||||
break;
|
||||
case "misskey":
|
||||
readScopes = MISSKEY_READ_SCOPES;
|
||||
writeScopes = MISSKEY_WRITE_SCOPES;
|
||||
adminScopes = []
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
method: "read",
|
||||
label: "Read",
|
||||
scopes: readScopes,
|
||||
description: "read account's data",
|
||||
},
|
||||
{
|
||||
method: "write",
|
||||
label: "Write",
|
||||
scopes: writeScopes,
|
||||
description: "modify account's data",
|
||||
},
|
||||
{
|
||||
method: "admin",
|
||||
label: "Admin",
|
||||
scopes: adminScopes,
|
||||
description: "read all data on the server",
|
||||
},
|
||||
{
|
||||
method: "follow",
|
||||
label: "Follow",
|
||||
description:
|
||||
"modify account relationships,deprecated in 3.5.0 and newer.",
|
||||
},
|
||||
{
|
||||
method: "push",
|
||||
label: "Push",
|
||||
description: "receive push notifications",
|
||||
},
|
||||
|
||||
{
|
||||
method: "crypto",
|
||||
label: "Crypto",
|
||||
description: "use end-to-end encryption",
|
||||
},
|
||||
];
|
||||
};
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
export type InstanceType = "mastodon" | "akkoma" | "misskey" | "pleroma";
|
||||
|
||||
export type MethodType =
|
||||
| "read"
|
||||
| "write"
|
||||
|
|
Loading…
Reference in a new issue